-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.py
executable file
·93 lines (77 loc) · 3.38 KB
/
build.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
#!/usr/bin/env python
import codecs
import datetime
import optparse
import os
import subprocess
import sys
parser = optparse.OptionParser()
parser.add_option("-s", "--source", dest="source", action="store_true", help="Build source package")
parser.add_option("-i", "--i386", dest="i386", action="store_true", help="Build i386 binary package")
(options, args) = parser.parse_args()
if len(args) == 0:
print "E: No package given!"
sys.exit(1)
for i in range(0, len(args)):
package = args[i]
if package == "":
sys.exit(1)
if package[-1] == "/":
package = package[:-1]
if not os.path.exists(package):
print "E: package '%s' not found" % package
sys.exit(1)
start_time = datetime.datetime.now()
# create build script needed folders
os.system ("mkdir -p ~/mate/deb")
os.system ("mkdir -p ~/mate/logs")
os.system("rm -rf /tmp/%s/ " % package)
os.system("cp " + package + " /tmp/" + package + "/ -R")
os.chdir("/tmp/%s" % package)
os.system("rm -rf debian/")
os.system("cp -R ~/mate/debian-packages/%s/debian/ ." % package)
os.system("echo '3.0 (native)' > debian/source/format")
# debian/changelog
date = datetime.date.today().strftime("%Y%m%d")
head = subprocess.check_output(["git", "rev-parse", "HEAD"])[:7]
suffix = "+git." + date + "." + head
orig_changelog_file = codecs.open("debian/changelog", encoding="utf-8", mode="r")
orig_changelog = orig_changelog_file.read().splitlines()
orig_changelog_file.close()
new_changelog = orig_changelog
new_changelog[0] = new_changelog[0].replace(")", suffix + ")")
for i in range(10):
new_changelog[0] = new_changelog[0].replace("-" + str(i), "")
new_changelog_file = codecs.open("debian/changelog", encoding="utf-8", mode="w")
new_changelog_file.write("\n".join(new_changelog))
new_changelog_file.close()
# debian/rules
orig_rules_file = codecs.open("debian/rules", encoding="utf-8", mode="r")
orig_rules = orig_rules_file.read()
orig_rules_file.close()
new_rules = orig_rules
new_rules = new_rules.replace("dh_auto_configure --", "NOCONFIGURE=1 ./autogen.sh\n\tdh_auto_configure --")
new_rules = new_rules.replace("#DEB_CONFIGURE_SCRIPT := ./autogen.sh", "DEB_CONFIGURE_SCRIPT := ./autogen.sh")
new_rules_file = codecs.open("debian/rules", encoding="utf-8", mode="w")
new_rules_file.write(new_rules)
new_rules_file.close()
if options.source:
os.system("dpkg-buildpackage -S -Zxz -uc -us")
os.system("mv -v ../*.dsc ~/mate/deb/")
os.system("mv -v ../*.xz ~/mate/deb/")
os.system("mv -v ../*.changes ~/mate/deb/")
else:
if options.i386:
os.system("dpkg-buildpackage -B -ai386 -Zxz -uc -tc 2>&1 | tee build.log")
else:
os.system("dpkg-buildpackage -b -Zxz -uc -tc 2>&1 | tee build.log")
os.system("mv -v build.log ~/mate/logs/%s.log" % package)
os.system("rm -v ../*.changes")
os.system("mv -v ../*.deb ~/mate/deb/")
os.chdir(os.path.join(os.path.expanduser("~"), "mate"))
os.system("rm -rf /tmp/%s/ " % package)
print "---------------------------------------------------------------"
os.system("ls -1 deb/")
print "---------------------------------------------------------------"
print (datetime.datetime.now() - start_time)
print "---------------------------------------------------------------"