diff options
Diffstat (limited to 'update_sharing.py')
-rwxr-xr-x | update_sharing.py | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/update_sharing.py b/update_sharing.py index d2b357b..55e8096 100755 --- a/update_sharing.py +++ b/update_sharing.py @@ -5,27 +5,27 @@ import sqlite3 from dedup.utils import fetchiter def add_values(cursor, insert_key, files, size): - cursor.execute("UPDATE sharing SET files = files + ?, size = size + ? WHERE package1 = ? AND package2 = ? AND func1 = ? AND func2 = ?;", + cursor.execute("UPDATE sharing SET files = files + ?, size = size + ? WHERE pid1 = ? AND pid2 = ? AND func1 = ? AND func2 = ?;", (files, size) + insert_key) if cursor.rowcount > 0: return - cursor.execute("INSERT INTO sharing (package1, package2, func1, func2, files, size) VALUES (?, ?, ?, ?, ?, ?);", + cursor.execute("INSERT INTO sharing (pid1, pid2, func1, func2, files, size) VALUES (?, ?, ?, ?, ?, ?);", insert_key + (files, size)) def compute_pkgdict(rows): pkgdict = dict() - for package, _, filename, size, function in rows: - funcdict = pkgdict.setdefault(package, {}) + for pid, _, filename, size, function in rows: + funcdict = pkgdict.setdefault(pid, {}) funcdict.setdefault(function, []).append((size, filename)) return pkgdict def process_pkgdict(cursor, pkgdict): - for package1, funcdict1 in pkgdict.items(): + for pid1, funcdict1 in pkgdict.items(): for function1, files in funcdict1.items(): numfiles = len(files) size = sum(entry[0] for entry in files) - for package2, funcdict2 in pkgdict.items(): - if package1 == package2: + for pid2, funcdict2 in pkgdict.items(): + if pid1 == pid2: pkgnumfiles = numfiles - 1 pkgsize = size - min(entry[0] for entry in files) if pkgnumfiles == 0: @@ -34,7 +34,7 @@ def process_pkgdict(cursor, pkgdict): pkgnumfiles = numfiles pkgsize = size for function2 in funcdict2.keys(): - insert_key = (package1, package2, function1, function2) + insert_key = (pid1, pid2, function1, function2) add_values(cursor, insert_key, pkgnumfiles, pkgsize) def main(): @@ -46,7 +46,7 @@ def main(): readcur = db.cursor() readcur.execute("SELECT hash FROM hash GROUP BY hash HAVING count(*) > 1;") for hashvalue, in fetchiter(readcur): - cur.execute("SELECT content.package, content.id, content.filename, content.size, hash.function FROM hash JOIN content ON hash.cid = content.id WHERE hash = ?;", + cur.execute("SELECT content.pid, content.id, content.filename, content.size, hash.function FROM hash JOIN content ON hash.cid = content.id WHERE hash = ?;", (hashvalue,)) rows = cur.fetchall() print("processing hash %s with %d entries" % (hashvalue, len(rows))) |