Debian Codegraph @

Scripts/release.py

raw
1 """
2 requires Python Image Library - http://www.pythonware.com/products/pil/
3 requires grep and diff - http://www.mingw.org/msys.shtml
4 requires command line svn - http://subversion.tigris.org/
5 requires pysvn - http://pysvn.tigris.org/
6 requires win32com - http://starship.python.net/~skippy/win32/Downloads.html
7 requires requests - https://requests.readthedocs.io/en/latest/
8
9 example release.cfg:
10 =========================
11 [auth]
12 USER=kichik
13 WIKI_PASSWORD=xxx
14
15 [version]
16 VERSION=2.10
17 VER_MAJOR=2
18 VER_MINOR=1
19 VER_REVISION=0
20 VER_BUILD=0
21
22 [svn]
23 SVN="C:\svn-win32\bin\svn.exe"
24 SVNROOT=https://svn.code.sf.net/p/nsis/code/NSIS
25
26 [compression]
27 TAR_BZ2=7zatarbz2.bat %s %s
28 ZIP="C:\Program Files\7-zip\7za.exe" a -tzip %s -mx9 -mfb=255 -mpass=4 %s
29
30 [rsh]
31 RSH="C:\Program Files\PuTTY\plink.exe" -2 -l kichik nsis.sourceforge.net
32
33 [sftp]
34 SFTP="C:\Program Files\PuTTY\psftp.exe" -2 -l kichik,nsis -batch -b %s frs.sourceforge.net
35
36 [wiki]
37 PURGE_URL=https://nsis.sourceforge.io/%s?action=purge
38 UPDATE_URL=https://nsis.sourceforge.io/Special:Simpleupdate?action=raw
39
40 [svn2cl]
41 SVN2CL_XSL=svn2cl.xsl
42
43 [options]
44 SKIP_CPPUNIT=no
45 SCONS_ARGS="TOOLSET=msvc,mssdk,mslink,mslib,masm"
46 =========================
47
48 7zatarbz2.bat:
49 =========================
50 @echo off
51 "C:\Program Files\7-zip\7za.exe" a -ttar %2.tar -r %2
52 "C:\Program Files\7-zip\7za.exe" a -tbzip2 %1 -mx9 -mpass=7 %2.tar
53 =========================
54
55 TODO
56 ~~~~
57
58 * Create release on SourceForge automatically
59 * Edit update.php
60 * http://en.wikipedia.org/w/index.php?title=Nullsoft_Scriptable_Install_System&action=edit
61 * Update Freshmeat
62 * Update BetaNews
63
64 """
65
66 import os
67 import os.path
68 import shutil
69 import sys
70 import time
71 from PIL import Image, ImageFont, ImageDraw
72 from configparser import RawConfigParser
73 import time
74 import pysvn
75 import requests
76 import urllib.parse
77
78 ### read config
79
80 if not os.path.isfile('release.cfg'):
81 print('Unable to find release.cfg. Is this the right working directory?')
82 sys.exit(1)
83
84 cfg = RawConfigParser()
85 cfg.read('release.cfg')
86
87 USER = cfg.get('auth', 'USER')
88 WIKI_PASSWORD = cfg.get('auth', 'WIKI_PASSWORD')
89
90 VERSION = cfg.get('version', 'VERSION')
91 VER_MAJOR = cfg.get('version', 'VER_MAJOR')
92 VER_MINOR = cfg.get('version', 'VER_MINOR')
93 VER_REVISION = cfg.get('version', 'VER_REVISION')
94 VER_BUILD = cfg.get('version', 'VER_BUILD')
95
96 PRE_RELEASE_VERSION = 'a' in VERSION or 'b' in VERSION
97
98 SVN = cfg.get('svn', 'SVN')
99 SVNROOT = cfg.get('svn', 'SVNROOT')
100
101 TAR_BZ2 = cfg.get('compression', 'TAR_BZ2')
102 ZIP = cfg.get('compression', 'ZIP')
103
104 RSH = cfg.get('rsh', 'RSH')
105
106 SFTP = cfg.get('sftp', 'SFTP')
107
108 PURGE_URL = cfg.get('wiki', 'PURGE_URL')
109 UPDATE_URL = cfg.get('wiki', 'UPDATE_URL')
110
111 SVN2CL_XSL = cfg.get('svn2cl', 'SVN2CL_XSL')
112
113 SKIP_CPPUINT = cfg.get('options', 'SKIP_CPPUNIT')
114
115 SCONS_ARGS = cfg.get('options', 'SCONS_ARGS')
116
117 ### config env
118
119 SVN_TAG = 'v' + ''.join(VERSION.split('.'))
120
121 SOURCE_DATE_EPOCH = str(int(time.time()))
122 SCONS_REPRODUCIBLE_ARGS = 'SOURCE_DATE_EPOCH=%s' % (SOURCE_DATE_EPOCH)
123
124 newverdir = 'nsis-%s-src' % VERSION
125 scons_line = 'scons %s %s -C %s VERSION=%s VER_MAJOR=%s VER_MINOR=%s VER_REVISION=%s VER_BUILD=%s ' \
126 % (SCONS_ARGS, SCONS_REPRODUCIBLE_ARGS, newverdir, \
127 VERSION, VER_MAJOR, VER_MINOR, VER_REVISION, VER_BUILD)
128
129 ### utility functions
130
131 def log(msg, log_dir = '.'):
132 open('%s\\release-%s.log' % (log_dir, VERSION), 'a').write(msg + '\n')
133
134 def exit(log_dir = '.'):
135 log('\nerror occurred, exiting', log_dir)
136 sys.exit(3)
137
138 LOG_ERRORS = 2
139 LOG_ALL = 1
140 LOG_NOTHING = 0
141
142 def run(command, log_level, err, wanted_ret = 0, log_dir = '.'):
143 log('\nrunning %s\n' % command, log_dir)
144
145 if log_level == LOG_ERRORS:
146 cmd = '%s 2>> %s\\release-%s.log' % (command, log_dir, VERSION)
147 elif log_level == LOG_ALL:
148 cmd = '%s >> %s\\release-%s.log 2>&1' % (command, log_dir, VERSION)
149 elif log_level == LOG_NOTHING:
150 cmd = command
151 else:
152 raise ValueError
153
154 ret = os.system('if 1==1 ' + cmd)
155
156 # sleep because for some weird reason, running cvs.exe hugs
157 # the release log for some time after os.system returns
158 # still needed for svn?
159 import time
160 time.sleep(5)
161
162 if ret != wanted_ret:
163 print('*** ' + err)
164 log('*** ' + err, log_dir)
165 exit(log_dir)
166
167 def confirm(question):
168 print(question)
169 if input() != 'y':
170 sys.exit(2)
171
172 ### process functions
173
174 def Confirm():
175 confirm('are you sure you want to release version %s?' % VERSION)
176 confirm('did you update history.but?')
177
178 def StartLog():
179 open('release-%s.log' % VERSION, 'w').write('releasing version %s at %s\n\n' % (VERSION, time.ctime()))
180
181 def DeleteOldFolders():
182 for d in ['strlen_8192', 'log', 'insttest', 'insttestscons']:
183 if os.path.isdir(d):
184 log('Deleting %s' % d)
185 shutil.rmtree(d)
186
187 def RunTests():
188 print('running tests...')
189
190 run(
191 'scons %s -C .. %s' % (SCONS_ARGS, SKIP_CPPUINT == 'yes' and 'test-scripts' or 'test'),
192 LOG_ALL,
193 'tests failed - see test.log for details'
194 )
195
196 def TestSubversionEOL():
197 print('ensuring EOL...')
198
199 from os import walk
200 from os.path import join
201 from os.path import splitext
202
203 eoldict = {
204 '.nsh' : 'native',
205 '.nsi' : 'native',
206 '.txt' : 'native',
207 '.ini' : 'CRLF',
208 '.dsp' : 'CRLF',
209 '.dsw' : 'CRLF'
210 }
211
212 exceptions = ['newfile.txt', 'oldfile.txt']
213
214 svn = pysvn.Client()
215
216 bad_eol = False
217 for root, dirs, files in walk('..'):
218 def versioned(f):
219 try:
220 s = svn.status(join(root, f))[0].text_status
221 except pysvn.ClientError as e:
222 if 'not a working copy' in e.args[0]:
223 return False
224 if 'was not found' in e.args[0]:
225 return False
226 raise
227 return s != pysvn.wc_status_kind.unversioned
228
229 svn_files = filter(versioned, files)
230 svn_files = filter(lambda x: x not in exceptions, svn_files)
231
232 for f in svn_files:
233 ext = splitext(f)[1]
234 if ext in eoldict.keys():
235 eol = eoldict[ext]
236 path = join(root, f)
237 s = list(svn.propget('svn:eol-style', path).values())
238 if not s or s[0] != eol:
239 error = f'*** {path} has bad eol-style (expected "{eol}", got "{s}")'
240 print(error)
241 log(error)
242 bad_eol = True
243
244 if bad_eol:
245 exit()
246
247 def CreateMenuImage():
248 print('creating images...')
249
250 ## create new header.gif for menu
251
252 im = Image.new('RGB', (598, 45), '#000000')
253
254 # copy background from header-notext.gif
255
256 bim = Image.open(r'..\Menu\images\header-notext.gif')
257 im.paste(bim)
258
259 # draw new version number
260
261 draw = ImageDraw.Draw(im)
262 font = ImageFont.truetype('trebuc.ttf', 24)
263 text = 'nullsoft scriptable install system %s' % VERSION
264 draw.text((85, 7), text, font = font, fill = 'white')
265
266 # save
267
268 im = im.convert('P', palette = Image.ADAPTIVE)
269 im.save(r'..\Menu\images\header.gif')
270
271 def CommitMenuImage():
272 print('committing header.gif...')
273
274 run(
275 '%s commit -m %s ..\\Menu\\images\\header.gif' % (SVN, VERSION),
276 LOG_ALL,
277 'failed committing header.gif'
278 )
279
280 def TestInstaller():
281 print('testing installer...')
282
283 os.mkdir('insttestscons')
284
285 run(
286 'scons %s -C .. VERSION=test PREFIX=%s\\insttestscons install dist-installer' % (SCONS_ARGS, os.getcwd()),
287 LOG_ALL,
288 'installer creation failed'
289 )
290
291 run(
292 '..\\nsis-test-setup.exe /S /D=%s\\insttest' % os.getcwd(),
293 LOG_NOTHING,
294 'installer failed'
295 )
296
297 run(
298 'diff -r insttest insttestscons | grep -v uninst-nsis.exe | grep -v NSIS.exe',
299 LOG_ALL,
300 'scons and installer installations differ',
301 1
302 )
303
304 def Tag():
305 print('tagging...')
306
307 run(
308 '%s copy %s/trunk %s/tags/%s -m "Tagging for release %s"' % (SVN, SVNROOT, SVNROOT, SVN_TAG, VERSION),
309 LOG_ALL,
310 'failed creating tag %s' % SVN_TAG
311 )
312
313 def Export():
314 print('exporting a fresh copy...')
315
316 run(
317 '%s export %s/tags/%s %s' % (SVN, SVNROOT, SVN_TAG, newverdir),
318 LOG_ALL,
319 'export failed'
320 )
321
322 def CreateChangeLog():
323 import win32com.client
324 import codecs
325
326 if not os.path.isfile(SVN2CL_XSL):
327 print('downloading svn2cl.xsl stylesheet...')
328 r = requests.get('http://svn.apache.org/repos/asf/subversion/trunk/contrib/client-side/svn2cl/svn2cl.xsl')
329 r.raise_for_status()
330 with open(SVN2CL_XSL, 'w') as f:
331 f.write(r.text)
332
333 print('generating ChangeLog...')
334
335 changelog = os.path.join(newverdir, 'ChangeLog')
336
337 # generate changelog xml
338 run(
339 '%s log --xml --verbose %s > %s' % (SVN, SVNROOT, changelog),
340 LOG_ERRORS,
341 'changelog failed'
342 )
343
344 # load changelog xml
345 xmlo = win32com.client.Dispatch('Microsoft.XMLDOM')
346 xmlo.loadXML(open(changelog).read())
347 xmlo.preserveWhiteSpace = True
348
349 # load xsl
350 xslo = win32com.client.Dispatch('Microsoft.XMLDOM')
351 xslo.validateOnParse = False
352 xslo.preserveWhiteSpace = True
353 xslo.loadXML(open(SVN2CL_XSL).read())
354
355 # set strip-prefix to ''
356 for a in xslo.selectNodes("/xsl:stylesheet/xsl:param[@name = 'strip-prefix']")[0].attributes:
357 if a.name == 'select':
358 a.value = "''"
359
360 # transform
361 transformed = xmlo.transformNode(xslo)
362 codecs.open(changelog, 'w', 'utf-8').write(transformed)
363
364 def CreateSourceTarball():
365 print('creating source tarball...')
366
367 run(
368 TAR_BZ2 % (newverdir + '.tar.bz2', newverdir),
369 LOG_ALL,
370 'source tarball creation failed'
371 )
372
373 def BuildRelease():
374 print('creating distribution files...')
375
376 run(
377 scons_line + 'dist',
378 LOG_ALL,
379 'creation of distribution files failed'
380 )
381
382 def CreateSpecialBuilds():
383 def create_special_build(name, option):
384 print('creating %s special build...' % name)
385
386 os.mkdir(name)
387
388 run(
389 scons_line + 'PREFIX=%s\\%s %s install-compiler install-stubs' % (os.getcwd(), name, option),
390 LOG_ALL,
391 'creation of %s special build failed' % name
392 )
393
394 os.chdir(name)
395 run(
396 ZIP % ('..\\nsis-%s-%s.zip' % (VERSION, name), '*'),
397 LOG_ALL,
398 'compression of %s special build failed' % name,
399 log_dir = '..'
400 )
401 os.chdir('..')
402
403 create_special_build('strlen_8192', 'NSIS_MAX_STRLEN=8192')
404 create_special_build('log', 'NSIS_CONFIG_LOG=yes')
405
406 def UploadFiles():
407 print('uploading files to SourceForge...')
408
409 folder = 'NSIS 3/' + VERSION
410 if PRE_RELEASE_VERSION:
411 folder = 'NSIS 3 Pre-release/' + VERSION
412
413 sftpcmds = open('sftp-commands', 'w')
414 sftpcmds.write('mkdir "/home/frs/project/nsis/%s"\n' % folder)
415 sftpcmds.write('cd "/home/frs/project/nsis/%s"\n' % folder)
416 sftpcmds.write('put %s.tar.bz2\n' % newverdir)
417 sftpcmds.write('put %s\\nsis-%s-setup.exe\n' % (newverdir, VERSION))
418 sftpcmds.write('put %s\\nsis-%s.zip\n' % (newverdir, VERSION))
419 sftpcmds.write('put nsis-%s-log.zip\n' % VERSION)
420 sftpcmds.write('put nsis-%s-strlen_8192.zip\n' % VERSION)
421 sftpcmds.write('put %s\\build\\urelease\\Docs\\chm\\SectionF.1.html RELEASE.html\n' % newverdir)
422 sftpcmds.close()
423
424 run(
425 SFTP % 'sftp-commands',
426 LOG_ERRORS,
427 'upload failed'
428 )
429
430 os.unlink('sftp-commands')
431
432 def ManualRelease():
433 print('go fix release notes...')
434 print(' http://nsis.sf.net/rn/new')
435 print()
436
437 input()
438
439 def UpdateWiki():
440 print('updating wiki...')
441
442 def update_wiki_page(page, data, summary):
443 print(' updating `%s` to `%s`' % (page, data))
444
445 import urllib
446
447 post = 'su_user=' + urllib.parse.quote(USER)
448 post += '&su_password=' + urllib.parse.quote(WIKI_PASSWORD)
449 post += '&su_title=' + urllib.parse.quote(page)
450 post += '&su_data=' + urllib.parse.quote(data)
451 post += '&su_summary=' + urllib.parse.quote(summary)
452
453 if requests.get(UPDATE_URL, post).text.strip() != 'success':
454 log('*** failed updating `%s` wiki page' % page)
455 print(' *** failed updating `%s` wiki page' % page)
456
457 if not PRE_RELEASE_VERSION:
458 update_wiki_page('Template:NSISVersion', VERSION, 'new version')
459 update_wiki_page('Template:NSISReleaseDate', time.strftime('%B %d, %Y'), 'new version')
460 update_wiki_page('Template:NSISIsPreRelease', 'no', 'new version')
461 else:
462 update_wiki_page('Template:NSISPreVersion', VERSION, 'new version')
463 update_wiki_page('Template:NSISPreReleaseDate', time.strftime('%B %d, %Y'), 'new version')
464 update_wiki_page('Template:NSISIsPreRelease', 'yes', 'new version')
465
466 os.system('start ' + PURGE_URL % 'Download')
467
468 def ToDo():
469 print('automatic phase done\n')
470 print("""
471 * Make new release files the default download
472 * Edit update.php
473 * Post news item
474 * http://en.wikipedia.org/w/index.php?title=Nullsoft_Scriptable_Install_System&action=edit
475 * Update Freshmeat
476 * Update BetaNews
477 """)
478
479 def CloseLog():
480 log('done')
481
482 ### ok, let's go!
483
484 Confirm()
485 StartLog()
486 DeleteOldFolders()
487 RunTests()
488 TestSubversionEOL()
489 CreateMenuImage()
490 CommitMenuImage()
491 TestInstaller()
492 Tag()
493 Export()
494 CreateChangeLog()
495 CreateSourceTarball()
496 BuildRelease()
497 CreateSpecialBuilds()
498 UploadFiles()
499 ManualRelease()
500 UpdateWiki()
501 ToDo()
502 CloseLog()