Skip to content

Commit 66e0954

Browse files
committed
Python 3 preparation: miscellaneous Python scripts not named *.py.
1 parent 1ec8a76 commit 66e0954

File tree

6 files changed

+55
-50
lines changed

6 files changed

+55
-50
lines changed

frontends/roundup.cgi

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1818

1919
# python version check
20+
from __future__ import print_function
2021
from roundup import version_check
2122
from roundup.i18n import _
2223
import sys, time
@@ -73,11 +74,11 @@ try:
7374
import traceback, StringIO, cgi
7475
from roundup.cgi import cgitb
7576
except:
76-
print "Content-Type: text/plain\n"
77-
print _("Failed to import cgitb!\n\n")
77+
print("Content-Type: text/plain\n")
78+
print(_("Failed to import cgitb!\n\n"))
7879
s = StringIO.StringIO()
7980
traceback.print_exc(None, s)
80-
print s.getvalue()
81+
print(s.getvalue())
8182

8283

8384
#
@@ -89,7 +90,7 @@ def checkconfig():
8990

9091
# see if there's an environment var. ROUNDUP_INSTANCE_HOMES is the
9192
# old name for it.
92-
if os.environ.has_key('ROUNDUP_INSTANCE_HOMES'):
93+
if 'ROUNDUP_INSTANCE_HOMES' in os.environ:
9394
homes = os.environ.get('ROUNDUP_INSTANCE_HOMES')
9495
else:
9596
homes = os.environ.get('TRACKER_HOMES', '')
@@ -146,7 +147,7 @@ def main(out, err):
146147
tracker = path[1]
147148
os.environ['TRACKER_NAME'] = tracker
148149
os.environ['PATH_INFO'] = string.join(path[2:], '/')
149-
if TRACKER_HOMES.has_key(tracker):
150+
if tracker in TRACKER_HOMES:
150151
# redirect if we need a trailing '/'
151152
if len(path) == 2:
152153
request.send_response(301)
@@ -182,19 +183,18 @@ def main(out, err):
182183
out.write('Not found: %s'%client.path)
183184

184185
else:
185-
import urllib
186+
from roundup.anypy import urllib_
186187
request.send_response(200)
187188
request.send_header('Content-Type', 'text/html')
188189
request.end_headers()
189190
w = request.write
190191
w(_('<html><head><title>Roundup trackers index</title></head>\n'))
191192
w(_('<body><h1>Roundup trackers index</h1><ol>\n'))
192-
homes = TRACKER_HOMES.keys()
193-
homes.sort()
193+
homes = sorted(TRACKER_HOMES.keys())
194194
for tracker in homes:
195195
w(_('<li><a href="%(tracker_url)s/index">%(tracker_name)s</a>\n')%{
196196
'tracker_url': os.environ['SCRIPT_NAME']+'/'+
197-
urllib.quote(tracker),
197+
urllib_.quote(tracker),
198198
'tracker_name': cgi.escape(tracker)})
199199
w(_('</ol></body></html>'))
200200

@@ -223,7 +223,7 @@ except:
223223
ts = time.ctime()
224224
out.write('''<p>%s: An error occurred. Please check
225225
the server log for more information.</p>'''%ts)
226-
print >> sys.stderr, 'EXCEPTION AT', ts
226+
print('EXCEPTION AT', ts, file=sys.stderr)
227227
traceback.print_exc(0, sys.stderr)
228228

229229
sys.stdout.flush()

scripts/add-issue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@ created as the current user (%s) if they exist as a Roundup
88
user, or "admin" otherwise.
99
'''
1010

11+
from __future__ import print_function
1112
import sys, os, pwd
1213

1314
from roundup import instance, mailgw, date
1415

1516
# open the instance
1617
username = pwd.getpwuid(os.getuid())[0]
1718
if len(sys.argv) < 3:
18-
print "Error: Not enough arguments"
19-
print __doc__.strip()%(sys.argv[0], username)
19+
print("Error: Not enough arguments")
20+
print(__doc__.strip()%(sys.argv[0], username))
2021
sys.exit(1)
2122
tracker_home = sys.argv[1]
2223
issue_priority = sys.argv[2]

scripts/roundup-reminder

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@ TODO: introduce some structure ;)
2727
TODO: possibly make this more general and configurable...
2828
'''
2929

30+
from __future__ import print_function
3031
import sys, cStringIO, MimeWriter, smtplib
3132
from roundup import instance, date
3233
from roundup.mailer import SMTPConnection
3334

3435
# open the instance
3536
if len(sys.argv) != 2:
36-
print 'You need to specify an instance home dir'
37+
print('You need to specify an instance home dir')
3738
instance_home = sys.argv[1]
3839
instance = instance.open(instance_home)
3940
db = instance.open('admin')
@@ -94,32 +95,32 @@ for user_id in db.user.list():
9495
body = part.startbody('text/plain')
9596

