summaryrefslogtreecommitdiff
path: root/rbutil/rbutilqt/deploy-release.py
diff options
context:
space:
mode:
Diffstat (limited to 'rbutil/rbutilqt/deploy-release.py')
-rw-r--r--rbutil/rbutilqt/deploy-release.py214
1 files changed, 214 insertions, 0 deletions
diff --git a/rbutil/rbutilqt/deploy-release.py b/rbutil/rbutilqt/deploy-release.py
new file mode 100644
index 0000000000..a4b9dcea97
--- /dev/null
+++ b/rbutil/rbutilqt/deploy-release.py
@@ -0,0 +1,214 @@
1#!/usr/bin/python
2# __________ __ ___.
3# Open \______ \ ____ ____ | | _\_ |__ _______ ___
4# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7# \/ \/ \/ \/ \/
8# $Id$
9#
10# Copyright (c) 2009 Dominik Riebeling
11#
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.
14#
15# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16# KIND, either express or implied.
17#
18#
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
23#
24# requires python which package (http://code.google.com/p/which/)
25# requires upx.exe in PATH on Windows.
26#
27
28import re
29import os
30import sys
31import tarfile
32import zipfile
33import shutil
34import subprocess
35import getopt
36import which
37
38# == Global stuff ==
39# Windows nees some special treatment. Differentiate between program name
40# and executable filename.
41program = "rbutilqt"
42if sys.platform == "win32":
43 progexe = "Release/rbutilqt.exe"
44else:
45 progexe = program
46
47programfiles = [ progexe ]
48
49
50# == Functions ==
51def usage(myself):
52 print "Usage: %s [options]" % myself
53 print " -q, --qmake=<qmake> path to qmake"
54 print " -h, --help this help"
55
56
57def 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)
70
71
72def 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!"
93
94 return result
95
96
97def qmake(qmake="qmake"):
98 print "Running qmake ..."
99 output = subprocess.Popen([qmake, "-config", "static", "-config", "release"],
100 stdout=subprocess.PIPE).communicate()
101
102
103def 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()
110
111
112def upxfile():
113 # run upx on binary
114 print "UPX'ing binary ..."
115 output = subprocess.Popen(["upx", progexe], stdout=subprocess.PIPE).communicate()
116
117
118def 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)
145
146
147def 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)
170
171
172def 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)
186
187 # qmake path
188 if qt == "":
189 qt = findqt()
190 if qt == "":
191 print "ERROR: No suitable Qt installation found."
192 os.exit(1)
193
194 # figure version from sources
195 ver = findversion("version.h")
196 header = "Building %s %s" % (program, ver)
197 print header
198 print len(header) * "="
199
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."
209
210
211if __name__ == "__main__":
212 main()
213
214