Skip to content

Commit f4bf374

Browse files
Make demo.py run under either Python 2 or 3.
1 parent 7729750 commit f4bf374

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

roundup/demo.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@
22
#
33
# Copyright (c) 2003 Richard Jones ([email protected])
44
#
5+
from __future__ import print_function
56

67
import errno
78
import os
89
import shutil
910
import socket
1011
import sys
11-
import urlparse
1212
import getopt
1313

14+
try:
15+
import urlparse
16+
except ImportError:
17+
import urllib.parse as urlparse
18+
1419
from roundup import configuration
1520
from roundup.scripts import roundup_server
1621

@@ -51,11 +56,11 @@ def install_demo(home, backend, template):
5156
if os.path.exists(home + '/config.ini'):
5257
# clear everything out to avoid conflicts with former
5358
# extensions and detectors
54-
print "Nuking directory left from the previous demo instance."
59+
print("Nuking directory left from the previous demo instance.")
5560
shutil.rmtree(home)
5661
else:
57-
print "Error: Refusing to nuke non-tracker directory:"
58-
print " %s" % home
62+
print("Error: Refusing to nuke non-tracker directory:")
63+
print(" %s" % home)
5964
sys.exit(1)
6065

6166
template_dir = os.path.join('share', 'roundup', 'templates', template)
@@ -73,19 +78,19 @@ def install_demo(home, backend, template):
7378
# pick a fairly odd, random port
7479
port = 8917
7580
while 1:
76-
print 'Trying to set up web server on port %d ...'%port,
81+
print('Trying to set up web server on port %d ...'%port,)
7782
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
7883
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
7984
try:
8085
s.connect((hostname, port))
81-
except socket.error, e:
86+
except socket.error as e:
8287
if not hasattr(e, 'args') or e.args[0] != errno.ECONNREFUSED:
8388
raise
84-
print 'should be ok.'
89+
print('should be ok.')
8590
break
8691
else:
8792
s.close()
88-
print 'already in use.'
93+
print('already in use.')
8994
port += 100
9095
config['TRACKER_WEB'] = 'http://%s:%s/demo/'%(hostname, port)
9196

@@ -117,7 +122,7 @@ def install_demo(home, backend, template):
117122

118123
def run_demo(home):
119124
"""Run the demo tracker instance from its ``home`` directory"""
120-
print "Demo Tracker Home:", home
125+
print("Demo Tracker Home:", home)
121126

122127
cfg = configuration.CoreConfig(home)
123128
url = cfg["TRACKER_WEB"]
@@ -145,8 +150,8 @@ def run_demo(home):
145150

146151
def usage(msg = ''):
147152
if msg:
148-
print msg
149-
print """\
153+
print(msg)
154+
print("""\
150155
Usage: %(script)s [options] [nuke]
151156
152157
Run a demo server. Config and database files are created in
@@ -160,7 +165,7 @@ def usage(msg = ''):
160165
-h -- print this help message
161166
-t template -- specify the tracker template to use
162167
-b backend -- specify the database backend to use
163-
""" % dict(script=sys.argv[0], datadir=TRACKER_HOME+os.sep)
168+
""" % dict(script=sys.argv[0], datadir=TRACKER_HOME+os.sep))
164169

165170

166171
def main():
@@ -171,7 +176,7 @@ def main():
171176

172177
try:
173178
opts, args = getopt.getopt(sys.argv[1:], 't:b:h')
174-
except getopt.GetoptError, e:
179+
except getopt.GetoptError as e:
175180
usage(str(e))
176181
return 1
177182
for opt, arg in opts:
@@ -194,11 +199,11 @@ def main():
194199
usage()
195200
return 1
196201

197-
print "Initializing demo instance in:\n %s" % home
202+
print("Initializing demo instance in:\n %s" % home)
198203
install_demo(home, backend, template)
199204
elif opts:
200-
print "Error: Arguments are not allowed when running an existing demo."
201-
print " Use the 'nuke' command to start over."
205+
print("Error: Arguments are not allowed when running an existing demo.")
206+
print(" Use the 'nuke' command to start over.")
202207
sys.exit(1)
203208

204209
run_demo(home)

0 commit comments

Comments
 (0)