-
Notifications
You must be signed in to change notification settings - Fork 0
/
pavement.py
373 lines (329 loc) · 12.9 KB
/
pavement.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
#!/usr/bin/env python
# pavement.py - Paver file fore building BtSync AppImage
#
import sys
if not '' in sys.path:
sys.path.insert(0, '')
import re
from os import environ
from paver.easy import path, task, needs, sh, pushd
from version import get_git_version
BUILD_DIR=path('build')
WORK_DIR=BUILD_DIR / 'tmp'
TARGET_DIR=BUILD_DIR / 'AppDir'
BUILD_PREFIX='/_nowhere_'
TARGET_PREFIX=TARGET_DIR / 'usr'
DIR_MODE=0755
EXE_MODE=0755
PLATFORM='x86_64'
VERSION=get_git_version()
class Package(object):
"""Class for handling software packages"""
def __init__(self, version, workdir, name=None,
remote_name=None, remote_prefix=None,
local_name=None, local_prefix=None,
url=None, urlbase=None,
dir_in_archive=True, dirmode=DIR_MODE):
assert url or urlbase
self.remote_name = (remote_prefix and remote_prefix + '-' or '') + \
(remote_name or name or self.name_from_class()) + '-' + version
self.local_name = (local_prefix and local_prefix + '-' or '') + \
(local_name or name or self.name_from_class()) + '-' + version
self.remote_archive_name = self.remote_name + '.tar.gz'
self.local_archive_name = self.local_name + '.tar.gz'
self.url = url or (urlbase + '/' + self.remote_archive_name)
self.local_archive_path = workdir / self.local_archive_name
self.extract_path = workdir / self.local_name
self._strip_components = dir_in_archive and 1 or 0
self._dirmode = dirmode
def download(self):
"""Download the package"""
sh("curl -f '%s' -o '%s'" % (self.url, self.local_archive_path))
def extract(self):
"""Extract the packge"""
self.extract_path.mkdir(self._dirmode)
sh("tar -xvzf '%s' -C '%s' --strip-components=%d" % (\
self.local_archive_path, self.extract_path,
self._strip_components))
def download_and_extract(self):
"""Download and extract the package"""
self.download()
self.extract()
def name_from_class(self):
"""Convert class name into a package name.
Conversion is done by lowercasing all caps and adding dashes in front
of them when they follow lowercase letters.
For example:
BTSyncDeb => btsync-deb
"""
return re.sub('([a-z]?)([A-Z])',
lambda m: (m.group(1) and m.group(1) + '-') + \
m.group(2).lower(),
self.__class__.__name__)
class BTSync(Package):
def __init__(self, version='1.4.103', platform=PLATFORM, workdir=WORK_DIR,
targetdir=TARGET_DIR, dirmode=DIR_MODE):
self.platform = platform
self.platform_nic = { 'x86_64': 'x64' }.get(self.platform, self.platform)
super(BTSync, self).__init__(version=version,
name='btsync_' + self.platform_nic,
urlbase='http://syncapp.bittorrent.com/' + version,
dir_in_archive=False, workdir=workdir, dirmode=dirmode)
self.binary_src_path = self.extract_path / 'btsync'
self.binary_target_dir = targetdir / 'usr' / 'lib' / 'btsync-common'
self.binary_target_path = self.binary_target_dir / 'btsync-core'
self.key_target_dir = targetdir / 'usr' / 'lib' / 'btsync-gui'
self.key_target_path = self.key_target_dir / 'btsync-gui.key'
class BTSyncDeb(Package):
def __init__(self, tag='btsync-1.4.1-1', workdir=WORK_DIR):
super(BTSyncDeb, self).__init__(version=tag,
url='https://codeload.github.com/tuxpoldo/btsync-deb/tar.gz/' +
tag, workdir=workdir)
self.gui_path = self.extract_path / 'btsync-gui'
self.install_file = self.gui_path / 'debian' / 'btsync-gui-gtk.install'
self.patch = path('btsync_deb_appindicator_path.patch')
class QREncode(Package):
def __init__(self, version='3.4.4', workdir=WORK_DIR):
super(QREncode, self).__init__(version=version,
urlbase='http://fukuchi.org/works/qrencode',
workdir=workdir)
class PythonQREncode(Package):
def __init__(self, version='1.01', workdir=WORK_DIR, tagretdir=TARGET_DIR):
super(PythonQREncode, self).__init__(version=version,
remote_name='qrencode',
urlbase='https://pypi.python.org/packages/source/q/qrencode',
workdir=workdir)
self.patch = path('python_qrencode_fix_pillow_import.patch')
class PythonQREncode(Package):
def __init__(self, version='1.01', workdir=WORK_DIR, tagretdir=TARGET_DIR):
super(PythonQREncode, self).__init__(version=version,
remote_name='qrencode',
urlbase='https://pypi.python.org/packages/source/q/qrencode',
workdir=workdir)
self.patch = path('python_qrencode_fix_pillow_import.patch')
class Urllib3(Package):
def __init__(self, version='1.8.2', workdir=WORK_DIR, tagretdir=TARGET_DIR):
super(Urllib3, self).__init__(version=version,
urlbase='https://pypi.python.org/packages/source/u/urllib3',
workdir=workdir)
class Requests(Package):
def __init__(self, version='1.2.3', workdir=WORK_DIR, tagretdir=TARGET_DIR):
super(Requests, self).__init__(version=version,
urlbase='https://pypi.python.org/packages/source/r/requests',
workdir=workdir)
class AppImageKit(Package):
def __init__(self, tag='1', workdir=WORK_DIR):
super(AppImageKit, self).__init__(version=tag,
url='https://codeload.github.com/probonopd/AppImageKit/tar.gz/' +
tag, workdir=workdir)
self.patch = path('appimagekit_fix_icontheme.patch')
self.package_tool = self.extract_path / 'AppImageAssistant.AppDir' /\
'package'
self.libc_wrap_gen_path = self.extract_path / 'LibcWrapGenerator'
self.libc_wrap_gen_src = self.libc_wrap_gen_path /\
'LibcWrapGenerator.vala'
self.libc_wrap_gen = self.libc_wrap_gen_path / 'LibcWrapGenerator'
self.libc_wrap_h = self.libc_wrap_gen_path / 'libcwrap.h'
@task
def mk_build_dir():
"""Create directories to build the appdir in"""
for d in (BUILD_DIR, WORK_DIR, TARGET_DIR):
d.mkdir(DIR_MODE)
@task
@needs('mk_build_dir')
def get_btsync_bin():
"""Download the BtSync binary"""
BTSync().download_and_extract()
@task
@needs('mk_build_dir')
def get_btsync_deb_src():
"""Checkout btsync-deb source from Github"""
BTSyncDeb().download_and_extract()
@task
@needs('mk_build_dir')
def get_qrencode_src():
"""Download and extract qrencode sources"""
QREncode().download_and_extract()
@task
@needs('mk_build_dir')
def get_python_qrencode_src():
"""Download and extract python-qrencode sources"""
PythonQREncode().download_and_extract()
@task
@needs('mk_build_dir')
def get_python_urllib3_src():
"""Download and extract python-urllib3 sources"""
Urllib3().download_and_extract()
@task
@needs('mk_build_dir')
def get_python_requests_src():
"""Download and extract python-requests sources"""
Requests().download_and_extract()
@task
@needs('mk_build_dir')
def get_appimagekit_src():
"""Checkout AppImageKit source from Github"""
AppImageKit().download_and_extract()
@task
@needs('get_btsync_deb_src')
def build_btsync_gui():
"""Build the BySync GUI"""
btsd=BTSyncDeb()
locdir = btsd.gui_path / 'locale'
locdir.mkdir(DIR_MODE)
for pofile in (btsd.gui_path / 'po').glob('*.po'):
dstdir = locdir
for sd in (pofile.namebase, 'LC_MESSAGES'):
dstdir = dstdir / sd
dstdir.mkdir(DIR_MODE)
sh("msgfmt -c '%s' -o '%s'" % (pofile, dstdir / 'btsync-gu.mo'))
patchabs = btsd.patch.abspath()
with pushd(btsd.extract_path):
sh("patch -p1 < '%s'" % (patchabs))
@task
@needs('get_qrencode_src')
def build_qrencode():
"""Build the qrencode library"""
with pushd(QREncode().extract_path):
sh("./configure --without-tools --without-tests --prefix='%s'" % \
(BUILD_PREFIX))
sh('make')
@task
@needs('get_python_qrencode_src', 'install_qrencode')
def build_python_qrencode():
"""Build the python-qrencode library"""
pqre = PythonQREncode()
include_dir = (TARGET_PREFIX / 'include').abspath()
lib_dir = (TARGET_PREFIX / 'lib').abspath()
environ['CFLAGS'] = '-I' + include_dir
environ['LDFLAGS'] = '-L' + lib_dir
patchabs = pqre.patch.abspath()
with pushd(pqre.extract_path):
sh("patch -p1 < '%s'" % (patchabs))
sh("python setup.py build")
@task
@needs('get_python_urllib3_src')
def build_python_urllib3():
"""Build the python-urllib3 library"""
pl = Urllib3()
with pushd(pl.extract_path):
sh("python setup.py build")
@task
@needs('get_python_requests_src')
def build_python_requests():
"""Build the python-requests library"""
pl = Requests()
with pushd(pl.extract_path):
sh("python setup.py build")
@task
@needs('get_appimagekit_src')
def build_appimagekit():
"""Build the AppImahgeKit"""
aik = AppImageKit()
patchabs = aik.patch.abspath()
with pushd(aik.extract_path):
sh("patch -p1 < '%s'" % (patchabs,))
sh("cmake .")
sh('rm -f AppImageAssistant')
sh('make AppImageAssistant')
lcwgsabs = aik.libc_wrap_gen_src.abspath()
with pushd(aik.libc_wrap_gen_path):
sh("valac --pkg gee-0.8 --pkg posix --pkg glib-2.0 --pkg gio-2.0 '%s'" %
(lcwgsabs,))
sh("%s --target 2.7 --libdir /lib --output '%s'" % \
(aik.libc_wrap_gen, aik.libc_wrap_h))
@task
@needs('build_btsync_gui')
def install_btsync_gui():
"""Install the BTSync GUI files to the AppDir"""
btsd=BTSyncDeb()
with open(btsd.install_file, 'r') as f:
for l in f:
if re.match('^\s*(#|$)', l):
continue
src, dst = l.split()
src = btsd.gui_path / src
# The *.desktop file goes to the AppDir root to AppImageKit will
# find it
if src.ext == '.desktop':
dst = TARGET_DIR
else:
dst = TARGET_DIR / dst
dst.makedirs(DIR_MODE)
sh("cp --preserve=mode -frt '%s' '%s'" % (dst, src))
@task
@needs('get_btsync_bin')
def install_btsync_bin():
"""Install the BTSync binary to the AppDir"""
btsync = BTSync()
btsync.binary_target_dir.makedirs(DIR_MODE)
sh("install -m %o '%s' '%s'" % (EXE_MODE, btsync.binary_src_path,
btsync.binary_target_path))
@task
@needs('mk_build_dir')
def install_api_token():
"""Install the API token to the AppDir"""
btsync = BTSync()
btsync.key_target_dir.makedirs(DIR_MODE)
path('btsync-api-token.txt').copyfile(btsync.key_target_path)
@task
@needs('mk_build_dir')
def install_apprun():
"""Install the AppRun script in the AppDir"""
sh("install -m %o '%s' '%s'" % (EXE_MODE, 'AppRun', TARGET_DIR / 'AppRun'))
@task
@needs('build_qrencode')
def install_qrencode():
"""Instrall the qrencode library"""
abstgt=TARGET_PREFIX.abspath()
with pushd(QREncode().extract_path):
sh('make prefix=%s install' % (abstgt))
@task
@needs('build_python_qrencode')
def install_python_qrencode():
"""Install the qrencode Python bindings"""
abstgt=TARGET_PREFIX.abspath()
abslib=(TARGET_PREFIX / 'lib' / 'python').abspath()
with pushd(PythonQREncode().extract_path):
sh("python setup.py install --home='%s' --install-lib='%s'" % (abstgt,
abslib))
@task
@needs('build_python_urllib3')
def install_python_urllib3():
"""Install the urllib3 Python library"""
abstgt=TARGET_PREFIX.abspath()
abslib=(TARGET_PREFIX / 'lib' / 'python').abspath()
environ['PYTHONPATH'] = (environ.has_key('PYTHONPATH') and
environ['PYTHONPATH'] + ':' or '') + abslib
with pushd(Urllib3().extract_path):
sh("python setup.py install --home='%s' --install-lib='%s'" % (abstgt,
abslib))
@task
@needs('build_python_requests')
def install_python_requests():
"""Install the requests Python library"""
abstgt=TARGET_PREFIX.abspath()
abslib=(TARGET_PREFIX / 'lib' / 'python').abspath()
environ['PYTHONPATH'] = (environ.has_key('PYTHONPATH') and
environ['PYTHONPATH'] + ':' or '') + abslib
with pushd(Requests().extract_path):
sh("python setup.py install --home='%s' --install-lib='%s'" % (abstgt,
abslib))
@task
@needs(['install_python_qrencode', 'install_python_urllib3',
'install_python_requests', 'install_btsync_gui', 'install_btsync_bin',
'install_api_token', 'install_apprun'])
def install():
"""Install everything to the AppDir"""
pass
@task
@needs(['install', 'build_appimagekit'])
def mk_appimage():
"""Create an AppImage containing the app and all dependencies"""
pt = AppImageKit().package_tool
target = BUILD_DIR / ('btsync-app-%s-%s' % (PLATFORM, VERSION))
sh("%s '%s' '%s'" % (pt, TARGET_DIR, target))
@task
def clean():
"""Delete all build artifacts"""
sh("rm -rf '%s'" % (BUILD_DIR))