]>
dreyeck.freedombox.rocks Git - topic-maps.git/blob - vendor/cxtm/release.py
2 # -*- coding: utf-8 -*-
5 # Script to make a CXTM test suite release.
7 # It creates a tar.gz distribution and updates the HTML page
12 from datetime
import date
13 from string
import Template
18 # Name of the directory for the generated index.html and the dist file
19 # The directory will be created if it does not exist
20 _DIST_DIRNAME
= 'release'
22 def get_directory_names():
24 Returns the subdirectory names, '.svn' and 'web' excluded
26 return [n
for n
in os
.listdir('.') if n
not in ('.svn', 'web', _DIST_DIRNAME
) and os
.path
.isdir(os
.path
.join('.', n
))]
28 _LAST_CHANGES_PATTERN
= re
.compile(r
'(\*.+?)(?:\n\n)', re
.DOTALL|re
.MULTILINE
)
30 def generate_index_and_mail():
32 Creates the index.html.
34 def update_test_count(dct
, key
, path
):
36 dct
[key
+'_valid'] = test_case_count(os
.path
.join(path
, 'baseline'))
37 dct
[key
+'_invalid'] = test_case_count(os
.path
.join(path
, 'invalid'))
39 dct
[key
+'_valid'] = test_case_count(os
.path
.join(path
, 'valid'))
40 dct
[key
+'_invalid'] = test_case_count(os
.path
.join(path
, 'invalid')) + test_case_count(os
.path
.join(path
, 'bad-schema'))
41 def test_case_count(path
):
42 return len([n
for n
in glob
.glob(path
+ '/*.*') if not n
.endswith('.sub')])
43 dct
= {'release_version': RELEASE_VERSION
,
44 'release_date': date
.today().isoformat()}
45 for dirname
in get_directory_names():
46 update_test_count(dct
, dirname
, os
.path
.join('.', dirname
))
49 # CRTM tests are in a subdir of the RDF tests
50 update_test_count(dct
, 'crtm', os
.path
.join('.', dirname
, 'crtm'))
51 # The external mapping tests are in a subdir of the RDF tests
52 # Count them to the RDF tests
53 update_test_count(dct
, '__rdf', os
.path
.join('.', dirname
, 'externalmapping'))
54 dct
['rdf_valid'] += dct
.pop('__rdf_valid')
55 dct
['rdf_invalid'] += dct
.pop('__rdf_invalid')
56 elif dirname
== 'tmcl':
57 update_test_count(dct
, dirname
, os
.path
.join('.', dirname
, 'level-1'))
58 # Update the test count for XTM 2.1 and JTM 1.1 since XTM 2.1 requires XTM 2.0 and JTM 1.1 requires JTM 1.0
59 dct
['xtm21_valid'] += dct
['xtm2_valid']
60 dct
['xtm21_invalid'] += dct
['xtm2_invalid']
61 dct
['jtm11_valid'] += dct
['jtm_valid']
62 dct
['jtm11_invalid'] += dct
['jtm_invalid']
65 for k
,v
in dct
.iteritems():
70 dct
['total_valid'] = total_valid
71 dct
['total_invalid'] = total_invalid
73 tpl
= Template(open('./web/index.html').read())
75 index_page
= open('./%s/index.html' % _DIST_DIRNAME
, 'wb')
76 index_page
.write(tpl
.substitute(dct
))
79 mail_tpl
= Template(open('./web/mail.txt').read())
80 changes
= open('./CHANGES.txt').read()
81 dct
['changes'] = _LAST_CHANGES_PATTERN
.search(changes
).group(1)
82 mail
= open('./%s/mail.txt' % _DIST_DIRNAME
, 'wb')
83 mail
.write(mail_tpl
.substitute(dct
))
88 Generates the distribution file.
91 return '.svn' in fn
or fn
.endswith('.bak')
92 name
= 'cxtm-tests-' + str(RELEASE_VERSION
)
94 archive_name
= name
+ '.tar.gz'
95 tar
= tarfile
.open(archive_name
, fileobj
=open(_DIST_DIRNAME
+ '/' + archive_name
, 'wb'), mode
='w:gz')
96 for f
in 'README', 'CHANGES.txt', 'LICENSE.txt':
97 tar
.add(f
, arcname
=base_dir
+f
)
98 for d
in get_directory_names():
99 tar
.add(d
+ '/', arcname
=base_dir
+d
, exclude
=exclude_file
)
103 if __name__
== '__main__':
105 if sys
.hexversion
< 0x020600F0:
106 raise Exception('Requires Python >= 2.6')
107 if not os
.path
.isdir('./' + _DIST_DIRNAME
):
108 os
.mkdir('./' + _DIST_DIRNAME
)
110 generate_index_and_mail()