-
Notifications
You must be signed in to change notification settings - Fork 0
/
digsigsums.py
45 lines (37 loc) · 1.59 KB
/
digsigsums.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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
if '/DEBIAN/' in filePath:
relativepath = 'var/lib/dpkg/info/{0}.{1}'.format(packageName, filePath[15+len(packageName):])
else:
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()