# HG changeset patch # User jjohnson # Date 1500319324 14400 # Node ID bed5018e7ae3564a373439bf32b73eca198a8706 # Parent 357fe86f245d6bd7f7c7edd471c3cb84edaa0a77 Uploaded diff -r 357fe86f245d -r bed5018e7ae3 ._filters.py Binary file ._filters.py has changed diff -r 357fe86f245d -r bed5018e7ae3 filter_tabular.py --- a/filter_tabular.py Fri Jul 14 17:34:22 2017 -0400 +++ b/filter_tabular.py Mon Jul 17 15:22:04 2017 -0400 @@ -29,8 +29,7 @@ inputPath = os.path.abspath(options.input) inputFile = open(inputPath, 'r') except Exception as e: - print("failed: %s" % e, file=sys.stderr) - exit(3) + exit('Error: %s' % (e)) else: inputFile = sys.stdin @@ -39,8 +38,7 @@ outputPath = os.path.abspath(options.output) outputFile = open(outputPath, 'w') except Exception as e: - print("failed: %s" % e, file=sys.stderr) - exit(3) + exit('Error: %s' % (e)) else: outputFile = sys.stdout @@ -49,8 +47,8 @@ try: fh = open(options.jsonfile) filters = json.load(fh) - except Exception as exc: - print("Error: %s" % exc, file=sys.stderr) + except Exception as e: + exit('Error: %s' % (e)) if options.verbose and filters: for f in filters: @@ -62,9 +60,8 @@ try: filter_file(inputFile, outputFile, filters=filters) - except Exception as exc: - print("Error: %s" % exc, file=sys.stderr) - exit(1) + except Exception as e: + exit('Error: %s' % (e)) if __name__ == "__main__": diff -r 357fe86f245d -r bed5018e7ae3 filter_tabular.xml --- a/filter_tabular.xml Fri Jul 14 17:34:22 2017 -0400 +++ b/filter_tabular.xml Mon Jul 17 15:22:04 2017 -0400 @@ -1,4 +1,4 @@ - + diff -r 357fe86f245d -r bed5018e7ae3 filters.py --- a/filters.py Fri Jul 14 17:34:22 2017 -0400 +++ b/filters.py Mon Jul 17 15:22:04 2017 -0400 @@ -56,15 +56,14 @@ return self def __next__(self): - return next(self) - - def next(self): if not self.src_lines: self.get_lines() if self.src_lines: return self.src_lines.pop(0) raise StopIteration + next = __next__ + def select_columns(self, line, cols): fields = line.split('\t') return '\t'.join([fields[x] for x in cols]) @@ -111,7 +110,7 @@ self.col_idx = col_idx self.filters = filters self.tsv_file = \ - input_file if isinstance(input_file, file) else open(input_file) + input_file if hasattr(input_file, 'readline') else open(input_file) if skip and skip > 0: for i in range(skip): if not self.tsv_file.readline(): @@ -130,9 +129,6 @@ return self def __next__(self): - return next(self) - - def next(self): ''' Iteration ''' for i, line in enumerate(self.source): fields = line.rstrip('\r\n').split('\t') @@ -141,6 +137,8 @@ return fields raise StopIteration + next = __next__ + def filter_file(input_file, output, skip=0, comment_char='#', filters=None): data_lines = 0 @@ -155,5 +153,4 @@ print('Failed at line: %d err: %s' % (linenum, e), file=sys.stderr) except Exception as e: - print('Failed: %s' % (e), file=sys.stderr) - exit(1) + exit('Error: %s' % (e)) diff -r 357fe86f245d -r bed5018e7ae3 load_db.py --- a/load_db.py Fri Jul 14 17:34:22 2017 -0400 +++ b/load_db.py Mon Jul 17 15:22:04 2017 -0400 @@ -122,8 +122,7 @@ conn.commit() c.close() except Exception as e: - print('Failed: %s' % (e), file=sys.stderr) - exit(1) + exit('Error: %s' % (e)) def create_index(conn, table_name, index_name, index_columns, unique=False): diff -r 357fe86f245d -r bed5018e7ae3 query_db.py --- a/query_db.py Fri Jul 14 17:34:22 2017 -0400 +++ b/query_db.py Mon Jul 17 15:22:04 2017 -0400 @@ -43,16 +43,16 @@ tables_query = TABLE_QUERY rslt = c.execute(tables_query).fetchall() for table, sql in rslt: - print("Table %s:" % table, file=sys.stderr) + print("Table %s:" % table, file=outputFile) try: col_query = 'SELECT * FROM %s LIMIT 0' % table cur = conn.cursor().execute(col_query) cols = [col[0] for col in cur.description] - print(" Columns: %s" % cols, file=sys.stderr) + print(" Columns: %s" % cols, file=outputFile) except Exception as exc: - print("Error: %s" % exc, file=sys.stderr) - except Exception as exc: - print("Error: %s" % exc, file=sys.stderr) + print("Warning: %s" % exc, file=sys.stderr) + except Exception as e: + exit('Error: %s' % (e)) exit(0) diff -r 357fe86f245d -r bed5018e7ae3 query_tabular.py --- a/query_tabular.py Fri Jul 14 17:34:22 2017 -0400 +++ b/query_tabular.py Mon Jul 17 15:22:04 2017 -0400 @@ -66,8 +66,7 @@ outputPath = os.path.abspath(options.output) outputFile = open(outputPath, 'w') except Exception as e: - print("failed: %s" % e, file=sys.stderr) - exit(3) + exit('Error: %s' % (e)) else: outputFile = sys.stdout @@ -109,8 +108,8 @@ if 'tables' in tdef: for ti, table in enumerate(tdef['tables']): _create_table(ti, table) - except Exception as exc: - print("Error: %s" % exc, file=sys.stderr) + except Exception as e: + exit('Error: %s' % (e)) query = None if (options.query_file is not None): @@ -124,15 +123,14 @@ if (query is None): try: describe_tables(get_connection(options.sqlitedb), outputFile) - except Exception as exc: - print("Error: %s" % exc, file=sys.stderr) + except Exception as e: + exit('Error: %s' % (e)) else: try: run_query(get_connection(options.sqlitedb), query, outputFile, no_header=options.no_header) - except Exception as exc: - print("Error: %s" % exc, file=sys.stderr) - exit(1) + except Exception as e: + exit('Error: %s' % (e)) if __name__ == "__main__": diff -r 357fe86f245d -r bed5018e7ae3 query_tabular.xml --- a/query_tabular.xml Fri Jul 14 17:34:22 2017 -0400 +++ b/query_tabular.xml Mon Jul 17 15:22:04 2017 -0400 @@ -1,4 +1,4 @@ - + using sqlite sql diff -r 357fe86f245d -r bed5018e7ae3 sqlite_to_tabular.py --- a/sqlite_to_tabular.py Fri Jul 14 17:34:22 2017 -0400 +++ b/sqlite_to_tabular.py Mon Jul 17 15:22:04 2017 -0400 @@ -31,8 +31,7 @@ outputPath = os.path.abspath(options.output) outputFile = open(outputPath, 'w') except Exception as e: - print("failed: %s" % e, file=sys.stderr) - exit(3) + exit('Error: %s' % (e)) else: outputFile = sys.stdout @@ -48,16 +47,15 @@ if (query is None): try: describe_tables(get_connection(options.sqlitedb), outputFile) - except Exception as exc: - print("Error: %s" % exc, file=sys.stderr) + except Exception as e: + exit('Error: %s' % (e)) exit(0) else: try: run_query(get_connection(options.sqlitedb), query, outputFile, no_header=options.no_header) - except Exception as exc: - print("Error: %s" % exc, file=sys.stderr) - exit(1) + except Exception as e: + exit('Error: %s' % (e)) if __name__ == "__main__": diff -r 357fe86f245d -r bed5018e7ae3 sqlite_to_tabular.xml --- a/sqlite_to_tabular.xml Fri Jul 14 17:34:22 2017 -0400 +++ b/sqlite_to_tabular.xml Mon Jul 17 15:22:04 2017 -0400 @@ -1,5 +1,5 @@ - + for SQL query