FS#8961 - Anti-Aliased Fonts.
[kugel-rb.git] / rbutil / rbutilqt / deploy-release.py
bloba4b9dcea973cba8cd1831739df0981b248a64415
1 #!/usr/bin/python
2 # __________ __ ___.
3 # Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 # \/ \/ \/ \/ \/
8 # $Id$
10 # Copyright (c) 2009 Dominik Riebeling
12 # All files in this archive are subject to the GNU General Public License.
13 # See the file COPYING in the source tree root for full license agreement.
15 # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 # KIND, either express or implied.
19 # Automate building releases for deployment.
20 # Run from source folder. Error checking / handling rather is limited.
21 # If the required Qt installation isn't in PATH use --qmake option.
22 # Tested on Linux and MinGW / W32
24 # requires python which package (http://code.google.com/p/which/)
25 # requires upx.exe in PATH on Windows.
28 import re
29 import os
30 import sys
31 import tarfile
32 import zipfile
33 import shutil
34 import subprocess
35 import getopt
36 import which
38 # == Global stuff ==
39 # Windows nees some special treatment. Differentiate between program name
40 # and executable filename.
41 program = "rbutilqt"
42 if sys.platform == "win32":
43 progexe = "Release/rbutilqt.exe"
44 else:
45 progexe = program
47 programfiles = [ progexe ]
50 # == Functions ==
51 def usage(myself):
52 print "Usage: %s [options]" % myself
53 print " -q, --qmake=<qmake> path to qmake"
54 print " -h, --help this help"
57 def findversion(versionfile):
58 '''figure most recent program version from version.h,
59 returns version string.'''
60 h = open(versionfile, "r")
61 c = h.read()
62 h.close()
63 r = re.compile("#define +VERSION +\"(.[0-9\.a-z]+)\"")
64 m = re.search(r, c)
65 s = re.compile("\$Revision: +([0-9]+)")
66 n = re.search(s, c)
67 if n == None:
68 print "WARNING: Revision not found!"
69 return m.group(1)
72 def findqt():
73 '''Search for Qt4 installation. Return path to qmake.'''
74 print "Searching for Qt"
75 bins = ["qmake", "qmake-qt4"]
76 result = ""
77 for binary in bins:
78 q = which.which(binary)
79 if len(q) > 0:
80 output = subprocess.Popen([q, "-version"], stdout=subprocess.PIPE,
81 stderr=subprocess.PIPE).communicate()
82 for ou in output:
83 r = re.compile("Qt[^0-9]+([0-9\.]+[a-z]*)")
84 m = re.search(r, ou)
85 if not m == None:
86 print "Qt found: %s" % m.group(1)
87 s = re.compile("4\..*")
88 n = re.search(s, m.group(1))
89 if not n == None:
90 result = q
91 if result == "":
92 print "ERROR: No suitable Qt found!"
94 return result
97 def qmake(qmake="qmake"):
98 print "Running qmake ..."
99 output = subprocess.Popen([qmake, "-config", "static", "-config", "release"],
100 stdout=subprocess.PIPE).communicate()
103 def build():
104 # make
105 print "Building ..."
106 output = subprocess.Popen(["make"], stdout=subprocess.PIPE).communicate()
107 # strip
108 print "Stripping binary."
109 output = subprocess.Popen(["strip", progexe], stdout=subprocess.PIPE).communicate()
112 def upxfile():
113 # run upx on binary
114 print "UPX'ing binary ..."
115 output = subprocess.Popen(["upx", progexe], stdout=subprocess.PIPE).communicate()
118 def zipball(versionstring):
119 '''package created binary'''
120 print "Creating binary zipball."
121 outfolder = program + "-v" + versionstring
122 archivename = outfolder + ".zip"
123 # create output folder
124 os.mkdir(outfolder)
125 # move program files to output folder
126 for f in programfiles:
127 shutil.copy(f, outfolder)
128 # create zipball from output folder
129 zf = zipfile.ZipFile(archivename, mode='w', compression=zipfile.ZIP_DEFLATED)
130 for root, dirs, files in os.walk(outfolder):
131 for name in files:
132 zf.write(os.path.join(root, name))
133 for name in dirs:
134 zf.write(os.path.join(root, name))
135 zf.close()
136 # remove output folder
137 for root, dirs, files in os.walk(outfolder, topdown=False):
138 for name in files:
139 os.remove(os.path.join(root, name))
140 for name in dirs:
141 os.rmdir(os.path.join(root, name))
142 os.rmdir(outfolder)
143 st = os.stat(archivename)
144 print "done: %s, %i bytes" % (archivename, st.st_size)
147 def tarball(versionstring):
148 '''package created binary'''
149 print "Creating binary tarball."
150 outfolder = program + "-v" + versionstring
151 archivename = outfolder + ".tar.bz2"
152 # create output folder
153 os.mkdir(outfolder)
154 # move program files to output folder
155 for f in programfiles:
156 shutil.copy(f, outfolder)
157 # create tarball from output folder
158 tf = tarfile.open(archivename, mode='w:bz2')
159 tf.add(outfolder)
160 tf.close()
161 # remove output folder
162 for root, dirs, files in os.walk(outfolder, topdown=False):
163 for name in files:
164 os.remove(os.path.join(root, name))
165 for name in dirs:
166 os.rmdir(os.path.join(root, name))
167 os.rmdir(outfolder)
168 st = os.stat(archivename)
169 print "done: %s, %i bytes" % (archivename, st.st_size)
172 def main():
173 try:
174 opts, args = getopt.getopt(sys.argv[1:], "qh", ["qmake=", "help"])
175 except getopt.GetoptError, err:
176 print str(err)
177 usage(sys.argv[0])
178 sys.exit(1)
179 qt = ""
180 for o, a in opts:
181 if o in ("-q", "--qmake"):
182 qt = a
183 if o in ("-h", "--help"):
184 usage(sys.argv[0])
185 sys.exit(0)
187 # qmake path
188 if qt == "":
189 qt = findqt()
190 if qt == "":
191 print "ERROR: No suitable Qt installation found."
192 os.exit(1)
194 # figure version from sources
195 ver = findversion("version.h")
196 header = "Building %s %s" % (program, ver)
197 print header
198 print len(header) * "="
200 # build it.
201 qmake(qt)
202 build()
203 if sys.platform == "win32":
204 upxfile()
205 zipball(ver)
206 else:
207 tarball(ver)
208 print "done."
211 if __name__ == "__main__":
212 main()