Mercurial > repos > jjohnson > query_tabular
comparison filter_tabular.py @ 22:bed5018e7ae3 draft
Uploaded
author | jjohnson |
---|---|
date | Mon, 17 Jul 2017 15:22:04 -0400 |
parents | ab27c4bd14b9 |
children |
comparison
equal
deleted
inserted
replaced
21:357fe86f245d | 22:bed5018e7ae3 |
---|---|
27 if options.input is not None: | 27 if options.input is not None: |
28 try: | 28 try: |
29 inputPath = os.path.abspath(options.input) | 29 inputPath = os.path.abspath(options.input) |
30 inputFile = open(inputPath, 'r') | 30 inputFile = open(inputPath, 'r') |
31 except Exception as e: | 31 except Exception as e: |
32 print("failed: %s" % e, file=sys.stderr) | 32 exit('Error: %s' % (e)) |
33 exit(3) | |
34 else: | 33 else: |
35 inputFile = sys.stdin | 34 inputFile = sys.stdin |
36 | 35 |
37 if options.output is not None: | 36 if options.output is not None: |
38 try: | 37 try: |
39 outputPath = os.path.abspath(options.output) | 38 outputPath = os.path.abspath(options.output) |
40 outputFile = open(outputPath, 'w') | 39 outputFile = open(outputPath, 'w') |
41 except Exception as e: | 40 except Exception as e: |
42 print("failed: %s" % e, file=sys.stderr) | 41 exit('Error: %s' % (e)) |
43 exit(3) | |
44 else: | 42 else: |
45 outputFile = sys.stdout | 43 outputFile = sys.stdout |
46 | 44 |
47 filters = None | 45 filters = None |
48 if options.jsonfile: | 46 if options.jsonfile: |
49 try: | 47 try: |
50 fh = open(options.jsonfile) | 48 fh = open(options.jsonfile) |
51 filters = json.load(fh) | 49 filters = json.load(fh) |
52 except Exception as exc: | 50 except Exception as e: |
53 print("Error: %s" % exc, file=sys.stderr) | 51 exit('Error: %s' % (e)) |
54 | 52 |
55 if options.verbose and filters: | 53 if options.verbose and filters: |
56 for f in filters: | 54 for f in filters: |
57 print('%s %s' % (f['filter'], | 55 print('%s %s' % (f['filter'], |
58 ', '.join( | 56 ', '.join( |
60 for k in set(f.keys()) - set(['filter'])])), | 58 for k in set(f.keys()) - set(['filter'])])), |
61 file=sys.stdout) | 59 file=sys.stdout) |
62 | 60 |
63 try: | 61 try: |
64 filter_file(inputFile, outputFile, filters=filters) | 62 filter_file(inputFile, outputFile, filters=filters) |
65 except Exception as exc: | 63 except Exception as e: |
66 print("Error: %s" % exc, file=sys.stderr) | 64 exit('Error: %s' % (e)) |
67 exit(1) | |
68 | 65 |
69 | 66 |
70 if __name__ == "__main__": | 67 if __name__ == "__main__": |
71 __main__() | 68 __main__() |