Improve log flow
parent
271d4cafd6
commit
d350dc0bdb
30
camelot.py
30
camelot.py
|
|
@ -125,6 +125,7 @@ if __name__ == '__main__':
|
||||||
froot, fext = os.path.splitext(fname)
|
froot, fext = os.path.splitext(fname)
|
||||||
if fext.lower() != '.pdf':
|
if fext.lower() != '.pdf':
|
||||||
print "camelot can parse only pdfs right now"
|
print "camelot can parse only pdfs right now"
|
||||||
|
shutil.rmtree(tmpdir)
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
logfname = os.path.join(tmpdir, froot + '.log')
|
logfname = os.path.join(tmpdir, froot + '.log')
|
||||||
|
|
@ -156,8 +157,7 @@ if __name__ == '__main__':
|
||||||
invert=args['--invert'], debug=args['--debug'])
|
invert=args['--invert'], debug=args['--debug'])
|
||||||
if data is None:
|
if data is None:
|
||||||
print
|
print
|
||||||
print "See 'camelot lattice -h' for various parameters you can tweak."
|
continue
|
||||||
sys.exit()
|
|
||||||
for k in sorted(data.keys()):
|
for k in sorted(data.keys()):
|
||||||
csvfile = g_froot + '_%s.csv' % k
|
csvfile = g_froot + '_%s.csv' % k
|
||||||
with open(csvfile, 'w') as outfile:
|
with open(csvfile, 'w') as outfile:
|
||||||
|
|
@ -183,8 +183,7 @@ if __name__ == '__main__':
|
||||||
debug=args['--debug'])
|
debug=args['--debug'])
|
||||||
if data is None:
|
if data is None:
|
||||||
print
|
print
|
||||||
print "See 'camelot stream -h' for various parameters you can tweak."
|
continue
|
||||||
sys.exit()
|
|
||||||
csvfile = g_froot + '.csv'
|
csvfile = g_froot + '.csv'
|
||||||
with open(csvfile, 'w') as outfile:
|
with open(csvfile, 'w') as outfile:
|
||||||
writer = csv.writer(outfile)
|
writer = csv.writer(outfile)
|
||||||
|
|
@ -197,17 +196,24 @@ if __name__ == '__main__':
|
||||||
print "couldn't parse", g_fname, "see log for more info"
|
print "couldn't parse", g_fname, "see log for more info"
|
||||||
print
|
print
|
||||||
|
|
||||||
|
if args['--log']:
|
||||||
|
if args['--output']:
|
||||||
|
shutil.copy(logfname, args['--output'])
|
||||||
|
else:
|
||||||
|
shutil.copy(logfname, fdir)
|
||||||
|
|
||||||
|
if args['--debug'] not in [None, False]:
|
||||||
|
print "See 'camelot <method> -h' for various parameters you can tweak."
|
||||||
|
shutil.rmtree(tmpdir)
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
glob_csv = sorted(glob.glob(os.path.join(tmpdir, '*.csv')), key=filesort)
|
glob_csv = sorted(glob.glob(os.path.join(tmpdir, '*.csv')), key=filesort)
|
||||||
if args['--format'] == 'csv':
|
if args['--format'] == 'csv':
|
||||||
if len(glob_csv) == 1:
|
if len(glob_csv) == 1:
|
||||||
if args['--output']:
|
if args['--output']:
|
||||||
shutil.copy(glob_csv[0], args['--output'])
|
shutil.copy(glob_csv[0], args['--output'])
|
||||||
if args['--log']:
|
|
||||||
shutil.copy(logfname, args['--output'])
|
|
||||||
else:
|
else:
|
||||||
shutil.copy(glob_csv[0], fdir)
|
shutil.copy(glob_csv[0], fdir)
|
||||||
if args['--log']:
|
|
||||||
shutil.copy(zippath, fdir)
|
|
||||||
else:
|
else:
|
||||||
zipname = froot + '.zip'
|
zipname = froot + '.zip'
|
||||||
zippath = os.path.join(tmpdir, zipname)
|
zippath = os.path.join(tmpdir, zipname)
|
||||||
|
|
@ -217,12 +223,8 @@ if __name__ == '__main__':
|
||||||
myzip.write(g, os.path.join(froot, os.path.basename(g)))
|
myzip.write(g, os.path.join(froot, os.path.basename(g)))
|
||||||
if args['--output']:
|
if args['--output']:
|
||||||
shutil.copy(zippath, args['--output'])
|
shutil.copy(zippath, args['--output'])
|
||||||
if args['--log']:
|
|
||||||
shutil.copy(logfname, args['--output'])
|
|
||||||
else:
|
else:
|
||||||
shutil.copy(zippath, fdir)
|
shutil.copy(zippath, fdir)
|
||||||
if args['--log']:
|
|
||||||
shutil.copy(zippath, fdir)
|
|
||||||
print
|
print
|
||||||
elif args['--format'] == 'xlsx':
|
elif args['--format'] == 'xlsx':
|
||||||
from pyexcel_xlsx import save_data
|
from pyexcel_xlsx import save_data
|
||||||
|
|
@ -241,12 +243,8 @@ if __name__ == '__main__':
|
||||||
save_data(xlsxpath, data)
|
save_data(xlsxpath, data)
|
||||||
if args['--output']:
|
if args['--output']:
|
||||||
shutil.copy(xlsxpath, args['--output'])
|
shutil.copy(xlsxpath, args['--output'])
|
||||||
if args['--log']:
|
|
||||||
shutil.copy(logfname, args['--output'])
|
|
||||||
else:
|
else:
|
||||||
shutil.copy(xlsxpath, fdir)
|
shutil.copy(xlsxpath, fdir)
|
||||||
if args['--log']:
|
|
||||||
shutil.copy(zippath, fdir)
|
|
||||||
print
|
print
|
||||||
print "saved as", xlsxname
|
print "saved as", xlsxname
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue