summaryrefslogtreecommitdiff
path: root/readyaml.py
diff options
context:
space:
mode:
Diffstat (limited to 'readyaml.py')
-rwxr-xr-xreadyaml.py27
1 files changed, 12 insertions, 15 deletions
diff --git a/readyaml.py b/readyaml.py
index 2ef9a3b..7b75f2c 100755
--- a/readyaml.py
+++ b/readyaml.py
@@ -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 binascii
import optparse
import sqlite3
import sys
@@ -26,13 +27,11 @@ def readyaml(db, stream):
pid = None
cur.execute("BEGIN;")
- cur.execute("SELECT name, id FROM function;")
- funcmapping = dict(cur.fetchall())
if pid is not None:
- cur.execute("DELETE FROM content WHERE pid = ?;", (pid,))
cur.execute("DELETE FROM dependency WHERE pid = ?;", (pid,))
cur.execute("UPDATE package SET version = ?, architecture = ?, source = ? WHERE id = ?;",
(metadata["version"], metadata["architecture"], metadata["source"], pid))
+ cur.execute("DELETE FROM control WHERE pid = ?;", (pid,))
else:
cur.execute("INSERT INTO package (name, version, architecture, source) VALUES (?, ?, ?, ?);",
(package, metadata["version"], metadata["architecture"],
@@ -40,18 +39,16 @@ def readyaml(db, stream):
pid = cur.lastrowid
cur.executemany("INSERT INTO dependency (pid, required) VALUES (?, ?);",
((pid, dep) for dep in metadata["depends"]))
- for entry in gen:
- if entry == "commit":
- db.commit()
- return
-
- cur.execute("INSERT INTO content (pid, filename, size) VALUES (?, ?, ?);",
- (pid, entry["name"], entry["size"]))
- cid = cur.lastrowid
- cur.executemany("INSERT INTO hash (cid, fid, hash) VALUES (?, ?, ?);",
- ((cid, funcmapping[func], hexhash)
- for func, hexhash in entry["hashes"].items()))
- raise ValueError("missing commit block")
+ for name, content in metadata["data"].items():
+ content = sqlite3.Binary(binascii.a2b_base64(content))
+ cur.execute("INSERT INTO controlcontent (content) VALUES (?);",
+ (content,))
+ docid = cur.lastrowid
+ cur.execute("INSERT INTO control (pid, name, cid) VALUES (?, ?, ?);",
+ (pid, name, docid))
+ commit = next(gen)
+ if commit != "commit":
+ raise ValueError("missing commit block")
def main():
parser = optparse.OptionParser()