Add generation of digsigsums for control.tar.gz to buildcommand
[pywienerlinien] / digsigsums.py
1 import sys
2 import os
3 import hashlib
4 from os.path import join
5
6 # digsigsums.py generate DEBIAN/digsigsums for aegis on meego 1.2 harmattan
7 # it is meant to be run just before dh_builddeb from the builddirectory with the package name as parameter
8 # builds the digsigsums file in ./debian/$packagename/DEBIAN/
9
10 def check_file(filePath):
11     fh = open(filePath, 'r')
12     if fh.read(2) == '#!':
13         fh.close()
14         return True
15     fh.close()
16     return False
17         
18 def hash_file(filePath, packageName):        
19     # digsigsums format:
20     # S 15 com.nokia.maemo H 40 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx R 5 abcde
21     # Source (might change) hash (sha1)                                 relative path
22     relativepath = filePath[8+len(packageName):]
23     fileToHash = open (filePath, 'rb')
24     sha1 = hashlib.sha1()
25     sha1.update(fileToHash.read())
26     hashString = sha1.hexdigest()
27     fileToHash.close()
28     return 'S 15 com.nokia.maemo H 40 {0} R {1} {2}\n'.format(hashString, len(relativepath), relativepath)
29
30
31 if(len(sys.argv) > 1):
32     packageName = sys.argv[1]
33     
34     # generate DEBIAN/digsigsums for control.tar.gz
35     digsigsums = open('debian/'+packageName+'/DEBIAN/digsigsums', 'w')
36     for path, dirs, files in os.walk('debian/'+packageName):
37         for filename in files:
38             if check_file(join(path,filename)):
39                 digsigsums.write(hash_file(join(path,filename), packageName))
40                     
41     digsigsums.close()