9697
# do the plain text bit
97-
print >>body, 'Created ID Activity Title'
98-
print >>body, '='*75
98+
print('Created ID Activity Title', file=body)
99+
print('='*75, file=body)
99100
# '2 months 213 immediate cc_daemon barfage
100101
old_priority = None
101102
for priority_order, activity_date, creation_date, issue_id in l:
102103
priority = db.issue.get(issue_id, 'priority')
103104
if (priority != old_priority):
104105
old_priority = priority
105-
print >>body, ' ', db.priority.get(priority,'name')
106+
print(' ', db.priority.get(priority,'name'), file=body)
106107
# pretty creation
107108
creation = (creation_date - date.Date('.')).pretty()
108109
activity = (activity_date - date.Date('.')).pretty()
109110
title = db.issue.get(issue_id, 'title')
110111
if len(title) > 42:
111112
title = title[:38] + ' ...'
112-
print >>body, '%-11s %-4s %-9s %-42s'%(creation, issue_id,
113-
activity, title)
113+
print('%-11s %-4s %-9s %-42s'%(creation, issue_id,
114+
activity, title), file=body)
114115

115116
# some help to finish off
116-
print >>body, '''
117+
print('''
117118
To view or respond to any of the issues listed above, visit the URL
118119
119120
%s
120121
121122
and click on "My Issues". Do NOT respond to this message.
122-
'''%db.config.TRACKER_WEB
123+
'''%db.config.TRACKER_WEB, file=body)
123124

124125

125126
# now the HTML one
@@ -132,27 +133,27 @@ and click on "My Issues". Do NOT respond to this message.
132133
'month': ' bgcolor="#ffffcd"',
133134
'whenever': ' bgcolor="#ffffff"',
134135
}
135-
print >>body, '''<table border>
136+
print('''<table border>
136137
<tr><th>Created</th> <th>ID</th> <th>Activity</th> <th>Title</th></tr>
137-
'''
138+
''', file=body)
138139
old_priority = None
139140
for priority_order, activity_date, creation_date, issue_id in l:
140141
priority = db.issue.get(issue_id,'priority')
141142
if (priority != old_priority):
142143
old_priority = priority
143-
print >>body, '<tr><td>-></td><td>-></td><td>-></td><td><b>%s</b></td></tr>'%db.priority.get(priority,'name')
144+
print('<tr><td>-></td><td>-></td><td>-></td><td><b>%s</b></td></tr>'%db.priority.get(priority,'name'), file=body)
144145
creation = (creation_date - date.Date('.')).pretty()
145146
title = db.issue.get(issue_id, 'title')
146147
issue_id = '<a href="%sissue%s">%s</a>'%(db.config.TRACKER_WEB,
147148
issue_id, issue_id)
148149
activity = (activity_date - date.Date('.')).pretty()
149-
print >>body, '''<tr><td>%s</td><td>%s</td><td>%s</td>
150-
<td>%s</td></tr>'''%(creation, issue_id, activity, title)
151-
print >>body, '</table>'
150+
print('''<tr><td>%s</td><td>%s</td><td>%s</td>
151+
<td>%s</td></tr>'''%(creation, issue_id, activity, title), file=body)
152+
print('</table>', file=body)
152153

153-
print >>body, '''<p>To view or respond to any of the issues listed
154+
print('''<p>To view or respond to any of the issues listed
154155
above, simply click on the issue ID. Do <b>not</b> respond to
155-
this message.</p>'''
156+
this message.</p>''', file=body)
156157

157158
# finish of the multipart
158159
writer.lastpart()

scripts/spam-remover

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2323
# SOFTWARE.
2424

