fixing routing.py bug, if time is 24:00
[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     if '/DEBIAN/' in filePath:
23         relativepath = 'var/lib/dpkg/info/{0}.{1}'.format(packageName, filePath[15+len(packageName):])
24     else:
25         relativepath = filePath[8+len(packageName):]        
26         
27     fileToHash = open (filePath, 'rb')
28     sha1 = hashlib.sha1()
29     sha1.update(fileToHash.read())
30     hashString = sha1.hexdigest()
31     fileToHash.close()
32     return 'S 15 com.nokia.maemo H 40 {0} R {1} {2}\n'.format(hashString, len(relativepath), relativepath)
33
34
35 if(len(sys.argv) > 1):
36     packageName = sys.argv[1]
37     
38     # generate DEBIAN/digsigsums for control.tar.gz
39     digsigsums = open('debian/'+packageName+'/DEBIAN/digsigsums', 'w')
40     for path, dirs, files in os.walk('debian/'+packageName):
41         for filename in files:
42             if check_file(join(path,filename)):
43                 digsigsums.write(hash_file(join(path,filename), packageName))
44                     
45     digsigsums.close()