add option -d --database for db path to all scripts
authorHelmut Grohne <helmut@subdivi.de>
Mon, 2 Sep 2013 16:51:20 +0000 (18:51 +0200)
committerHelmut Grohne <helmut@subdivi.de>
Mon, 2 Sep 2013 16:51:20 +0000 (18:51 +0200)
autoimport.py
readyaml.py
update_sharing.py
webapp.py

index a0681b3..d44c012 100755 (executable)
@@ -83,9 +83,12 @@ def main():
                       help="avoid reimporting same versions")
     parser.add_option("-p", "--prune", action="store_true",
                       help="prune packages old packages")
+    parser.add_option("-d", "--database", action="store",
+                      default="test.sqlite3",
+                      help="path to the sqlite3 database file")
     options, args = parser.parse_args()
     tmpdir = tempfile.mkdtemp(prefix=b"debian-dedup")
-    db = sqlite3.connect("test.sqlite3")
+    db = sqlite3.connect(options.database)
     cur = db.cursor()
     cur.execute("PRAGMA foreign_keys = ON;")
     e = concurrent.futures.ThreadPoolExecutor(multiprocessing.cpu_count())
index 21b1ca1..2ef9a3b 100755 (executable)
@@ -2,6 +2,7 @@
 """This tool reads a yaml file as generated by importpkg.py on stdin and
 updates the database with the contents."""
 
+import optparse
 import sqlite3
 import sys
 
@@ -53,7 +54,12 @@ def readyaml(db, stream):
     raise ValueError("missing commit block")
 
 def main():
-    db = sqlite3.connect("test.sqlite3")
+    parser = optparse.OptionParser()
+    parser.add_option("-d", "--database", action="store",
+                      default="test.sqlite3",
+                      help="path to the sqlite3 database file")
+    options, args = parser.parse_args()
+    db = sqlite3.connect(options.database)
     readyaml(db, sys.stdin)
 
 if __name__ == "__main__":
index 5ec6c7b..1ff0fd8 100755 (executable)
@@ -1,5 +1,6 @@
 #!/usr/bin/python
 
+import optparse
 import sqlite3
 
 from dedup.utils import fetchiter
@@ -37,8 +38,7 @@ def process_pkgdict(cursor, pkgdict):
                     insert_key = (pid1, pid2, fid1, fid2)
                     add_values(cursor, insert_key, pkgnumfiles, pkgsize)
 
-def main():
-    db = sqlite3.connect("test.sqlite3")
+def main(db):
     cur = db.cursor()
     cur.execute("PRAGMA foreign_keys = ON;")
     cur.execute("DELETE FROM sharing;")
@@ -61,4 +61,9 @@ def main():
     db.commit()
 
 if __name__ == "__main__":
-    main()
+    parser = optparse.OptionParser()
+    parser.add_option("-d", "--database", action="store",
+                      default="test.sqlite3",
+                      help="path to the sqlite3 database file")
+    options, args = parser.parse_args()
+    main(sqlite3.connect(options.database))
index f202c2e..632b485 100755 (executable)
--- a/webapp.py
+++ b/webapp.py
@@ -1,6 +1,7 @@
 #!/usr/bin/python
 
 import datetime
+import optparse
 import sqlite3
 from wsgiref.simple_server import make_server
 
@@ -237,7 +238,12 @@ class Application(object):
         return html_response(source_template.render(params))
 
 def main():
-    app = Application(sqlite3.connect("test.sqlite3"))
+    parser = optparse.OptionParser()
+    parser.add_option("-d", "--database", action="store",
+                      default="test.sqlite3",
+                      help="path to the sqlite3 database file")
+    options, args = parser.parse_args()
+    app = Application(sqlite3.connect(options.database))
     app = SharedDataMiddleware(app, {"/": ("dedup", "static")})
     make_server("0.0.0.0", 8800, app).serve_forever()