25+
from __future__ import print_function
2526
_doc = '''
2627
%prog [options]
2728
Remove file attachment spam from a tracker:
@@ -89,7 +90,7 @@ def main():
8990
opt, args = cmd.parse_args()
9091
# open the instance
9192
if len(args):
92-
print >> sys.stderr, "This command doesn't take arguments"
93+
print("This command doesn't take arguments", file=sys.stderr)
9394
cmd.show_help()
9495
tracker = instance.open(opt.instance)
9596
db = tracker.open('admin')
@@ -110,21 +111,21 @@ def main():
110111
clsname, id = hyperdb.splitDesignator(d)
111112
cls = db.getclass(clsname)
112113
issuefiles = dict.fromkeys(cls.get (id, 'files'))
113-
for fid in issuefiles.keys():
114+
for fid in list(issuefiles.keys()):
114115
f = db.file.getnode(fid)
115116
if fid in files_to_remove or f.creator in users:
116117
files_to_remove[fid] = True
117118
files_found[fid] = True
118119
if not opt.quiet:
119-
print "deleting file %s from issue" % f
120+
print("deleting file %s from issue" % f)
120121
del issuefiles[fid]
121122
if opt.doit:
122-
cls.set(id, files=issuefiles.keys())
123+
cls.set(id, files=list(issuefiles.keys()))
123124
journal = oldjournal = db.getjournal(clsname, id)
124125
# do this twice, we may have file-removals *before* file
125126
# additions for files to delete and may discover mid-journal
126127
# that there are new files to remove
127-
for x in xrange(2):
128+
for x in range(2):
128129
newjournal = []
129130
for j in journal:
130131
if j[3] == 'set' and 'files' in j[4]:
@@ -138,8 +139,8 @@ def main():
138139
files_found.update(f)
139140
files_to_remove.update(f)
140141
del changes['+']
141-
# change dict in-place, don't use iteritems
142-
for k, v in changes.items():
142+
# change dict in-place
143+
for k, v in list(changes.items()):
143144
new_f = []
144145
for f in v:
145146
if f in files_to_remove:
@@ -154,7 +155,7 @@ def main():
154155
if not opt.quiet:
155156
msg.append ("Old journal entry: %s" % str(j))
156157
if changes:
157-
j[4]['files'] = tuple(changes.iteritems())
158+
j[4]['files'] = tuple(changes.items())
158159
else:
159160
del j[4]['files']
160161
if j[4]:
@@ -165,7 +166,7 @@ def main():
165166
msg.append ("deleted")
166167
if len(msg) == 2 and msg[0][4:] != msg[1][4:]:
167168
for m in msg:
168-
print m
169+
print(m)
169170
else:
170171
newjournal.append(j)
171172
journal = newjournal
@@ -176,7 +177,7 @@ def main():
176177
db.file.set(f, content=' ')
177178
db.commit()
178179
else:
179-
print "Database not changed"
180+
print("Database not changed")
180181

181182

182183
if __name__ == '__main__':

scripts/weekly-report

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
# This script is free software, you may redistribute it
77
# and/or modify under the same terms as Python.
88

9+
from __future__ import print_function
910
import sys, math
1011
from roundup import instance, date
1112

1213
# open the instance
1314
if len(sys.argv) != 2:
14-
print 'You need to specify an instance home dir'
15+
print('You need to specify an instance home dir')
1516
instance_home = sys.argv[1]
1617
instance = instance.open(instance_home)
1718
db = instance.open('admin')
@@ -29,7 +30,7 @@ for issue_id in db.issue.filter(None, {'activity': '-1w;'}):
2930
if ts < old: continue
3031
if action == 'create':
3132
created.append(issue_id)
32-
elif action == 'set' and data.has_key('messages'):
33+
elif action == 'set' and 'messages' in data:
3334
num += 1
3435
summary.setdefault(db.issue.get(issue_id, 'status'), []).append(issue_id)
3536
messages.append((num, issue_id))
@@ -38,21 +39,21 @@ for issue_id in db.issue.filter(None, {'activity': '-1w;'}):
3839
#for k,v in summary.items():
3940
# print k, len(v)
4041

41-
print '\nCREATED:'
42-
print '\n'.join(['%s: %s'%(id, db.issue.get(id, 'title'))
43-
for id in created])
42+
print('\nCREATED:')
43+
print('\n'.join(['%s: %s'%(id, db.issue.get(id, 'title'))
44+
for id in created]))
4445

45-
print '\nRESOLVED:'
46+
print('\nRESOLVED:')
4647
resolved_id = db.status.lookup('resolved')
47-
print '\n'.join(['%s: %s'%(id, db.issue.get(id, 'title'))
48-
for id in summary.get(resolved_id, [])])
48+
print('\n'.join(['%s: %s'%(id, db.issue.get(id, 'title'))
49+
for id in summary.get(resolved_id, [])]))
4950

50-
print '\nTOP TEN MOST DISCUSSED:'
51+
print('\nTOP TEN MOST DISCUSSED:')
5152
messages.sort()
5253
messages.reverse()
5354
nmax = messages[0][0]
5455
fmt = '%%%dd - %%s: %%s'%(int(math.log(nmax, 10)) + 1)
55-
print '\n'.join([fmt%(num, id, db.issue.get(id, 'title'))
56-
for num, id in messages[:10]])
56+
print('\n'.join([fmt%(num, id, db.issue.get(id, 'title'))
57+
for num, id in messages[:10]]))
5758

5859
# vim: set filetype=python ts=4 sw=4 et si

tools/base64

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
#!/usr/bin/env python
2+
from __future__ import print_function
23
import zlib, base64, sys
3-
print base64.encodestring(zlib.compress(sys.stdin.read()))
4+
print(base64.encodestring(zlib.compress(sys.stdin.read())))

0 commit comments

Comments
 (0)