Skip to content

Commit fc4dc26

Browse files
committed
make it possible to keep downloaded archive
1 parent db298e6 commit fc4dc26

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

load_into_pg.py

+18-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python3
1+
#!/usr/bin/env python
22
import sys
33
import time
44
import argparse
@@ -245,15 +245,15 @@ def handleTable(table, insertJson, createFk, mbDbFile, dbConnectionParam):
245245
if post != '':
246246
cur.execute(post)
247247
conn.commit()
248-
six.print_('Post processing took {} seconds'.format(time.time() - start_time))
248+
six.print_('Post processing took {0:.1f} seconds'.format(time.time() - start_time))
249249
if createFk:
250250
# fk-processing (creation of foreign keys)
251251
start_time = time.time()
252252
six.print_('fk processing ...')
253253
if post != '':
254254
cur.execute(fk)
255255
conn.commit()
256-
six.print_('fk processing took {} seconds'.format(time.time() - start_time))
256+
six.print_('fk processing took {0:.1f} seconds'.format(time.time() - start_time))
257257

258258
except IOError as e:
259259
six.print_("Could not read from file {}.".format(dbFile), file=sys.stderr)
@@ -393,19 +393,22 @@ def moveTableToSchema(table, schemaName, dbConnectionParam):
393393

394394
# load a project
395395
elif args.so_project:
396-
import urllib.request
397396
import libarchive
398397

399-
# download the 7z archive in /tmp
400-
file_name = args.so_project + '.stackexchange.com.7z'
401-
url = '{0}/{1}'.format(args.archive_url, file_name)
402-
filepath = '/tmp/'+file_name
403-
six.print_('Downloading the archive, please be patient ...')
404-
try:
405-
urllib.request.urlretrieve(url, filepath, show_progress)
406-
except Exception as e:
407-
six.print_('Error: impossible to download the {0} archive ({1})'.format(url, e))
408-
exit(1)
398+
filepath = None
399+
if args.file:
400+
filepath = args.file
401+
else:
402+
# download the 7z archive in /tmp
403+
file_name = args.so_project + '.stackexchange.com.7z'
404+
url = '{0}/{1}'.format(args.archive_url, file_name)
405+
filepath = '/tmp/'+file_name
406+
six.print_('Downloading the archive, please be patient ...')
407+
try:
408+
six.moves.urllib.request.urlretrieve(url, filepath, show_progress)
409+
except Exception as e:
410+
six.print_('Error: impossible to download the {0} archive ({1})'.format(url, e))
411+
exit(1)
409412

410413
try:
411414
libarchive.extract_file(filepath)
@@ -417,7 +420,7 @@ def moveTableToSchema(table, schemaName, dbConnectionParam):
417420

418421
for table in tables:
419422
six.print_('Load {0}.xml file'.format(table))
420-
handleTable(table, args.insert_json, args.foreign_keys, args.file, dbConnectionParam)
423+
handleTable(table, args.insert_json, args.foreign_keys, None, dbConnectionParam)
421424
# remove file
422425
os.remove(table+'.xml')
423426

0 commit comments

Comments
 (0)