autoimport: don't fork for readyaml
authorHelmut Grohne <helmut@subdivi.de>
Tue, 11 Jun 2013 21:22:10 +0000 (23:22 +0200)
committerHelmut Grohne <helmut@subdivi.de>
Tue, 11 Jun 2013 21:22:10 +0000 (23:22 +0200)
This appears to be a huge performance boost.

autoimport.py
readyaml.py

index 48d3f8c..d326d61 100755 (executable)
@@ -16,6 +16,8 @@ import concurrent.futures
 from debian import deb822
 from debian.debian_support import version_compare
 
+from readyaml import readyaml
+
 def process_http(pkgs, url):
     pkglist = urllib.urlopen(url + "/dists/sid/main/binary-amd64/Packages.gz").read()
     pkglist = gzip.GzipFile(fileobj=io.BytesIO(pkglist)).read()
@@ -115,9 +117,9 @@ def main():
             print("sqlimporting %s" % name)
             with open(inf) as inp:
                 try:
-                    subprocess.check_call(["python", "readyaml.py"], stdin=inp)
-                except subprocess.CalledProcessError:
-                    print("%s failed sql" % name)
+                    readyaml(db, inp)
+                except Exception as exc:
+                    print("%s failed sql with exception %r" % (name, exc))
                 else:
                     os.unlink(inf)
 
index b66c7f3..e2f3bb3 100755 (executable)
@@ -8,11 +8,10 @@ import sys
 from debian.debian_support import version_compare
 import yaml
 
-def main():
-    db = sqlite3.connect("test.sqlite3")
+def readyaml(db, stream):
     cur = db.cursor()
     cur.execute("PRAGMA foreign_keys = ON;")
-    gen = yaml.safe_load_all(sys.stdin)
+    gen = yaml.safe_load_all(stream)
     metadata = next(gen)
     package = metadata["package"]
     cur.execute("SELECT version FROM package WHERE package = ?;",
@@ -44,5 +43,9 @@ def main():
                          for func, hexhash in entry["hashes"].items()))
     raise ValueError("missing commit block")
 
+def main():
+    db = sqlite3.connect("test.sqlite3")
+    readyaml(db, sys.stdin)
+
 if __name__ == "__main__":
     main()