-
Notifications
You must be signed in to change notification settings - Fork 8
/
mkdeb.py
executable file
·105 lines (83 loc) · 2.68 KB
/
mkdeb.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/python3
import os
import stat
import shutil
class FileMap:
def __init__(self, s, d, mode='r', f=""):
self.src = s
self.dst = d
self.mode = mode
if f == "":
self.filename = os.path.basename(s)
else:
self.filename = f
fix_dri = 'tmp'
deb_dir = fix_dri + "/DEBIAN"
def create_script(path):
with open(path, mode='x') as f:
f.writelines("#!/usr/bin/env bash")
f.close()
os.chmod(path, stat.S_IXUSR | stat.S_IWUSR | stat.S_IRUSR |
stat.S_IROTH | stat.S_IXOTH | stat.S_IRGRP | stat.S_IXGRP)
return path
def create_template():
os.mkdir(fix_dri)
os.mkdir(deb_dir)
script = ["preinst", "postinst", "prerm", "postrm"]
path = map(lambda x: deb_dir + "/" + x, script)
for p in path:
print(create_script(p))
def create_control(package, version, arch, description, depends):
with open(deb_dir + "/" + "control", mode='x') as f:
f.writelines("Package: " + package)
f.write("\n")
f.writelines("Version: " + version)
f.write("\n")
f.writelines("Priority: extra")
f.write("\n")
f.writelines("Architecture: " + arch)
f.write("\n")
f.writelines("Maintainer: EMQX")
f.write("\n")
f.writelines("Section: EMQX")
f.write("\n")
f.writelines("Provides: EMQX")
f.write("\n")
f.writelines("Description: " + description)
f.write("\n")
if len(depends) != 0:
f.writelines("Depends: " + depends)
f.write("\n")
f.writelines("Installed-Size: " + str(cal_size(fix_dri)))
f.write("\n")
f.close()
def cal_size(path):
size = 0
for root, dirs, files in os.walk(path):
size += sum([os.path.getsize(os.path.join(root, name))
for name in files])
return size
def copy_dir(src, dst):
dstpath = fix_dri + dst
if not os.path.exists(dstpath):
os.makedirs(dstpath)
os.system('cp -r' + ' ' + src + ' ' + dstpath)
def create_deb_file(rules):
for r in rules:
src = r.src
dstpath = fix_dri + r.dst
dst = dstpath + r.filename
if not os.path.isfile(src):
print("%s not exist!" % src)
continue
if not os.path.exists(dstpath):
os.makedirs(dstpath)
shutil.copyfile(src, dst)
if r.mode == "x":
os.chmod(dst,
stat.S_IXUSR | stat.S_IRUSR | stat.S_IWUSR | stat.S_IXGRP | stat.S_IWGRP | stat.S_IRGRP)
print("copy: %s => %s" % (src, dst))
if __name__ == "mkdeb":
if os.path.exists(fix_dri):
shutil.rmtree(fix_dri)
create_template()