TPE-294 RPM spec error when processing multiple requests 39/163439/2
authorhyokeun <hyokeun.jeon@samsung.com>
Mon, 11 Dec 2017 07:14:44 +0000 (16:14 +0900)
committerhyokeun <hyokeun.jeon@samsung.com>
Mon, 11 Dec 2017 07:39:59 +0000 (16:39 +0900)
Change-Id: I0ffcb628929d49e629e0426684d60af8e2e5e1d9

common/get_name_from_specfile.py [new file with mode: 0755]
common/workflow.py
debian/jenkins-scripts-common.install
packaging/jenkins-scripts.spec

diff --git a/common/get_name_from_specfile.py b/common/get_name_from_specfile.py
new file mode 100755 (executable)
index 0000000..a7ae529
--- /dev/null
@@ -0,0 +1,89 @@
+#!/usr/bin/env python
+
+import os
+import sys
+import json
+import argparse
+from argparse import ArgumentParser
+from datetime import datetime, timedelta
+
+from gbp.rpm import SpecFile
+from gbp.git.repository import GitRepositoryError
+from gbp.errors import GbpError
+
+# set default char-set endcoding to utf-8
+reload(sys)
+sys.setdefaultencoding('utf-8') # pylint: disable-msg=E1101
+
+def unicode_to_str(obj):
+    """convert unicode object to str"""
+
+    if isinstance(obj, list):
+        return [unicode_to_str(element) for element in obj]
+    elif isinstance(obj, dict):
+        return {unicode_to_str(key) : unicode_to_str(value) for key, value \
+                in obj.iteritems()}
+    elif isinstance(obj, unicode):
+        return obj.encode('utf-8')
+    else:
+        return obj
+
+def format_output(data):
+    print '-----BEGIN RC OUTPUT-----'
+    sys.stdout.flush()
+    print data
+    sys.stdout.flush()
+    print '-----END RC OUTPUT-----'
+
+def parse_specfile(specfile, tag, event, tagger):
+    """parse specfile"""
+
+    spec = None
+
+    try:
+        # use gbp to parse specfile
+        spec = SpecFile(specfile)
+    except GbpError, err:
+        print 'gbp parse spec failed. %s' % err
+        msg = 'The tag %s pushed, but backend service failed to parse %s. \n'\
+                'Please try "gbs export" on this tag and make sure it can '\
+                'work.\n\n'\
+                'Error message:\n'\
+                '%s' % (tag, os.path.basename(specfile), err)
+        return {'message': msg, 'spec': None}
+
+    return {'message': None, 'spec': spec.name}
+
+
+def search_main(args):
+
+    resp = parse_specfile(args.specfile, args.tag, None, None)
+    format_output(resp)
+
+def argument_parsing(argv):
+    """Any arguments passed from user"""
+
+    parser = argparse.ArgumentParser(description='AWS control interface')
+
+    subparsers = parser.add_subparsers(dest='subcommands')
+
+    #### [subcommand - search] ####
+    cmd_search = subparsers.add_parser('search')
+    cmd_search.add_argument('-f', '--specfile', action='store', dest='specfile', \
+                      help='Absolute full path of spec file to be parsed.')
+    cmd_search.add_argument('-t', '--tag', action='store', dest='tag', \
+                      help='SR tag name.')
+
+    return parser.parse_args(argv[1:])
+
+def main(argv):
+    args = argument_parsing(argv)
+    if args.subcommands == 'search':
+        return search_main(args)
+    else:
+        print 'Unsopported command %s' % args.subcommands
+        return -1
+
+if __name__ == '__main__':
+    sys.exit(main(sys.argv))
+
index 63116b5..14aebf9 100644 (file)
@@ -335,6 +335,28 @@ def find_specfile(prj_dir, packaging_dir, tag, event, tagger, pkg_name=None, deb
         print 'specfile %s' % spec
         return {'message': None, 'spec': spec}
 
+def parse_specfile2(specfile, tag, event, tagger):
+    """parse specfile"""
+
+    spec = None
+
+    try:
+        # use gbp to parse specfile
+        spec = SpecFile(specfile)
+    except GbpError, err:
+        print 'gbp parse spec failed. %s' % err
+        msg = 'The tag %s pushed, but backend service failed to parse %s. \n'\
+                'Please try "gbs export" on this tag and make sure it can '\
+                'work.\n\n'\
+                'Error message:\n'\
+                '%s' % (tag, os.path.basename(specfile), err)
+        del spec
+        return {'message': msg, 'spec': None}
+
+    specname = spec.name
+    del spec
+    return {'message': None, 'spec': specname}
+
 def parse_specfile(specfile, tag, event, tagger):
     """parse specfile"""
 
@@ -546,6 +568,7 @@ def create_project(build, obs_project, submit_list, mode=MODE_NORMAL):
             'images': [],
             'base': get_base_project(build, ref_obs_target_prj)
            }
