autoimport: add option to skip hash checking
[~helmut/debian-dedup.git] / autoimport.py
index 94358b6..132e671 100755 (executable)
@@ -28,7 +28,7 @@ from dedup.compression import decompress
 
 from readyaml import readyaml
 
-def process_http(pkgs, url):
+def process_http(pkgs, url, addhash=True):
     pkglist = urlopen(url + "/dists/sid/main/binary-amd64/Packages.gz")
     pkglist = decompress(pkglist, ".gz")
     pkglist = deb822.Packages.iter_paragraphs(pkglist)
@@ -37,9 +37,11 @@ def process_http(pkgs, url):
         if name in pkgs and \
                 version_compare(pkgs[name]["version"], pkg["Version"]) > 0:
             continue
-        pkgs[name] = dict(version=pkg["Version"],
-                          filename="%s/%s" % (url, pkg["Filename"]),
-                          sha256hash=pkg["SHA256"])
+        inst = dict(version=pkg["Version"],
+                    filename="%s/%s" % (url, pkg["Filename"]))
+        if addhash:
+            inst["sharing"] = pkg["SHA256"]
+        pkgs[name] = inst
 
 def process_file(pkgs, filename):
     base = os.path.basename(filename)
@@ -93,6 +95,8 @@ def main():
     parser.add_argument("-d", "--database", action="store",
                         default="test.sqlite3",
                         help="path to the sqlite3 database file")
+    parser.add_argument("--noverify", action="store_true",
+                        help="do not verify binary package hashes")
     parser.add_argument("files", nargs='+',
                         help="files or directories or repository urls")
     args = parser.parse_args()
@@ -105,7 +109,7 @@ def main():
     for d in args.files:
         print("processing %s" % d)
         if d.startswith(("http://", "https://", "ftp://", "file://")):
-            process_http(pkgs, d)
+            process_http(pkgs, d, not args.noverify)
         elif os.path.isdir(d):
             process_dir(pkgs, d)
         else: