Make it work with cdebootstrap
authorJoachim Breitner <mail@joachim-breitner.de>
Sun, 10 Aug 2008 19:41:36 +0000 (19:41 +0000)
committerJoachim Breitner <mail@joachim-breitner.de>
Sun, 10 Aug 2008 19:41:36 +0000 (19:41 +0000)
apt-repository-merge
test.conf

index df258a7..295d21a 100644 (file)
@@ -3,10 +3,11 @@
 from optparse import OptionParser
 
 import gzip
-from debian_bundle import deb822
+import deb822
 import urllib2
 import os
 import os.path
+import hashlib
 
 class Config(deb822._multivalued):
     _multivalued_fields = {
@@ -28,6 +29,8 @@ def add_rewrite(path, base):
     rewrite_rules_by_dir.setdefault(dir,[])
     rewrite_rules_by_dir[dir].append(( file, base ))
 
+release_files = []
+
 for arch in config["arches"].split():
     print "Merging architecture %s" % arch
 
@@ -55,9 +58,9 @@ for arch in config["arches"].split():
                output_packages[package_name] = ( repo, package,)
 
 
-    package_out_file = "%s/dists/%s/%s/binary-%s/Packages" % (
-       config["Output"], config["Dist"], config["Section"], arch
-       )
+    package_file = "dists/%s/%s/binary-%s/Packages" % (
+           config["Dist"], config["Section"], arch)
+    package_out_file = "%s/%s" % ( config["Output"], package_file)
     if not os.path.isdir(os.path.dirname(package_out_file)):
        os.makedirs(os.path.dirname(package_out_file))
     package_out = file(package_out_file,'w')
@@ -65,6 +68,12 @@ for arch in config["arches"].split():
        package_out.write(str(package))
        package_out.write("\n")
        add_rewrite(package["Filename"], repo["Base"])
+    package_out.close()            
+    gzip.GzipFile(package_out_file + ".gz", 'w').write(
+           file(package_out_file,'r').read()
+       )
+    release_files.append(package_file)
+    release_files.append(package_file + ".gz")
 
 if True:    # to match indentation with above
     print "Merging sources"
@@ -94,9 +103,9 @@ if True:    # to match indentation with above
                output_packages[package_name] = ( repo, package,)
 
 
-    package_out_file = "%s/dists/%s/%s/sources/Sources" % (
-       config["Output"], config["Dist"], config["Section"]
-       )
+    package_file = "dists/%s/%s/sources/Sources" % ( config["Dist"], config["Section"])
+    package_out_file = "%s/%s" % ( config["Output"], package_file)
+
     if not os.path.isdir(os.path.dirname(package_out_file)):
        os.makedirs(os.path.dirname(package_out_file))
     package_out = file(package_out_file,'w')
@@ -112,6 +121,12 @@ if True:    # to match indentation with above
            pkgpath = "pool/%s/%s/%s/%s" % (
                repo["Section"], c, package_name, pkgfile["name"] )
            add_rewrite(pkgpath, repo["Base"])
+    package_out.close()            
+    gzip.GzipFile(package_out_file + ".gz", 'w').write(
+           file(package_out_file,'r').read()
+       )
+    release_files.append(package_file)
+    release_files.append(package_file + ".gz")
 
 print "Writing README.txt"
 readme = file("%s/README.txt" % config["Output"],'w')
@@ -141,3 +156,23 @@ for dir, rewrites in rewrite_rules_by_dir.items():
        readme.write("%s -> %s/%s/%s\n" %
                (filename, base, dir, filename) )
 
+print "Writing Release file"
+release_file = file("%s/dists/%s/Release" % (config["Output"], config["Dist"]),'w')
+release = deb822.Release()
+release["Origin"] = "Debian"
+release["Label"] = "Debian"
+release["Suite"] = config["Dist"]
+release["Codename"] = config["Dist"]
+release["Architectures"] = config["Arches"]
+release["Components"] = config["Section"]
+release["Description"] = "Merged apt repository"
+release["MD5Sum"] = []
+for file_name in release_files:
+    output_file_name = "%s/%s" % (config["Output"], file_name)
+    f = file(output_file_name, 'r')
+    release["MD5Sum"].append({
+           'name'  : file_name.split('/',2)[2],
+           'size'  : os.path.getsize(output_file_name),
+           'md5sum': hashlib.md5(f.read()).hexdigest()
+       })
+release_file.write(str(release))
index 42ad191..52dec71 100644 (file)
--- a/test.conf
+++ b/test.conf
@@ -3,6 +3,7 @@ Repos:
  http://mirror/debian experimental main
 # http://mirror/debian/ sid main
 Arches: armel i386
-Dist: unstable+experimental+pkg-fso
+#Dist: unstable+experimental+pkg-fso
+Dist: sid
 Section: main
 Output: output