--- /dev/null
+#!/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))
+
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"""
'images': [],
'base': get_base_project(build, ref_obs_target_prj)
}
+
# Enable Github Connection
if submit_list[0].get('github_type'):
info['github'] = []
# 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
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)
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):
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/
%{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)