1
- #!/usr/bin/env python3
1
+ #!/usr/bin/env python
2
2
import sys
3
3
import time
4
4
import argparse
@@ -245,15 +245,15 @@ def handleTable(table, insertJson, createFk, mbDbFile, dbConnectionParam):
245
245
if post != '' :
246
246
cur .execute (post )
247
247
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 ))
249
249
if createFk :
250
250
# fk-processing (creation of foreign keys)
251
251
start_time = time .time ()
252
252
six .print_ ('fk processing ...' )
253
253
if post != '' :
254
254
cur .execute (fk )
255
255
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 ))
257
257
258
258
except IOError as e :
259
259
six .print_ ("Could not read from file {}." .format (dbFile ), file = sys .stderr )
@@ -393,19 +393,22 @@ def moveTableToSchema(table, schemaName, dbConnectionParam):
393
393
394
394
# load a project
395
395
elif args .so_project :
396
- import urllib .request
397
396
import libarchive
398
397
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 )
409
412
410
413
try :
411
414
libarchive .extract_file (filepath )
@@ -417,7 +420,7 @@ def moveTableToSchema(table, schemaName, dbConnectionParam):
417
420
418
421
for table in tables :
419
422
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 )
421
424
# remove file
422
425
os .remove (table + '.xml' )
423
426
0 commit comments