[go: up one dir, main page]

Menu

[b34c80]: / db_md5.py  Maximize  Restore  History

Download this file

47 lines (40 with data), 1.9 kB

 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
46
47
# Writing the md5sums file
# -*- coding: utf-8 -*-
import os, stat, commands
class MD5():
def __init__(self):
#self.rootdir = rootdir # Set the working folder, same folder where deb is built
pass
def IsExecutable(self, file):
# Find out if the file is an executable
# executable = commands.getoutput("if [ -x %s ]\nthen echo true\nfi" % file) #bash version
# if executable == "true":
# executable = stat.S_IXUSR & os.stat(file)[stat.ST_MODE] #python version
executable = os.access(file, os.X_OK) #another python version
if executable:
return True
else:
return False
def WriteMd5(self, builddir, tempdir):
tempdir = tempdir.encode('utf-8')
os.chdir(builddir)
temp_list = []
md5_list = [] # Final list used to write the md5sum file
for root, dirs, files in os.walk(tempdir):
for file in files:
file = "%s/%s" % (root, file)
# if self.IsExecutable(file):
# md5 = commands.getoutput("md5sum -b \"%s\"" % file)
# elif not self.IsExecutable(file):
md5 = commands.getoutput(("md5sum -t \"%s\"" % file))
temp_list.append(md5)
for item in temp_list:
# Remove [tempdir] from the path name in the md5sum so that it has a
# true unix path
# e.g., instead of "/myfolder_temp/usr/local/bin", "/usr/local/bin"
sum_split = item.split("%s/" % tempdir)
sum_join = "".join(sum_split)
md5_list.append(sum_join)
file = open("%s/DEBIAN/md5sums" % tempdir, "w") # Create the md5sums file in the "DEBIAN" directory
file.write("%s\n" % "\n".join(md5_list)) # Write the final list to the file
file.close() # Save the file