Mercurial > p > roundup > code
changeset 5412:c75defc1c2f0
Python 3 preparation: miscellaneous Python scripts not named *.py.
| author | Joseph Myers <jsm@polyomino.org.uk> |
|---|---|
| date | Wed, 25 Jul 2018 00:36:40 +0000 |
| parents | 9c6d98bf79db |
| children | 7a41dd2abbbd |
| files | frontends/roundup.cgi scripts/add-issue scripts/roundup-reminder scripts/spam-remover scripts/weekly-report tools/base64 |
| diffstat | 6 files changed, 55 insertions(+), 50 deletions(-) [+] |
line wrap: on
line diff
--- a/frontends/roundup.cgi Wed Jul 25 00:35:49 2018 +0000 +++ b/frontends/roundup.cgi Wed Jul 25 00:36:40 2018 +0000 @@ -17,6 +17,7 @@ # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # python version check +from __future__ import print_function from roundup import version_check from roundup.i18n import _ import sys, time @@ -73,11 +74,11 @@ import traceback, StringIO, cgi from roundup.cgi import cgitb except: - print "Content-Type: text/plain\n" - print _("Failed to import cgitb!\n\n") + print("Content-Type: text/plain\n") + print(_("Failed to import cgitb!\n\n")) s = StringIO.StringIO() traceback.print_exc(None, s) - print s.getvalue() + print(s.getvalue()) # @@ -89,7 +90,7 @@ # see if there's an environment var. ROUNDUP_INSTANCE_HOMES is the # old name for it. - if os.environ.has_key('ROUNDUP_INSTANCE_HOMES'): + if 'ROUNDUP_INSTANCE_HOMES' in os.environ: homes = os.environ.get('ROUNDUP_INSTANCE_HOMES') else: homes = os.environ.get('TRACKER_HOMES', '') @@ -146,7 +147,7 @@ tracker = path[1] os.environ['TRACKER_NAME'] = tracker os.environ['PATH_INFO'] = string.join(path[2:], '/') - if TRACKER_HOMES.has_key(tracker): + if tracker in TRACKER_HOMES: # redirect if we need a trailing '/' if len(path) == 2: request.send_response(301) @@ -182,19 +183,18 @@ out.write('Not found: %s'%client.path) else: - import urllib + from roundup.anypy import urllib_ request.send_response(200) request.send_header('Content-Type', 'text/html') request.end_headers() w = request.write w(_('<html><head><title>Roundup trackers index</title></head>\n')) w(_('<body><h1>Roundup trackers index</h1><ol>\n')) - homes = TRACKER_HOMES.keys() - homes.sort() + homes = sorted(TRACKER_HOMES.keys()) for tracker in homes: w(_('<li><a href="%(tracker_url)s/index">%(tracker_name)s</a>\n')%{ 'tracker_url': os.environ['SCRIPT_NAME']+'/'+ - urllib.quote(tracker), + urllib_.quote(tracker), 'tracker_name': cgi.escape(tracker)}) w(_('</ol></body></html>')) @@ -223,7 +223,7 @@ ts = time.ctime() out.write('''<p>%s: An error occurred. Please check the server log for more information.</p>'''%ts) - print >> sys.stderr, 'EXCEPTION AT', ts + print('EXCEPTION AT', ts, file=sys.stderr) traceback.print_exc(0, sys.stderr) sys.stdout.flush()
--- a/scripts/add-issue Wed Jul 25 00:35:49 2018 +0000 +++ b/scripts/add-issue Wed Jul 25 00:36:40 2018 +0000 @@ -8,6 +8,7 @@ user, or "admin" otherwise. ''' +from __future__ import print_function import sys, os, pwd from roundup import instance, mailgw, date @@ -15,8 +16,8 @@ # open the instance username = pwd.getpwuid(os.getuid())[0] if len(sys.argv) < 3: - print "Error: Not enough arguments" - print __doc__.strip()%(sys.argv[0], username) + print("Error: Not enough arguments") + print(__doc__.strip()%(sys.argv[0], username)) sys.exit(1) tracker_home = sys.argv[1] issue_priority = sys.argv[2]
--- a/scripts/roundup-reminder Wed Jul 25 00:35:49 2018 +0000 +++ b/scripts/roundup-reminder Wed Jul 25 00:36:40 2018 +0000 @@ -27,13 +27,14 @@ TODO: possibly make this more general and configurable... ''' +from __future__ import print_function import sys, cStringIO, MimeWriter, smtplib from roundup import instance, date from roundup.mailer import SMTPConnection # open the instance if len(sys.argv) != 2: - print 'You need to specify an instance home dir' + print('You need to specify an instance home dir') instance_home = sys.argv[1] instance = instance.open(instance_home) db = instance.open('admin') @@ -94,32 +95,32 @@ body = part.startbody('text/plain') # do the plain text bit - print >>body, 'Created ID Activity Title' - print >>body, '='*75 + print('Created ID Activity Title', file=body) + print('='*75, file=body) # '2 months 213 immediate cc_daemon barfage old_priority = None for priority_order, activity_date, creation_date, issue_id in l: priority = db.issue.get(issue_id, 'priority') if (priority != old_priority): old_priority = priority - print >>body, ' ', db.priority.get(priority,'name') + print(' ', db.priority.get(priority,'name'), file=body) # pretty creation creation = (creation_date - date.Date('.')).pretty() activity = (activity_date - date.Date('.')).pretty() title = db.issue.get(issue_id, 'title') if len(title) > 42: title = title[:38] + ' ...' - print >>body, '%-11s %-4s %-9s %-42s'%(creation, issue_id, - activity, title) + print('%-11s %-4s %-9s %-42s'%(creation, issue_id, + activity, title), file=body) # some help to finish off - print >>body, ''' + print(''' To view or respond to any of the issues listed above, visit the URL %s and click on "My Issues". Do NOT respond to this message. -'''%db.config.TRACKER_WEB +'''%db.config.TRACKER_WEB, file=body) # now the HTML one @@ -132,27 +133,27 @@ 'month': ' bgcolor="#ffffcd"', 'whenever': ' bgcolor="#ffffff"', } - print >>body, '''<table border> + print('''<table border> <tr><th>Created</th> <th>ID</th> <th>Activity</th> <th>Title</th></tr> -''' +''', file=body) old_priority = None for priority_order, activity_date, creation_date, issue_id in l: priority = db.issue.get(issue_id,'priority') if (priority != old_priority): old_priority = priority - print >>body, '<tr><td>-></td><td>-></td><td>-></td><td><b>%s</b></td></tr>'%db.priority.get(priority,'name') + print('<tr><td>-></td><td>-></td><td>-></td><td><b>%s</b></td></tr>'%db.priority.get(priority,'name'), file=body) creation = (creation_date - date.Date('.')).pretty() title = db.issue.get(issue_id, 'title') issue_id = '<a href="%sissue%s">%s</a>'%(db.config.TRACKER_WEB, issue_id, issue_id) activity = (activity_date - date.Date('.')).pretty() - print >>body, '''<tr><td>%s</td><td>%s</td><td>%s</td> - <td>%s</td></tr>'''%(creation, issue_id, activity, title) - print >>body, '</table>' + print('''<tr><td>%s</td><td>%s</td><td>%s</td> + <td>%s</td></tr>'''%(creation, issue_id, activity, title), file=body) + print('</table>', file=body) - print >>body, '''<p>To view or respond to any of the issues listed + print('''<p>To view or respond to any of the issues listed above, simply click on the issue ID. Do <b>not</b> respond to - this message.</p>''' + this message.</p>''', file=body) # finish of the multipart writer.lastpart()
--- a/scripts/spam-remover Wed Jul 25 00:35:49 2018 +0000 +++ b/scripts/spam-remover Wed Jul 25 00:36:40 2018 +0000 @@ -22,6 +22,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. +from __future__ import print_function _doc = ''' %prog [options] Remove file attachment spam from a tracker: @@ -89,7 +90,7 @@ opt, args = cmd.parse_args() # open the instance if len(args): - print >> sys.stderr, "This command doesn't take arguments" + print("This command doesn't take arguments", file=sys.stderr) cmd.show_help() tracker = instance.open(opt.instance) db = tracker.open('admin') @@ -110,21 +111,21 @@ clsname, id = hyperdb.splitDesignator(d) cls = db.getclass(clsname) issuefiles = dict.fromkeys(cls.get (id, 'files')) - for fid in issuefiles.keys(): + for fid in list(issuefiles.keys()): f = db.file.getnode(fid) if fid in files_to_remove or f.creator in users: files_to_remove[fid] = True files_found[fid] = True if not opt.quiet: - print "deleting file %s from issue" % f + print("deleting file %s from issue" % f) del issuefiles[fid] if opt.doit: - cls.set(id, files=issuefiles.keys()) + cls.set(id, files=list(issuefiles.keys())) journal = oldjournal = db.getjournal(clsname, id) # do this twice, we may have file-removals *before* file # additions for files to delete and may discover mid-journal # that there are new files to remove - for x in xrange(2): + for x in range(2): newjournal = [] for j in journal: if j[3] == 'set' and 'files' in j[4]: @@ -138,8 +139,8 @@ files_found.update(f) files_to_remove.update(f) del changes['+'] - # change dict in-place, don't use iteritems - for k, v in changes.items(): + # change dict in-place + for k, v in list(changes.items()): new_f = [] for f in v: if f in files_to_remove: @@ -154,7 +155,7 @@ if not opt.quiet: msg.append ("Old journal entry: %s" % str(j)) if changes: - j[4]['files'] = tuple(changes.iteritems()) + j[4]['files'] = tuple(changes.items()) else: del j[4]['files'] if j[4]: @@ -165,7 +166,7 @@ msg.append ("deleted") if len(msg) == 2 and msg[0][4:] != msg[1][4:]: for m in msg: - print m + print(m) else: newjournal.append(j) journal = newjournal @@ -176,7 +177,7 @@ db.file.set(f, content=' ') db.commit() else: - print "Database not changed" + print("Database not changed") if __name__ == '__main__':
--- a/scripts/weekly-report Wed Jul 25 00:35:49 2018 +0000 +++ b/scripts/weekly-report Wed Jul 25 00:36:40 2018 +0000 @@ -6,12 +6,13 @@ # This script is free software, you may redistribute it # and/or modify under the same terms as Python. +from __future__ import print_function import sys, math from roundup import instance, date # open the instance if len(sys.argv) != 2: - print 'You need to specify an instance home dir' + print('You need to specify an instance home dir') instance_home = sys.argv[1] instance = instance.open(instance_home) db = instance.open('admin') @@ -29,7 +30,7 @@ if ts < old: continue if action == 'create': created.append(issue_id) - elif action == 'set' and data.has_key('messages'): + elif action == 'set' and 'messages' in data: num += 1 summary.setdefault(db.issue.get(issue_id, 'status'), []).append(issue_id) messages.append((num, issue_id)) @@ -38,21 +39,21 @@ #for k,v in summary.items(): # print k, len(v) -print '\nCREATED:' -print '\n'.join(['%s: %s'%(id, db.issue.get(id, 'title')) - for id in created]) +print('\nCREATED:') +print('\n'.join(['%s: %s'%(id, db.issue.get(id, 'title')) + for id in created])) -print '\nRESOLVED:' +print('\nRESOLVED:') resolved_id = db.status.lookup('resolved') -print '\n'.join(['%s: %s'%(id, db.issue.get(id, 'title')) - for id in summary.get(resolved_id, [])]) +print('\n'.join(['%s: %s'%(id, db.issue.get(id, 'title')) + for id in summary.get(resolved_id, [])])) -print '\nTOP TEN MOST DISCUSSED:' +print('\nTOP TEN MOST DISCUSSED:') messages.sort() messages.reverse() nmax = messages[0][0] fmt = '%%%dd - %%s: %%s'%(int(math.log(nmax, 10)) + 1) -print '\n'.join([fmt%(num, id, db.issue.get(id, 'title')) - for num, id in messages[:10]]) +print('\n'.join([fmt%(num, id, db.issue.get(id, 'title')) + for num, id in messages[:10]])) # vim: set filetype=python ts=4 sw=4 et si
--- a/tools/base64 Wed Jul 25 00:35:49 2018 +0000 +++ b/tools/base64 Wed Jul 25 00:36:40 2018 +0000 @@ -1,3 +1,4 @@ #!/usr/bin/env python +from __future__ import print_function import zlib, base64, sys -print base64.encodestring(zlib.compress(sys.stdin.read())) +print(base64.encodestring(zlib.compress(sys.stdin.read())))