+
     # Enable Github Connection
     if submit_list[0].get('github_type'):
         info['github'] = []
@@ -622,7 +645,7 @@ def create_project(build, obs_project, submit_list, mode=MODE_NORMAL):
 
     # copy the maintainer list from obs_target_prj meta to corresponding
     # prerelease project
-    copy_person_project_meta(build, ref_obs_target_prj, obs_project)
+    copy_person_project_meta(build, obs_target_prj, obs_project)
 
     if build_flag != True:
         return
@@ -691,11 +714,21 @@ def get_info_from_tag(git, branch, target_project, tag, gerrit_env=None):
             resp = find_specfile(prjdir, packagingdir, tag, {'project': git}, None)
             if not resp['spec']:
                 return ret_data
-            resp = parse_specfile(resp['spec'], tag, git, None)
-            if not resp['spec']:
-                return ret_data
-            print 'spec name = %s' %(resp['spec'].name)
-            ret_data['spec_name'] = resp['spec'].name
+#            resp = parse_specfile2(resp['spec'], tag, git, None)
+#            if not resp['spec']:
+#                return ret_data
+            external_program = os.path.join(os.getenv('JENKINS_HOME'), 'jenkins-scripts/common/get_name_from_specfile.py')
+            cmdln = '%s search -f %s -t %s' % (external_program, resp['spec'], tag)
+            ret, outs = runner.show(cmdln)
+            if ret == 0:
+                ext_data = outs[outs.find('-----BEGIN RC OUTPUT-----')+26:outs.find('-----END RC OUTPUT-----')-1]
+                resp = ast.literal_eval(ext_data)
+            else:
+                print ret
+                raise Exception
+            sys.stdout.flush()
+            print 'spec name = %s' %(resp['spec'])
+            ret_data['spec_name'] = resp['spec']
         else:
             if obs_pkg:
                 print 'package name from mapping = %s' % (obs_pkg)
@@ -704,6 +737,7 @@ def get_info_from_tag(git, branch, target_project, tag, gerrit_env=None):
                 print 'package name from basename = %s' % (os.path.basename(git))
                 ret_data['spec_name'] = os.path.basename(git)
 
+    del mygit
     return ret_data
 
 def get_manifest_filelists_snapshot(profile, request_url, timeout=5, group=None):
index 22cb21d..d52707d 100644 (file)
@@ -42,3 +42,4 @@ debian/tmp/scripts/del-obs-tree-proj.sh /var/lib/jenkins/jenkins-scripts/scripts
 debian/tmp/scripts/nuget.exe /var/lib/jenkins/jenkins-scripts/scripts
 debian/tmp/common/aws_ec2.py /var/lib/jenkins/jenkins-scripts/common/
 debian/tmp/common/workflow.py /var/lib/jenkins/jenkins-scripts/common/
+debian/tmp/common/get_name_from_specfile.py /var/lib/jenkins/jenkins-scripts/common/
index 685c887..e9c7faa 100644 (file)
@@ -234,6 +234,7 @@ fi
 %{destdir}/scripts/nuget.exe
 %{destdir}/common/aws_ec2.py
 %{destdir}/common/workflow.py
+%{destdir}/common/get_name_from_specfile.py
 
 %files dependsgraph
 %defattr(-,jenkins,jenkins)