-
Notifications
You must be signed in to change notification settings - Fork 38
/
tasks.py
385 lines (303 loc) · 9.59 KB
/
tasks.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
374
375
376
377
378
379
380
381
382
383
384
385
#!/usr/bin/python
# -*- coding: utf-8 -*-
import builtins
import os
import os.path
import glob
import sys
import shutil
import re
from typing import List, Tuple, Callable, TextIO
from pathlib import Path
from invoke import task
from buildtools.utilites import getPython, print_info
from buildtools.defines import DEB_BINARY_BUILD_DIR, COVERAGE_PARAMS
from buildtools.builders import (BuilderWindows,
BuilderSources,
BuilderPlugins,
BuilderLinuxBinary,
BuilderDebBinaryFactory,
BuilderAppImage,
BuilderSnap,
BuilderWxPython
)
from buildtools.versionstools import (display_version,
InitUpdater,
VersionsXmlUpdater,
AppDataXmlUpdater)
@task
def plugins(c):
'''
Create an archive with plugins (7z required)
'''
builder = BuilderPlugins(c)
builder.build()
@task
def plugins_clear(c):
'''
Remove an archive with plugins (7z required)
'''
builder = BuilderPlugins(c)
builder.clear()
@task
def sources(c, is_stable=False):
'''
Create the sources archives
'''
builder = BuilderSources(c, is_stable=is_stable)
builder.build()
@task
def sources_clear(c):
'''
Remove the sources archives.
'''
builder = BuilderSources(c)
builder.clear()
@task
def win(c, is_stable=False, skiparchives=False, skipinstaller=False):
'''
Build OutWiker for Windows
'''
builder = BuilderWindows(c,
is_stable=is_stable,
create_archives=not skiparchives,
create_installer=not skipinstaller
)
builder.build()
@task
def win_clear(c):
'''
Remove assemblies under Windows
'''
builder = BuilderWindows(c)
builder.clear()
@task
def linux_binary(c, is_stable=False, skiparchives=False):
'''
Assemble binary builds for Linux
'''
builder = BuilderLinuxBinary(c,
is_stable,
create_archive=not skiparchives
)
builder.build()
@task
def linux_clear(c):
'''
Remove binary builds for Linux
'''
builder = BuilderLinuxBinary(c)
builder.clear()
@task
def run(c, args=''):
'''
Run OutWiker from sources
'''
with c.cd("src"):
c.run('{} runoutwiker.py {}'.format(getPython(), args))
@task(iterable=['params'])
def test(c, params):
'''
Run the unit tests
'''
if not params:
params = ['buildtools/src/buildtools/tests', 'src/outwiker/tests']
command = getPython() if params else 'coverage run {}'.format(COVERAGE_PARAMS)
c.run('{command} runtests.py {args}'.format(
command=command, args=' '.join(params)))
def _runTests(c, testdir, prefix, section='', *args):
files = [fname[len(testdir) + 1:]
for fname
in glob.glob('{path}/{prefix}*.py'.format(path=testdir,
prefix=prefix))]
files.sort()
with c.cd(testdir):
if section:
c.run('{python} {prefix}{section}.py {params}'.format(
python=getPython(),
prefix=prefix,
section=section,
params=' '.join(args))
)
else:
# with settings(warn_only=True):
for fname in files:
c.run('{python} {fname} {params}'.format(
python=getPython(),
fname=fname,
params=' '.join(args))
)
@task
def deb_binary(c, is_stable=False):
'''
Create binary deb package
'''
builder = BuilderDebBinaryFactory.get_default(DEB_BINARY_BUILD_DIR,
is_stable)
builder.build()
print_info('Deb created: {}'.format(builder.get_deb_files()))
@task
def deb_binary_clear(c):
'''
Remove binary deb package
'''
builder = BuilderDebBinaryFactory.get_default()
builder.clear()
@task
def clear(c):
'''
Remove artifacts after all assemblies
'''
plugins_clear()
sources_clear()
if sys.platform.startswith('linux'):
linux_clear()
# deb_clear()
deb_binary_clear()
elif sys.platform.startswith('win32'):
win_clear()
@task
def create_tree(c, maxlevel, nsiblings, path):
'''
Create wiki tree for the tests
'''
from outwiker.core.tree import WikiDocument
builtins._ = _empty
wikiroot = WikiDocument.create(path)
_create_tree(1, int(maxlevel), int(nsiblings), wikiroot)
def _empty(param):
return param
def _create_tree(level, maxlevel, nsiblings, parent):
from outwiker.pages.wiki.wikipage import WikiPageFactory
if level <= maxlevel:
for n in range(nsiblings):
pagename = 'page_{:03g}_{:03g}'.format(level, n)
print('Create page {}'.format(pagename))
newpage = WikiPageFactory().create(parent, pagename, [])
newpage.content = 'Абырвалг'
newpage.icon = 'images/outwiker_16.png'
_create_tree(level + 1, maxlevel, nsiblings, newpage)
@task
def build(c, is_stable=False):
'''
Create artifacts for current version.
'''
if is_stable:
build(False)
sources(c, is_stable)
plugins(c)
if sys.platform.startswith('win32'):
win(c, is_stable)
@task
def doc(c):
'''
Build documentation
'''
doc_path = 'doc/_build'
if os.path.exists(doc_path):
shutil.rmtree(doc_path)
with c.cd('doc'):
c.run('make html')
@task
def appimage(c, is_stable=False):
'''
Build AppImage package
'''
builder = BuilderAppImage(c, is_stable)
builder.build()
print_info('AppImage created: {}'.format(builder.get_appimage_files()))
@task
def coverage(c):
'''
Create test coverage statistics
'''
c.run('coverage report {} -i'.format(COVERAGE_PARAMS))
c.run('coverage html {} -i'.format(COVERAGE_PARAMS))
@task
def docker_build_create(c):
'''
Create a Docker image to build process
'''
with c.cd('need_for_build/build_docker'):
c.run('docker build -t outwiker/build_linux .')
@task
def docker_build(c, *args):
'''
Run the build process inside the Docker container
'''
docker_build_create()
tasks_str = ' '.join(args)
current_dir = os.path.abspath('.')
command = 'docker run -v "{path}:/home/user/project" --user $(id -u):$(id -g) -i -t outwiker/build_linux {tasks}'.format(
path=current_dir,
tasks=tasks_str
)
c.run(command)
@task(iterable=['params'])
def snap(c, params):
'''
Build clean snap package
'''
builder = BuilderSnap(c, params)
builder.build()
@task
def set_version(c, version_str=''):
"""Set new OutWiker version for all files with versions"""
if not version_str.strip():
display_version()
version_str = input(
'Enter new OutWiker version in the format: "x.x.x.xxx [status]": ')
version, status = _parse_version(version_str)
for fname, updater in _get_version_updaters():
_update_version_for_file(fname, updater.set_version, version, status)
@task
def add_new_version(c, version_str=''):
"""Append new version information to all files with versions"""
if not version_str.strip():
display_version()
version_str = input(
'Enter new OutWiker version in the format: "x.x.x.xxx [status]": ')
version, status = _parse_version(version_str)
for fname, updater in _get_version_updaters():
_update_version_for_file(fname, updater.add_version, version, status)
@task
def set_release_date(c, date=''):
"""Set release date for current version"""
if not date.strip():
display_version()
date = input('Enter OutWiker release date in the format: YYYY-MM-DD: ')
for fname, updater in _get_version_updaters():
_set_release_date_for_file(fname, updater, date)
@task
def build_wxpython(c):
"""Build wxPython from depends"""
builder = BuilderWxPython(c)
builder.build()
def _get_version_updaters():
return [
(Path('src', 'outwiker', '__init__.py'), InitUpdater()),
(Path('need_for_build', 'versions.xml'), VersionsXmlUpdater()),
(Path('need_for_build', 'linux',
'net.jenyay.Outwiker.appdata.xml'), AppDataXmlUpdater()),
]
def _parse_version(version_str: str) -> Tuple[List[int], str]:
regexp = re.compile(r'(?P<numbers>(\d+)(\.\d+)*)(?P<status>\s+.*)?')
match = regexp.match(version_str)
numbers = [int(number) for number in match.group('numbers').split('.')]
status = match.group('status')
if status is None:
status = ''
return (numbers, status.strip())
def _update_version_for_file(path: str,
updater_func: Callable[[TextIO, List[int], str], str],
version: List[int],
status: str):
with open(path, encoding="utf-8") as fp_in:
content_new = updater_func(fp_in, version, status)
with open(path, 'w', encoding="utf-8") as fp_out:
fp_out.write(content_new)
def _set_release_date_for_file(path: str, updater, date_str: str):
with open(path) as fp_in:
content_new = updater.set_release_date(fp_in, date_str)
with open(path, 'w') as fp_out:
fp_out.write(content_new)