pep8 and change ticket closing message slighlty

This commit is contained in:
Kovid Goyal 2017-02-16 11:35:37 +05:30
parent 796df81638
commit d425d50a90

View File

@ -1,11 +1,16 @@
#!/usr/bin/env python2 #!/usr/bin/env python2
# vim:fileencoding=utf-8 # vim:fileencoding=utf-8
from __future__ import (unicode_literals, division, absolute_import, # License: GPLv3 Copyright: 2008, Kovid Goyal <kovid at kovidgoyal.net>
print_function) from __future__ import absolute_import, division, print_function, unicode_literals
__license__ = 'GPL v3' import importlib
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>' import json
import re
import socket
import sys
import urllib
from lxml import html
''' '''
Hook to make the commit command automatically close bugs when the commit Hook to make the commit command automatically close bugs when the commit
@ -13,9 +18,7 @@ message contains `Fix #number` or `Implement #number`. Also updates the commit
message with the summary of the closed bug. message with the summary of the closed bug.
''' '''
import re, urllib, importlib, sys, json, socket
from lxml import html
SENDMAIL = ('/home/kovid/work/env', 'pgp_mail') SENDMAIL = ('/home/kovid/work/env', 'pgp_mail')
LAUNCHPAD_BUG = 'https://bugs.launchpad.net/calibre/+bug/%s' LAUNCHPAD_BUG = 'https://bugs.launchpad.net/calibre/+bug/%s'
@ -24,6 +27,7 @@ BUG_PAT = r'(Fix|Implement|Fixes|Fixed|Implemented|See)\s+#(\d+)'
socket.setdefaulttimeout(90) socket.setdefaulttimeout(90)
class Bug: class Bug:
def __init__(self): def __init__(self):
@ -46,7 +50,7 @@ class Bug:
else: else:
summary = json.loads(urllib.urlopen(GITHUB_BUG % bug).read())['title'] summary = json.loads(urllib.urlopen(GITHUB_BUG % bug).read())['title']
if summary: if summary:
print ('Working on bug:', summary) print('Working on bug:', summary)
if int(bug) > 100000 and action != 'See': if int(bug) > 100000 and action != 'See':
self.close_bug(bug, action) self.close_bug(bug, action)
return match.group() + ' [%s](%s)' % (summary, LAUNCHPAD_BUG % bug) return match.group() + ' [%s](%s)' % (summary, LAUNCHPAD_BUG % bug)
@ -54,11 +58,13 @@ class Bug:
return match.group() return match.group()
def close_bug(self, bug, action): def close_bug(self, bug, action):
print ('Closing bug #%s'% bug) print('Closing bug #%s' % bug)
suffix = ('The fix will be in the next release. ' suffix = (
'calibre is usually released every Friday.') 'The fix will be in the next release. '
'calibre is usually released every alternate Friday.'
)
action += 'ed' action += 'ed'
msg = '%s in branch %s. %s'%(action, 'master', suffix) msg = '%s in branch %s. %s' % (action, 'master', suffix)
msg = msg.replace('Fixesed', 'Fixed') msg = msg.replace('Fixesed', 'Fixed')
msg += '\n\n status fixreleased' msg += '\n\n status fixreleased'
@ -66,9 +72,10 @@ class Bug:
sendmail = importlib.import_module(SENDMAIL[1]) sendmail = importlib.import_module(SENDMAIL[1])
to = bug+'@bugs.launchpad.net' to = bug + '@bugs.launchpad.net'
sendmail.sendmail(msg, to, 'Fixed in master') sendmail.sendmail(msg, to, 'Fixed in master')
def main(): def main():
with open(sys.argv[-1], 'r+b') as f: with open(sys.argv[-1], 'r+b') as f:
raw = f.read().decode('utf-8') raw = f.read().decode('utf-8')
@ -79,6 +86,6 @@ def main():
f.truncate() f.truncate()
f.write(msg.encode('utf-8')) f.write(msg.encode('utf-8'))
if __name__ == '__main__': if __name__ == '__main__':
main() main()