forked from Jenyay/outwiker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
executable file
·375 lines (279 loc) · 10.1 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
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os
import os.path
import shutil
import glob
from fabric.api import local, lcd, settings
# Supported Ubuntu releases
distribs = ["wily", "trusty", "xenial"]
# List of the supported plugins
plugins_list = [
"autorenamer",
"changepageuid",
"counter",
"diagrammer",
"datagraph",
"export2html",
"externaltools",
"htmlformatter",
"htmlheads",
"lightbox",
"livejournal",
"pagetypecolor",
"readingmode",
"sessions",
"source",
"spoiler",
"statistics",
"style",
"thumbgallery",
"tableofcontents",
"texequation",
"updatenotifier",
"webpage",
]
def _getVersion():
"""
Return a tuple: (version number, build number)
"""
# The file with version number
fname = u"src/version.txt"
with open (fname) as fp_in:
lines = fp_in.readlines()
return (lines[0].strip(), lines[1].strip())
def _getDebSourceDirName():
"""
Return a folder name for sources for building the deb package
"""
version = _getVersion()
return "outwiker-{}+{}".format (version[0], version[1])
def _getOrigName (distname):
version = _getVersion()
return "outwiker_{}+{}~{}.orig.tar".format (version[0], version[1], distname)
def _debclean():
"""
Clean build/<distversion> folder
"""
local ('rm -rf build/{}'.format (_getDebSourceDirName()))
def _source():
"""
Create a sources folder for building the deb package
"""
_debclean()
dirname = os.path.join ("build", _getDebSourceDirName())
os.mkdir (dirname)
local ("rsync -avz --exclude=.bzr --exclude=distrib --exclude=build --exclude=*.pyc --exclude=*.dll --exclude=*.exe * --exclude=src/.ropeproject --exclude=src/test --exclude=src/setup_win.py --exclude=src/setup_tests.py --exclude=src/profile.py --exclude=src/tests.py --exclude=src/Microsoft.VC90.CRT.manifest --exclude=src/profiles --exclude=src/tools --exclude=doc --exclude=plugins --exclude=profiles --exclude=test --exclude=_update_version_bzr.py --exclude=outwiker_setup.iss --exclude=updateversion --exclude=updateversion.py --exclude=debian_tmp {dirname}/".format (dirname=dirname))
def _orig (distname):
"""
Create an archive for "original" sources for building the deb package
distname - Ubuntu release name
"""
_source()
origname = _getOrigName(distname)
with lcd ("build"):
local ("tar -cvf {} {}".format (origname, _getDebSourceDirName()))
local ("gzip -f build/{}".format (origname))
def debsource():
"""
Create files for uploading in PPA (including sources)
"""
_debuild ("debuild -S -sa --source-option=--include-binaries --source-option=--auto-commit",
distribs)
def deb():
"""
Assemble the deb package
"""
_debuild ("debuild --source-option=--include-binaries --source-option=--auto-commit",
distribs)
def debsingle():
"""
Assemble the deb package for the first Ubuntu release in the distribs list
"""
_debuild ("debuild --source-option=--include-binaries --source-option=--auto-commit",
[distribs[0]])
def _debuild (command, distriblist):
"""
Run command with debuild. The function assembles the deb packages for all releases in distriblist.
"""
for distname in distriblist:
# Change release name in the changelog file
_makechangelog (distribs[0], distname)
_orig(distname)
with lcd ("build/{}/debian".format (_getDebSourceDirName())):
local (command)
# Return the source release name
_makechangelog (distname, distribs[0])
def ppaunstable ():
"""
Upload the current OutWiker version in PPA (unstable)
"""
version = _getVersion()
for distname in distribs:
with lcd ("build".format (_getDebSourceDirName())):
local ("dput ppa:outwiker-team/unstable outwiker_{}+{}~{}_source.changes".format (version[0], version[1], distname))
def plugins():
"""
Create an archive with plugins (7z required)
"""
_remove (u"build/plugins/outwiker-plugins-all.zip")
for plugin in plugins_list:
_remove (u"build/plugins/{}.zip".format (plugin))
with lcd ("plugins/{}".format (plugin)):
local ("7z a -r -aoa -xr!*.pyc -xr!.ropeproject ../../build/plugins/{}.zip ./*".format (plugin))
local ("7z a -r -aoa -xr!*.pyc -xr!.ropeproject -w../ ../../build/plugins/outwiker-plugins-all.zip ./*".format (plugin))
def source ():
"""
Create the sources archives.
"""
version = _getVersion()
sourcesdir = os.path.join ("build", "sources")
if not os.path.exists (sourcesdir):
os.mkdir (sourcesdir)
fullfname = u"outwiker-src-full.zip"
srcfname = u"outwiker-src-min.zip"
_remove (fullfname)
_remove (srcfname)
local ('git archive --prefix=outwiker-{}.{}/ -o "{}/{}" HEAD'.format (version[0], version[1], sourcesdir, fullfname))
with lcd ("src"):
local ("7z a -r -aoa -xr!*.pyc -xr!.ropeproject -xr!tests.py -xr!profile.py -xr!setup_tests.py -xr!setup_win.py -xr!test -xr!profiles ../{}/{} ./*".format (sourcesdir, srcfname))
def win (skipinstaller=False):
"""
Assemble builds under Windows
"""
build_dir = u'build'
src_pluginsdir = u"plugins"
pluginsdir = os.path.join ("src", "plugins")
win_build_dir = os.path.join (build_dir, u"outwiker_win")
build_pluginsdir = os.path.join (win_build_dir, u'plugins')
# Create the plugins folder (it is not appened to the git repository)
_remove (pluginsdir)
os.mkdir (pluginsdir)
# Build by cx_Freeze
with lcd ("src"):
local ("python setup_win.py build")
_remove (build_pluginsdir)
os.mkdir (build_pluginsdir)
# Remove old versions
_remove ("build/outwiker_win_unstable.zip")
_remove ("build/outwiker_win_unstable.7z")
# Create archive without plugins
with lcd (win_build_dir):
local ("7z a ..\outwiker_win_unstable.zip .\* .\plugins -r -aoa")
local ("7z a ..\outwiker_win_unstable.7z .\* .\plugins -r -aoa")
# Compile installer
if not skipinstaller:
local ("iscc outwiker_setup.iss")
# Copy plugins to build folder
for plugin in plugins_list:
shutil.copytree (
os.path.join (src_pluginsdir, plugin, plugin),
os.path.join (build_pluginsdir, plugin),
)
# Archive versions with plugins
with lcd (win_build_dir):
local ("7z a ..\outwiker_win_unstable_all_plugins.zip .\* .\plugins -r -aoa -xr!*.pyc -xr!.ropeproject")
local ("7z a ..\outwiker_win_unstable_all_plugins.7z .\* .\plugins -r -aoa -xr!*.pyc -xr!.ropeproject")
def linux ():
"""
Assemble builds under Windows
"""
build_dir = u'build'
pluginsdir = os.path.join ("src", "plugins")
linux_build_dir = os.path.join (build_dir, u"outwiker_linux")
build_pluginsdir = os.path.join (linux_build_dir, u'plugins')
toRemove = [
os.path.join (linux_build_dir, u'tcl'),
os.path.join (linux_build_dir, u'tk'),
os.path.join (linux_build_dir, u'PyQt4.QtCore.so'),
os.path.join (linux_build_dir, u'PyQt4.QtGui.so'),
os.path.join (linux_build_dir, u'_tkinter.so'),
]
# Create the plugins folder (it is not appened to the git repository)
_remove (pluginsdir)
os.mkdir (pluginsdir)
# Build by cx_Freeze
with lcd ("src"):
local ("python setup_linux.py build")
map (_remove, toRemove)
_remove (build_pluginsdir)
os.mkdir (build_pluginsdir)
# Remove old versions
_remove ("build/outwiker_linux_unstable_x64.7z")
# Create archive without plugins
with lcd (linux_build_dir):
local ("7z a ../outwiker_linux_unstable_x64.7z ./* ./plugins -r -aoa")
def nextversion():
"""
Increment a version number (execute under Linux only, incremented the deb package version also)
"""
# The file with version number
fname = u"src/version.txt"
with open (fname) as fp_in:
lines = fp_in.readlines()
lines[1] = str (int (lines[1]) + 1) + "\n"
result = u"".join (lines)
with open (fname, "w") as fp_out:
fp_out.write (result)
local ('dch -v "{}+{}~{}"'.format (lines[0].strip(), lines[1].strip(), distribs[0]))
def debinstall():
"""
Assemble the first deb package in distribs and install it.
"""
debsingle()
version = _getVersion()
with lcd ("build"):
local ("sudo dpkg -i outwiker_{}+{}~{}_all.deb".format (version[0], version[1], distribs[0]))
def locale():
"""
Update the localization file (outwiker.pot)
"""
with lcd ("src"):
local (r'find . -iname "*.py" | xargs xgettext -o locale/outwiker.pot')
def localeplugin (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))
def run ():
"""
Run OutWiker from sources
"""
with lcd ("src"):
local ("python runoutwiker.py")
def test (section=u'', params=u''):
"""
Run the unit tests
"""
testdir = u'src'
files = [fname[len(testdir) + 1:]
for fname
in glob.glob (u'{}/tests_*.py'.format (testdir))]
files.sort()
with lcd ("src"):
if section:
local ("python tests_{}.py {}".format (section, params))
else:
with settings (warn_only=True):
for fname in files:
local ("python {}".format (fname, params))
def _makechangelog (distrib_src, distrib_new):
"""
Update the changelog file for current Ubuntu release.
"""
fname = "debian/changelog"
with open (fname) as fp:
lines = fp.readlines()
lines[0] = lines[0].replace (distrib_src, distrib_new)
with open (fname, "w") as fp:
fp.write (u"".join (lines))
def _remove (path):
"""
Remove the fname file if it exists. The function not catch exceptions.
"""
if os.path.exists (path):
if os.path.isfile (path):
os.remove (path)
elif os.path.isdir (path):
shutil.rmtree (path)