Skip to content

Commit a5a4d25

Browse files
authored
Merge pull request Networks-Learning#4 from italo-batista/fix/python_3_compat
Make Python 3 compatible
2 parents a6d8547 + f34a091 commit a5a4d25

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
*.pyc
55
.env/
66
private/
7+
./idea

load_into_pg.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ def handleTable(table, keys, dbname, mbDbFile, mbHost, mbPort, mbUsername, mbPas
4242
start_time = time.time()
4343

4444
try:
45-
pre = file('./sql/' + table + '_pre.sql').read()
46-
post = file('./sql/' + table + '_post.sql').read()
45+
pre = open('./sql/' + table + '_pre.sql').read()
46+
post = open('./sql/' + table + '_post.sql').read()
4747
except IOError as e:
4848
print >> sys.stderr, "Could not load pre/post sql. Are you running from the correct path?"
4949
sys.exit(-1)
@@ -70,15 +70,15 @@ def handleTable(table, keys, dbname, mbDbFile, mbHost, mbPort, mbUsername, mbPas
7070
try:
7171
with open(dbFile) as xml:
7272
# Pre-processing (dropping/creation of tables)
73-
print 'Pre-processing ...'
73+
print ('Pre-processing ...')
7474
if pre != '':
7575
cur.execute(pre)
7676
conn.commit()
77-
print 'Pre-processing took {:.1f} seconds'.format(time.time() - start_time)
77+
print ('Pre-processing took {:.1f} seconds'.format(time.time() - start_time))
7878

7979
# Handle content of the table
8080
start_time = time.time()
81-
print 'Processing data ...'
81+
print ('Processing data ...')
8282
for rows in Processor.batch(Processor.parse(xml), 500):
8383
valuesStr = ',\n'.join(
8484
[ _createCmdTuple(cur, keys, tmpl, row_attribs)
@@ -91,26 +91,26 @@ def handleTable(table, keys, dbname, mbDbFile, mbHost, mbPort, mbUsername, mbPas
9191
' VALUES\n' + valuesStr + ';'
9292
cur.execute(cmd)
9393
conn.commit()
94-
print 'Table processing took {:.1f} seconds'.format(time.time() - start_time)
94+
print ('Table processing took {:.1f} seconds'.format(time.time() - start_time))
9595

9696
# Post-processing (creation of indexes)
9797
start_time = time.time()
98-
print 'Post processing ...'
98+
print ('Post processing ...')
9999
if post != '':
100100
cur.execute(post)
101101
conn.commit()
102-
print 'Post processing took {} seconds'.format(time.time() - start_time)
102+
print ('Post processing took {} seconds'.format(time.time() - start_time))
103103

104104
except IOError as e:
105-
print >> sys.stderr, "Could not read from file {}.".format(dbFile)
106-
print >> sys.stderr, "IOError: {0}".format(e.strerror)
105+
print ("Could not read from file {}.".format(dbFile), file=sys.stderr)
106+
print ("IOError: {0}".format(e.strerror), file=sys.stderr)
107107
except pg.Error as e:
108-
print >> sys.stderr, "Error in dealing with the database."
109-
print >> sys.stderr, "pg.Error ({0}): {1}".format(e.pgcode, e.pgerror)
110-
print >> sys.stderr, str(e)
108+
print ("Error in dealing with the database.", file=sys.stderr)
109+
print ("pg.Error ({0}): {1}".format(e.pgcode, e.pgerror), file=sys.stderr)
110+
print (str(e), file=sys.stderr)
111111
except pg.Warning as w:
112-
print >> sys.stderr, "Warning from the database."
113-
print >> sys.stderr, "pg.Warning: {0}".format(str(w))
112+
print ("Warning from the database.", file=sys.stderr)
113+
print ("pg.Warning: {0}".format(str(w)), file=sys.stderr)
114114

115115

116116

@@ -268,10 +268,10 @@ def handleTable(table, keys, dbname, mbDbFile, mbHost, mbPort, mbUsername, mbPas
268268
'CreationDate',
269269
'UserId',
270270
]
271-
choice = raw_input('This will drop the {} table. Are you sure [y/n]?'.format(table))
271+
choice = input('This will drop the {} table. Are you sure [y/n]?'.format(table))
272272

273273
if len(choice) > 0 and choice[0].lower() == 'y':
274274
handleTable(table, keys, args.dbname, args.file, args.host, args.port, args.username, args.password)
275275
else:
276-
print "Cancelled."
276+
print ("Cancelled.")
277277

0 commit comments

Comments
 (0)