changeset 22:bed5018e7ae3 draft

Uploaded
author jjohnson
date Mon, 17 Jul 2017 15:22:04 -0400
parents 357fe86f245d
children 5bb148ee644a
files ._filters.py filter_tabular.py filter_tabular.xml filters.py load_db.py query_db.py query_tabular.py query_tabular.xml sqlite_to_tabular.py sqlite_to_tabular.xml
diffstat 10 files changed, 33 insertions(+), 44 deletions(-) [+]
line wrap: on
line diff
Binary file ._filters.py has changed
--- 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__":
--- 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 @@
-<tool id="filter_tabular" name="Filter Tabular" version="1.0.0">
+<tool id="filter_tabular" name="Filter Tabular" version="5.0.0">
     <description></description>
 
     <macros>
--- 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))
--- 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):
--- 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)
 
 
--- 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__":
--- 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 @@
-<tool id="query_tabular" name="Query Tabular" version="1.0.0">
+<tool id="query_tabular" name="Query Tabular" version="5.0.0">
     <description>using sqlite sql</description>
 
     <macros>
--- 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__":
--- 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 @@
 <?xml version="1.0"?>
-<tool id="sqlite_to_tabular" name="SQLite to tabular" version="1.0.0">
+<tool id="sqlite_to_tabular" name="SQLite to tabular" version="5.0.0">
     <description>for SQL query</description>
 
     <macros>