]> dreyeck.freedombox.rocks Git - topic-maps.git/blob - vendor/cxtm/release.py
docs: design draft for a read-only SHOP3 adapter over TMDM objects
[topic-maps.git] / vendor / cxtm / release.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 #
5 # Script to make a CXTM test suite release.
6 #
7 # It creates a tar.gz distribution and updates the HTML page
8 #
9 import re
10 import glob
11 import os
12 from datetime import date
13 from string import Template
14 import tarfile
15
16 RELEASE_VERSION = 0.5
17
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'
21
22 def get_directory_names():
23 """\
24 Returns the subdirectory names, '.svn' and 'web' excluded
25 """
26 return [n for n in os.listdir('.') if n not in ('.svn', 'web', _DIST_DIRNAME) and os.path.isdir(os.path.join('.', n))]
27
28 _LAST_CHANGES_PATTERN = re.compile(r'(\*.+?)(?:\n\n)', re.DOTALL|re.MULTILINE)
29
30 def generate_index_and_mail():
31 """\
32 Creates the index.html.
33 """
34 def update_test_count(dct, key, path):
35 if key != 'tmcl':
36 dct[key+'_valid'] = test_case_count(os.path.join(path, 'baseline'))
37 dct[key+'_invalid'] = test_case_count(os.path.join(path, 'invalid'))
38 else:
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))
47 # Special cases
48 if dirname == 'rdf':
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']
63 total_valid = 0
64 total_invalid = 0
65 for k,v in dct.iteritems():
66 if '_invalid' in k:
67 total_invalid+=v
68 elif '_valid' in k:
69 total_valid+=v
70 dct['total_valid'] = total_valid
71 dct['total_invalid'] = total_invalid
72 # Template
73 tpl = Template(open('./web/index.html').read())
74 # Generated page
75 index_page = open('./%s/index.html' % _DIST_DIRNAME, 'wb')
76 index_page.write(tpl.substitute(dct))
77 index_page.close()
78 # Generate e-mail
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))
84 mail.close()
85
86 def generate_dist():
87 """\
88 Generates the distribution file.
89 """
90 def exclude_file(fn):
91 return '.svn' in fn or fn.endswith('.bak')
92 name = 'cxtm-tests-' + str(RELEASE_VERSION)
93 base_dir = name+'/'
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)
100 tar.close()
101
102
103 if __name__ == '__main__':
104 import sys
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)
109 generate_dist()
110 generate_index_and_mail()