'Automatically generated by backend service.\n'\
'Please DO NOT Reply!'
+class SubmitobsError(Exception):
+ """Local error handler"""
+ pass
+
def send_mail(title, msg, receiver):
""" post message back to gerrit and send mail to tag owner """
- if receiver.has_key('author') and receiver.has_key('email'):
+ if 'author' in receiver and 'email' in receiver:
msg = 'Hi, %s,\n\n' % receiver['author'] + msg + EMAIL_FOOTER
prepare_mail("%s.mail.env" % random.random(), title, msg,
os.getenv('NOREPLY_EMAIL_SENDER'), receiver['email'])
# Since patchset_revision is used in gerrit feedback, real tag check
# is needed; and the key point is parse_submit_tag can not ensure the
# tag exsisting too.
- if not event['patchset_revision']: tag = None
+ if not event['patchset_revision']:
+ tag = None
elif event['event_type'] == 'change-merged':
# for chanage-merged, search submit tag on this commit
branch = event['branch']
branch, date = parse_submit_tag(tag)
message = []
+ psr = event['patchset_revision']
# check tag name format
if branch and date:
# check date format
- pattern = re.compile('^[0-9]{8}\.[0-9]{6}$')
+ pattern = re.compile(r'^[0-9]{8}\.[0-9]{6}$')
if not pattern.match(date):
message.append(WRONG_DATE_MSG % date)
# the tagged commit has been merged on gerrit
if branch not in branches:
# tag is on wrong branch
- message.append(WRONG_VERSION_MSG % (event['patchset_revision'],
- branch, branch))
+ message.append(WRONG_VERSION_MSG % (psr, branch, branch))
else:
# The tagged commit doesn't exist in git tree
cmd = '--current-patch-set status: open project: %s commit: %s' % \
- (event['project'], event['patchset_revision'])
+ (event['project'], psr)
gerritinfo = mygerrit.query(cmd)
- if len(gerritinfo) == 1 and gerritinfo[0].has_key('number') and gerritinfo[0].has_key('currentPatchSet'):
+ if len(gerritinfo) == 1 and 'number' in gerritinfo[0] \
+ and 'currentPatchSet' in gerritinfo[0]:
if gerritinfo[0]['branch'] == branch:
# the tagged commit still open, abort submit this time
- message.append(UNDER_REVIEW_MSG % event['patchset_revision'])
+ message.append(UNDER_REVIEW_MSG % psr)
else:
# tag is on wrong branch
- message.append(WRONG_VERSION_MSG % (event['patchset_revision'], branch, branch))
+ message.append(WRONG_VERSION_MSG % (psr, branch, branch))
else:
# cannot find tagged commit in git tree or gerrit open change
- message.append(WRONG_COMMIT_MSG % event['patchset_revision'])
+ message.append(WRONG_COMMIT_MSG % psr)
else:
# wrong tag format
message.append(UNKNOWN_FORMAT_MSG)
# check whether tag is an annotated tag
tagger = git.get_tag(tag)
- if not tagger.has_key('author') or not tagger.has_key('email'):
+ if 'author' not in tagger or 'email' not in tagger:
message.append(NOT_ANNOTATED_MSG)
# post comment to gerrit and send email if check failed
if message:
print message
- msg = 'The tag %s is pushed, but this submission failed because of following reason(s):\n\n' % tag + \
- '\n'.join(message)
- if len(message) != 1 or message[0] != UNDER_REVIEW_MSG % event['patchset_revision']:
+ msg = 'The tag %s is pushed, but this submission failed because of "\
+ "following reason(s):\n\n' % tag + '\n'.join(message)
+ if len(message) != 1 or message[0] != UNDER_REVIEW_MSG % psr:
msg += '\n\n' + SUGGESTION
- mygerrit.review(commit = event['patchset_revision'], message = msg)
+ mygerrit.review(commit = psr, message = msg)
send_mail(TITLE_FAILED % (tag, event['project']), msg, tagger)
return False
"""check whehter tag is deleted"""
# 0000*0 is a special git hash code in gerrit for deleted git object
- if oldrev != newrev and newrev == '0000000000000000000000000000000000000000':
+ if oldrev != newrev and newrev == '0'*40:
return True
else:
return False
def check_changes(obs_pkg, name, tag, tagger, event):
"""check whether this submission include modification for changes file"""
changelog = '%s.changes' % name
- if not os.path.isfile(os.path.join(obs_pkg.get_workdir(), '%s.changes' % name)):
+ change_file = os.path.join(obs_pkg.get_workdir(), '%s.changes' % name)
+ if not os.path.isfile(change_file):
chg = utils.find_changelog(obs_pkg.get_workdir())
if chg:
changelog = chg
status = obs_pkg.status(changelog)
if status in ['?', '!', 'D']:
# can not find changelog file under packaging directory
- title = '[Warning] no changelog file found in submission: [%s] of %s' % (tag, event['project'])
- msg = '[Error] The "%s" branch of "%s" project does NOT contain change file under packaging directory! Please create "packaging/%s" and document the bug fix and/or features in this changelog file before your submission.' % (event['branch'], event['project'], changelog)
+ title = '[Warning] no changelog file found in submission: [%s] of %s' \
+ % (tag, event['project'])
+ msg = '[Error] The "%s" branch of "%s" project does NOT contain '\
+ 'change file under packaging directory! Please create '\
+ '"packaging/%s" and document the bug fix and/or features in '\
+ 'this changelog file before your submission.' \
+ % (event['branch'], event['project'], changelog)
elif status == ' ':
# this submission didn't modify changelog file
- title = '[Warning] no new changelog entry in submission: [%s] of %s' % (tag, event['project'])
- msg = '[Error] Compare to last submission, this one (tag %s) does not contain any new entry for packaging/%s! Please add a new entry in change log to document the bug fix and/or feature before your submission. You can use "gbs changelog" to generate new entry, for details please refer to: https://source.tizen.org/documentation/reference/git-build-system/usage/gbs-changelog' % (tag, changelog)
+ title = '[Warning] no new changelog entry in submission: [%s] of %s' \
+ % (tag, event['project'])
+ msg = '[Error] Compare to last submission, this one (tag %s) does '\
+ 'not contain any new entry for packaging/%s! Please add a '\
+ 'new entry in change log to document the bug fix and/or '\
+ 'feature before your submission. You can use "gbs changelog" '\
+ 'to generate new entry, for details please refer to: '\
+ 'https://source.tizen.org/documentation/reference/'\
+ 'git-build-system/usage/gbs-changelog' % (tag, changelog)
elif status in ['M', 'A']:
print 'This submission has updated changes file.'
if pkg_name:
spec = '%s/%s/%s.spec' % (prj_dir, packaging_dir, pkg_name)
if not os.path.isfile(spec):
- msg = "The tag %s pushed, but backend service can not find %s under packaging directory, which is caused by mistake OBS_PACKAGE parameter in scm/git-obs-mapping project. Please correct it or contact system administrator for more details." % (tag, os.path.basename(spec))
+ msg = "The tag %s pushed, but backend service can not find %s "\
+ "under packaging directory, which is caused by mistake "\
+ "OBS_PACKAGE parameter in scm/git-obs-mapping project. "\
+ "Please correct it or contact system administrator for "\
+ "more details." % (tag, os.path.basename(spec))
else:
specs = utils.find_spec('%s/%s' % (prj_dir, packaging_dir))
if not specs:
# no spec exist under packaging, use default name
- msg = "The tag %s pushed, but packaging directory doesn't contain any spec file. Please create one and re-submit it." % tag
+ msg = "The tag %s pushed, but packaging directory doesn't "\
+ "contain any spec file. Please create one and re-submit "\
+ "it." % tag
elif len(specs) == 1:
# only one spec exist under packaging
spec = specs[0]
else:
# multiple specs exist under packaging, use default name
- spec = '%s/%s/%s.spec' % (prj_dir, packaging_dir, os.path.basename(event['project']))
+ spec = '%s/%s/%s.spec' % (prj_dir, packaging_dir, \
+ os.path.basename(event['project']))
if not os.path.isfile(spec):
- msg = "The tag %s pushed, but packaging directory contains multiply spec files, backend service can not decide which spec file to use. Please use OBS_PACKAGE parameter in scm/git-obs-mapping project to specify the target spec file or contact system administrator for more details." % tag
+ msg = "The tag %s pushed, but packaging directory contains "\
+ "multiply spec files, backend service can not decide "\
+ "which spec file to use. Please use OBS_PACKAGE "\
+ "parameter in scm/git-obs-mapping project to specify "\
+ "the target spec file or contact system "\
+ "administrator for more details." % tag
if msg:
print msg
print('specfile %s' % spec)
return spec
-def parse_specfile(specfile, tmp_dir, prj_dir, packaging_dir, tag, event, tagger):
+def parse_specfile(specfile, tmp_dir, prj_dir, packaging_dir, tag, event, \
+ tagger):
"""parse specfile and use "gbs export" to generate tarball"""
spec = None
# use gbs export to generate tarball
outdir = tempfile.mkdtemp(prefix=tmp_dir+'/')
with utils.Workdir(prj_dir):
- runner.show('gbs export --spec %s --packaging-dir %s -o %s' % (os.path.basename(specfile), packaging_dir, outdir))
- except Exception, exc:
- print('gbp parse spec failed. %s' % exc)
- msg = "The tag %s pushed, but backend service failed to parse %s. Please make sure (gbs export) can work in this project." % (tag, os.path.basename(specfile))
+ runner.show('gbs export --spec %s --packaging-dir %s -o %s' \
+ % (os.path.basename(specfile), packaging_dir, outdir))
+ except SubmitobsError, soe:
+ print('gbp parse spec failed. %s' % soe)
+ msg = "The tag %s pushed, but backend service failed to parse %s. "\
+ "Please make sure (gbs export) can work in this project." \
+ % (tag, os.path.basename(specfile))
send_mail(TITLE_FAILED % (tag, event['project']), msg, tagger)
return None, None
# check whether tag name is start with 'submit/'
if event['event_type'] == "ref-updated":
if not event['refname'].startswith('refs/tags/submit/'):
- print '\nREFNAME "%s" isn\'t start with refs/tags/submit, exit now' % event['refname']
+ print '\nREFNAME "%s" isn\'t start with refs/tags/submit, exit '\
+ 'now' % event['refname']
return 0
elif is_tag_deleted(event['oldrev'], event['newrev']):
print '\nREFNAME "%s" is deleted, exit now' % event['refname']
return 0
+ obs_mapping = '%s/%s/git-obs-mapping.xml' % (gitcache, mapping_prj)
# check whether git-obs-mapping.xml exist in local
- if not os.path.isfile('%s/%s/git-obs-mapping.xml' % (gitcache, mapping_prj)):
+ if not os.path.isfile(obs_mapping):
print('Update %s/git-obs-mapping.xml to local.' % mapping_prj)
- if not clone_gitproject(mapping_prj, os.path.join(gitcache, mapping_prj)):
+ if not clone_gitproject(mapping_prj, \
+ os.path.join(gitcache, mapping_prj)):
return 1
# quit directly if project do not map to any OBS project
- mymapping = mapping.Mapping('%s/%s/git-obs-mapping.xml' % (gitcache, mapping_prj))
+ mymapping = mapping.Mapping(obs_mapping)
if not mymapping.get_submit_mapping(event['project']):
print '\nThis project do not map to any OBS project, exit now'
return 0
return 1
mygit = Git(prjdir)
- mygerrit = gerrit.Gerrit(event['hostname'], event['username'], event['sshport'])
+ mygerrit = gerrit.Gerrit(event['hostname'], event['username'], \
+ event['sshport'])
tag = find_submit_tag(event, mygit)
if not tag:
obs_stg_prj = obs_dst_prj
# search specfile under packaging directory
- specfile = find_specfile(prjdir, packagingdir, tag, event, tagger, obs_pkg)
+ specfile = find_specfile(prjdir, packagingdir, tag, event, tagger, \
+ obs_pkg)
if not specfile:
return 0
# parse specfile and use "gbs export" to generate tarball
- spec, tarballdir = parse_specfile(specfile, tmpdir, prjdir, packagingdir, tag, event, tagger)
+ spec, tarballdir = parse_specfile(specfile, tmpdir, prjdir, \
+ packagingdir, tag, event, tagger)
if not spec or not tarballdir:
return 0
while retry_count > 0:
try:
if obs_stg_prj != obs_dst_prj:
- tmppkg = obspkg.ObsPackage(tmpdir, obs_stg_prj, 'tmp', apiurl, apiuser, apipasswd)
+ tmppkg = obspkg.ObsPackage(tmpdir, obs_stg_prj, 'tmp', \
+ apiurl, apiuser, apipasswd)
if tmppkg.is_new_pkg():
- tmppkg.commit("Leave an empty package in this project to prevent OBS delete it automatically when all request from here are accepted.")
+ tmppkg.commit("Leave an empty package in this "\
+ "project to prevent OBS delete it "\
+ "automatically when all request from "
+ "here are accepted.")
print '\nCheckout %s/%s to local' % (obs_stg_prj, spec.name)
- localpkg = obspkg.ObsPackage(tmpdir, obs_stg_prj, spec.name, apiurl, apiuser, apipasswd)
+ localpkg = obspkg.ObsPackage(tmpdir, obs_stg_prj, spec.name, \
+ apiurl, apiuser, apipasswd)
oscworkdir = localpkg.get_workdir()
localpkg.remove_all()
for myfile in os.listdir(tarballdir):
- shutil.copy2(os.path.join(tarballdir, myfile), os.path.join(oscworkdir, myfile))
+ shutil.copy2(os.path.join(tarballdir, myfile), \
+ os.path.join(oscworkdir, myfile))
localpkg.update_local()
- # check whether this submission inclued modification for changes file
+ # check whether this submission inclued modification
+ # for changes file
if not check_changes(localpkg, spec.name, tag, tagger, event):
return 1
# submit local pkg to obs and create sr
print '\nSubmit local pkg to obs...'
- commit_msg = 'Submitter: %s <%s>\nComments: %s\nGit project: %s\nTag: %s\nCommit: %s %s' % (tagger['author'], tagger['email'], tagger['message'], event['project'], tag, commitinfo['id'], commitinfo['subject'])
+ commit_msg = 'Submitter: %s <%s>\nComments: %s\nGit project: '\
+ '%s\nTag: %s\nCommit: %s %s' % (tagger['author'], \
+ tagger['email'], tagger['message'], event['project'], \
+ tag, commitinfo['id'], commitinfo['subject'])
localpkg.commit(commit_msg)
if obs_stg_prj != obs_dst_prj:
newreq = localpkg.submit_req(obs_dst_prj, msg=commit_msg)
print 'New request %s is created' % newreq
break
- except Exception, exc:
+ except SubmitobsError, soe:
print('obs operation failed, retrying...')
- print exc
+ print soe
sleep(1)
retry_count -= 1
return 1
# post sr info back to gerrit
- comment = '- Submitter: %s <%s>\n- Comments: %s\n- Git project: %s\n- Tag: %s\n- Commit: %s %s' % (tagger['author'], tagger['email'], tagger['message'], event['project'], tag, commitinfo['id'], commitinfo['subject'])
+ comment = '- Submitter: %s <%s>\n- Comments: %s\n- Git project: '\
+ '%s\n- Tag: %s\n- Commit: %s %s' % (tagger['author'], \
+ tagger['email'], tagger['message'], event['project'], tag, \
+ commitinfo['id'], commitinfo['subject'])
if obs_stg_prj != obs_dst_prj:
# submit to :build project and create a SR
requrl = ' %s/request/show/%s' % (os.getenv('OBS_URL'), newreq)
- comment = 'A SR (Submit Request) has been triggered to submit the commit to OBS %s project.\n' % obs_dst_prj + \
- comment + '\n' + \
- '- Request URL:%s' % requrl
+ comment = 'A SR (Submit Request) has been triggered to submit '\
+ 'the commit to OBS %s project.\n' % obs_dst_prj + \
+ comment + '\n' + '- Request URL:%s' % requrl
else:
# submit to final target project directly
- comment = 'This commit has been submitted to OBS %s project.\n' % obs_dst_prj + comment
+ comment = 'This commit has been submitted to OBS %s project.\n' \
+ % obs_dst_prj + comment
mygerrit.review(commit = event['patchset_revision'], message = comment)
return 0
if __name__ == '__main__':
-
sys.exit(main())