Add generation of digsigsums for control.tar.gz to buildcommand
authorChristian Ratzenhofer <christian_ratzenhofer@yahoo.de>
Thu, 12 Jan 2012 20:50:54 +0000 (21:50 +0100)
committerChristian Ratzenhofer <christian_ratzenhofer@yahoo.de>
Thu, 12 Jan 2012 20:51:42 +0000 (21:51 +0100)
bdist_hdeb.py
digsigsums.py [new file with mode: 0644]

index 40bf133..5a4184d 100644 (file)
@@ -38,14 +38,21 @@ class bdist_hdeb(Command):
         if target_dir is None:
             raise ValueError('could not find debian source directory')        
         
-        # inject aegis manifest into .deb
+        # inject custom logic to dh_builddeb (build digsigsums before and add aegis manifest after)
+        DEBNAME = self.distribution.get_name()+'_'+self.distribution.get_version()+'*_all.deb'
+        rules = open(target_dir+'/debian/rules', 'a')
+        rules.write('override_dh_builddeb:\n\tpython ../../digsigsums.py '+self.distribution.get_name()+\
+        '\n\tdh_builddeb')
         if self.aegis_manifest is not None:
-            DEBNAME = self.distribution.get_name()+'_'+self.distribution.get_version()+'*_all.deb'
-            copy(self.aegis_manifest, target_dir+'/_aegis')
-            rules = open(target_dir+'/debian/rules', 'a')
-            rules.write('override_dh_builddeb:\n\tdh_builddeb\n\tar q ../'+DEBNAME+' _aegis\n\n')
-            rules.close()
+            rules.write('\n\tar q ../'+DEBNAME+' _aegis')
+        
+        rules.write('\n\n')
+        rules.close()
 
+        # make aegies manifest avaiable to debian/rules
+        if self.aegis_manifest is not None:
+            copy(self.aegis_manifest, target_dir+'/_aegis')
+        
         # define system command to execute (gen .deb binary pkg)
         syscmd = ['dpkg-buildpackage','-rfakeroot','-uc','-b']
 
diff --git a/digsigsums.py b/digsigsums.py
new file mode 100644 (file)
index 0000000..79485ca
--- /dev/null
@@ -0,0 +1,41 @@
+import sys
+import os
+import hashlib
+from os.path import join
+
+# digsigsums.py generate DEBIAN/digsigsums for aegis on meego 1.2 harmattan
+# it is meant to be run just before dh_builddeb from the builddirectory with the package name as parameter
+# builds the digsigsums file in ./debian/$packagename/DEBIAN/
+
+def check_file(filePath):
+    fh = open(filePath, 'r')
+    if fh.read(2) == '#!':
+        fh.close()
+        return True
+    fh.close()
+    return False
+        
+def hash_file(filePath, packageName):        
+    # digsigsums format:
+    # S 15 com.nokia.maemo H 40 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx R 5 abcde
+    # Source (might change) hash (sha1)                                 relative path
+    relativepath = filePath[8+len(packageName):]
+    fileToHash = open (filePath, 'rb')
+    sha1 = hashlib.sha1()
+    sha1.update(fileToHash.read())
+    hashString = sha1.hexdigest()
+    fileToHash.close()
+    return 'S 15 com.nokia.maemo H 40 {0} R {1} {2}\n'.format(hashString, len(relativepath), relativepath)
+
+
+if(len(sys.argv) > 1):
+    packageName = sys.argv[1]
+    
+    # generate DEBIAN/digsigsums for control.tar.gz
+    digsigsums = open('debian/'+packageName+'/DEBIAN/digsigsums', 'w')
+    for path, dirs, files in os.walk('debian/'+packageName):
+        for filename in files:
+            if check_file(join(path,filename)):
+                digsigsums.write(hash_file(join(path,filename), packageName))
+                    
+    digsigsums.close()
\ No newline at end of file