-
Notifications
You must be signed in to change notification settings - Fork 39
/
fabfile.py
executable file
·738 lines (605 loc) · 19.7 KB
/
fabfile.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
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
#!/usr/bin/python
# -*- coding: utf-8 -*-
import builtins
import os
import os.path
import glob
import sys
import urllib.request
import urllib.error
import urllib.parse
import shutil
from fabric.api import local, lcd, settings, task, cd, put, hosts
from buildtools.libs.colorama import Fore
from buildtools.buildfacts import BuildFacts
from buildtools.utilites import (getPython,
execute,
getCurrentUbuntuDistribName,
getPathToPlugin,
tobool,
print_info,
print_warning,
print_error,
windows_only,
linux_only
)
from buildtools.defines import (
UBUNTU_RELEASE_NAMES,
BUILD_DIR,
DEB_SOURCE_BUILD_DIR,
DEB_BINARY_BUILD_DIR,
PLUGINS_DIR,
PLUGINS_LIST,
PLUGIN_VERSIONS_FILENAME,
FILES_FOR_UPLOAD_UNSTABLE_WIN,
FILES_FOR_UPLOAD_STABLE_WIN,
FILES_FOR_UPLOAD_UNSTABLE_LINUX,
FILES_FOR_UPLOAD_STABLE_LINUX,
NEED_FOR_BUILD_DIR,
PPA_UNSTABLE_PATH,
PPA_STABLE_PATH,
VM_BUILD_PARAMS,
LINUX_BUILD_DIR,
WINDOWS_BUILD_DIR,
)
from buildtools.versions import (getOutwikerVersion,
getOutwikerVersionStr,
downloadAppInfo,
getLocalAppInfoList,
)
from buildtools.contentgenerators import SiteChangelogGenerator
from buildtools.builders import (BuilderWindows,
BuilderSources,
BuilderPlugins,
BuilderLinuxBinary,
BuilderDebBinaryFactory,
BuilderDebSource,
BuilderDebSourcesIncluded,
BuilderAppImage,
)
from outwiker.utilites.textfile import readTextFile
from outwiker.core.xmlversionparser import XmlVersionParser
import outwiker
import outwiker.core
import outwiker.gui
import outwiker.actions
import outwiker.pages
import outwiker.utilites
import outwiker.libs
try:
from buildtools.serverinfo import (DEPLOY_SERVER_NAME,
DEPLOY_UNSTABLE_PATH,
DEPLOY_STABLE_PATH,
DEPLOY_HOME_PATH,
DEPLOY_SITE,
DEPLOY_PLUGINS_PACK_PATH,
PATH_TO_WINDOWS_DISTRIBS,
)
except ImportError:
shutil.copyfile(u'buildtools/serverinfo.py.example',
u'buildtools/serverinfo.py')
from buildtools.serverinfo import (DEPLOY_SERVER_NAME,
DEPLOY_UNSTABLE_PATH,
DEPLOY_STABLE_PATH,
DEPLOY_HOME_PATH,
DEPLOY_SITE,
DEPLOY_PLUGINS_PACK_PATH,
PATH_TO_WINDOWS_DISTRIBS,
)
from buildtools.uploaders import BinaryUploader
@task
@linux_only
def deb_sources_included(is_stable=False):
'''
Create files for uploading in PPA (including sources)
'''
builder = BuilderDebSourcesIncluded(DEB_SOURCE_BUILD_DIR,
UBUNTU_RELEASE_NAMES,
tobool(is_stable))
builder.build()
return builder.getResultPath()
@task
@linux_only
def deb(is_stable=False):
'''
Assemble the deb packages
'''
builder = BuilderDebSource(DEB_SOURCE_BUILD_DIR,
UBUNTU_RELEASE_NAMES,
tobool(is_stable))
builder.build()
return builder.getResultPath()
@task
@linux_only
def deb_clear():
'''
Remove the deb packages
'''
builder = BuilderDebSource(DEB_SOURCE_BUILD_DIR,
UBUNTU_RELEASE_NAMES,
False)
builder.clear()
@task
@linux_only
def deb_single(is_stable=False):
'''
Assemble the deb package for the current Ubuntu release
'''
builder = BuilderDebSource(DEB_SOURCE_BUILD_DIR,
[getCurrentUbuntuDistribName()],
tobool(is_stable))
builder.build()
return builder.getResultPath()
@task
@linux_only
def deb_install(is_stable=False):
'''
Assemble deb package for current Ubuntu release
'''
result_path = deb_single(tobool(is_stable))
version = getOutwikerVersion()
with lcd(result_path):
local("sudo dpkg -i outwiker_{}+{}~{}_all.deb".format(
version[0],
version[1],
getCurrentUbuntuDistribName()))
def _ppa_upload(ppa_path, deb_path):
'''
Upload the current OutWiker version in PPA
'''
version = getOutwikerVersion()
for distname in UBUNTU_RELEASE_NAMES:
with lcd(deb_path):
local("dput {} outwiker_{}+{}~{}_source.changes".format(
ppa_path,
version[0],
version[1],
distname))
@task
def plugins(updatedonly=False):
'''
Create an archive with plugins (7z required)
'''
builder = BuilderPlugins(updatedOnly=updatedonly)
builder.build()
@task
def plugins_clear():
'''
Remove an archive with plugins (7z required)
'''
builder = BuilderPlugins()
builder.clear()
@task
def sources(is_stable=False):
'''
Create the sources archives
'''
builder = BuilderSources(is_stable=tobool(is_stable))
builder.build()
@task
def sources_clear():
'''
Remove the sources archives.
'''
builder = BuilderSources()
builder.clear()
@task
@windows_only
def win(is_stable=False, skipinstaller=False, skiparchives=False):
'''
Build OutWiker for Windows with cx_Freeze
'''
builder = BuilderWindows(is_stable=tobool(is_stable),
create_archives=not tobool(skiparchives),
create_installer=not tobool(skipinstaller)
)
builder.build()
@task
@windows_only
def win_clear():
'''
Remove assemblies under Windows
'''
builder = BuilderWindows()
builder.clear()
@task
@linux_only
def linux_binary(is_stable=False, skiparchives=False):
'''
Assemble binary builds for Linux
'''
builder = BuilderLinuxBinary(is_stable=tobool(is_stable),
create_archive=not tobool(skiparchives)
)
builder.build()
@task
@linux_only
def linux_clear():
'''
Remove binary builds for Linux
'''
builder = BuilderLinuxBinary()
builder.clear()
@task
@linux_only
def locale():
'''
Update the localization file (outwiker.pot)
'''
with lcd("src"):
local(r'find . -iname "*.py" | xargs xgettext -o locale/outwiker.pot')
@task(alias='plugin_locale')
@linux_only
def locale_plugin(pluginname):
'''
Create or update the localization file for pluginname plug-in
'''
with lcd(os.path.join("plugins", pluginname, pluginname)):
local(r'find . -iname "*.py" | xargs xgettext -o locale/{}.pot'.format(pluginname))
@task
def run(args=u''):
'''
Run OutWiker from sources
'''
with lcd("src"):
execute(u'{} runoutwiker.py {}'.format(getPython(), args))
@task
def test(section=u'', *args):
'''
Run the unit tests
'''
_runTests(u'src', u'tests_', section, *args)
if len(section) == 0:
test_build(section, *args)
@task
def test_build(section=u'', *args):
'''
Run the build unit tests
'''
_runTests(u'.', u'test_build_', section, *args)
def _runTests(testdir, prefix, section=u'', *args):
files = [fname[len(testdir) + 1:]
for fname
in glob.glob(u'{path}/{prefix}*.py'.format(path=testdir,
prefix=prefix))]
files.sort()
with lcd(testdir):
if section:
execute("{python} {prefix}{section}.py {params}".format(
python=getPython(),
prefix=prefix,
section=section,
params=u' '.join(args))
)
else:
with settings(warn_only=True):
for fname in files:
execute("{python} {fname} {params}".format(
python=getPython(),
fname=fname,
params=u' '.join(args))
)
@task
@linux_only
def deb_binary(is_stable=False):
'''
Create binary deb package
'''
builder = BuilderDebBinaryFactory.get_default(DEB_BINARY_BUILD_DIR,
tobool(is_stable))
builder.build()
@task
@linux_only
def deb_binary_clear():
'''
Remove binary deb package
'''
builder = BuilderDebBinaryFactory.get_default()
builder.clear()
@task
def clear():
'''
Remove artefacts 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 plugin_changelog(plugin, lang):
'''
Generate plugin's changelog for the site
'''
path_to_xml = os.path.join(getPathToPlugin(plugin),
PLUGIN_VERSIONS_FILENAME)
_print_changelog(path_to_xml, lang)
@task
def outwiker_changelog(lang):
'''
Generate OutWiker's changelog for the site
'''
path_to_xml = os.path.join(u'src', 'versions.xml')
_print_changelog(path_to_xml, lang)
def _print_changelog(path_to_xml, lang):
xml_content = readTextFile(path_to_xml)
parser = XmlVersionParser([lang])
appinfo = parser.parse(xml_content)
generator = SiteChangelogGenerator(appinfo)
changelog = generator.make()
print(changelog)
@task
def site_versions():
'''
Compare current OutWiker and plugins versions with versions on the site
'''
app_list = getLocalAppInfoList()
# Downloading versions info
print(u'Downloading version info files...\n')
print(u'{: <20}{: <20}{}'.format(u'Title',
u'Deployed version',
u'Dev. version'))
print(u'-' * 60)
for localAppInfo in app_list:
url = localAppInfo.updatesUrl
name = localAppInfo.appname
print(u'{:.<20}'.format(name), end=u'')
try:
appinfo = downloadAppInfo(url)
if appinfo.currentVersion == localAppInfo.currentVersion:
font = Fore.GREEN
else:
font = Fore.RED
print(u'{siteversion:.<20}{devversion}'.format(
siteversion=str(appinfo.currentVersion),
devversion=font + str(localAppInfo.currentVersion)
))
except (urllib.error.URLError, urllib.error.HTTPError) as e:
print(Fore.RED + u'Error')
print(str(e))
print(url)
print('')
@task
def create_tree(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 = u'page_{:03g}_{:03g}'.format(level, n)
print(u'Create page {}'.format(pagename))
newpage = WikiPageFactory().create(parent, pagename, [])
newpage.content = u'Абырвалг'
newpage.icon = u'images/outwiker_16.png'
_create_tree(level + 1, maxlevel, nsiblings, newpage)
@hosts(DEPLOY_SERVER_NAME)
@task
def upload_plugin(*args):
'''
Upload plugin to site
'''
if len(args) == 0:
args = PLUGINS_LIST
version_str = getOutwikerVersionStr()
for pluginname in args:
path_to_plugin_local = os.path.join(BUILD_DIR,
version_str,
PLUGINS_DIR,
pluginname)
if not os.path.exists(path_to_plugin_local):
continue
path_to_xml_local = os.path.join(path_to_plugin_local,
PLUGIN_VERSIONS_FILENAME)
xml_content_local = readTextFile(path_to_xml_local)
appinfo_local = XmlVersionParser().parse(xml_content_local)
url = appinfo_local.updatesUrl
try:
appinfo_remote = downloadAppInfo(url)
except Exception:
appinfo_remote = None
if (appinfo_remote is not None and
appinfo_local.currentVersion < appinfo_remote.currentVersion):
print_error(u'Error. New version < Prev version')
sys.exit(1)
elif (appinfo_remote is not None and
appinfo_local.currentVersion == appinfo_remote.currentVersion):
print_warning(u'Warning: Uploaded the same version')
print_info(u'Uploading...')
path_to_upload = os.path.dirname(appinfo_local.updatesUrl.replace(DEPLOY_SITE + u'/', DEPLOY_HOME_PATH))
version_local = unicode(appinfo_local.currentVersion)
archive_name = u'{}-{}.zip'.format(pluginname, version_local)
path_to_archive_local = os.path.join(path_to_plugin_local, archive_name)
with cd(path_to_upload):
put(path_to_archive_local, archive_name)
put(path_to_xml_local, PLUGIN_VERSIONS_FILENAME)
site_versions()
@hosts(DEPLOY_SERVER_NAME)
@task
def upload_binary(is_stable=False):
'''
Upload unstable version to site
'''
facts = BuildFacts()
if is_stable:
win_tpl_files = FILES_FOR_UPLOAD_STABLE_WIN
linux_tpl_files = FILES_FOR_UPLOAD_STABLE_LINUX
deploy_path = DEPLOY_STABLE_PATH
else:
win_tpl_files = FILES_FOR_UPLOAD_UNSTABLE_WIN
linux_tpl_files = FILES_FOR_UPLOAD_UNSTABLE_LINUX
deploy_path = DEPLOY_UNSTABLE_PATH
versions_file = facts.versions_file
windows_result_path = os.path.join(PATH_TO_WINDOWS_DISTRIBS,
facts.version,
WINDOWS_BUILD_DIR)
binary_uploader = BinaryUploader(win_tpl_files,
linux_tpl_files,
windows_result_path,
versions_file,
deploy_path)
binary_uploader.deploy()
@hosts(DEPLOY_SERVER_NAME)
@task
def upload_plugins_pack():
'''
Upload archive with all plugins to site
'''
pluginsBuilder = BuilderPlugins()
pack_path = pluginsBuilder.get_plugins_pack_path()
with cd(DEPLOY_PLUGINS_PACK_PATH):
basename = os.path.basename(pack_path)
put(pack_path, basename)
def _add_git_tag(tagname):
local(u'git checkout master')
local(u'git tag {}'.format(tagname))
local(u'git push --tags')
@task
def build(is_stable=False):
'''
Create artefacts for current version.
'''
if is_stable:
build(False)
sources(is_stable)
plugins(True)
if sys.platform.startswith('linux'):
vm_linux_binary(is_stable)
deb_sources_included(is_stable)
elif sys.platform.startswith('win32'):
win(is_stable)
@hosts(DEPLOY_SERVER_NAME)
@task
@linux_only
def deploy(is_stable=False):
'''
Upload unstable version to site
'''
if is_stable:
deploy(False)
else:
# To upload only once
upload_plugin()
upload_plugins_pack()
ppa_path = PPA_STABLE_PATH if is_stable else PPA_UNSTABLE_PATH
deb_path = BuilderDebSourcesIncluded(DEB_SOURCE_BUILD_DIR,
UBUNTU_RELEASE_NAMES,
tobool(is_stable)).getResultPath()
_ppa_upload(ppa_path, deb_path)
upload_binary(is_stable)
version_str = getOutwikerVersionStr()
if is_stable:
tagname = u'release_{}'.format(version_str)
else:
tagname = u'unstable_{}'.format(version_str)
_add_git_tag(tagname)
@task(alias='apiversions')
def apiversion():
'''
Print current OutWiker API versions
'''
print(u'core: {}.{}'.format(outwiker.core.__version__[0],
outwiker.core.__version__[1]))
print(u'gui: {}.{}'.format(outwiker.gui.__version__[0],
outwiker.gui.__version__[1]))
print(u'actions: {}.{}'.format(outwiker.actions.__version__[0],
outwiker.actions.__version__[1]))
print(u'pages: {}.{}'.format(outwiker.pages.__version__[0],
outwiker.pages.__version__[1]))
print(u'utilites: {}.{}'.format(outwiker.utilites.__version__[0],
outwiker.utilites.__version__[1]))
print(u'libs: {}.{}'.format(outwiker.libs.__version__[0],
outwiker.libs.__version__[1]))
@task
def doc():
'''
Build documentation
'''
doc_path = u'doc/_build'
if os.path.exists(doc_path):
shutil.rmtree(doc_path)
with lcd('doc'):
local('make html')
@task
def prepare_virtual():
'''
Prepare virtual machine
'''
with lcd(os.path.join(NEED_FOR_BUILD_DIR, u'virtual')):
local(u'ansible-playbook virtual_prepare.yml -k --ask-sudo-pass')
@task
def vm_run():
'''
Run virtual machines for build
'''
for host_param in VM_BUILD_PARAMS.values():
with lcd(host_param[u'vagrant_path']):
local(u'vagrant up')
@task
def vm_update():
'''
Update the virtual machines
'''
for host_param in VM_BUILD_PARAMS.values():
with lcd(host_param[u'vagrant_path']):
local(u'vagrant box update')
@task(alias='vm_halt')
def vm_stop():
'''
Stop virtual machines for build
'''
for host_param in VM_BUILD_PARAMS.values():
with lcd(host_param[u'vagrant_path']):
local(u'vagrant halt')
@task
@linux_only
def vm_remove_keys():
'''
Remove local SSH keys for remote virual machines
'''
for host_param in VM_BUILD_PARAMS.values():
host = host_param[u'host']
local(u'ssh-keygen -f ~/.ssh/known_hosts -R {}'.format(host))
@task
def vm_prepare():
'''
Prepare virtual machines for build
'''
vm_run()
with lcd(u'need_for_build/virtual/build_machines'):
local(u'ansible-playbook prepare_build_machines.yml')
@task
def vm_linux_binary(is_stable=0):
'''
Create 64-bit assembly on virtual machines
'''
vm_run()
version_str = getOutwikerVersionStr()
version = getOutwikerVersion()
path_to_result = os.path.abspath(
os.path.join(BUILD_DIR, version_str, LINUX_BUILD_DIR)
)
if not os.path.exists(path_to_result):
os.makedirs(path_to_result)
with lcd(u'need_for_build/virtual/build_machines'):
local(u'ansible-playbook build_linux_binaries.yml --extra-vars "version={version} build={build} save_to={save_to} is_stable={is_stable}"'.format(
version=version[0],
build=version[1],
save_to=path_to_result,
is_stable=is_stable)
)
@task(alias='linux_appimage')
@linux_only
def appimage(is_stable=0):
builder = BuilderAppImage(is_stable=tobool(is_stable))
builder.build()