-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_scite_api_files_3.py
72 lines (51 loc) · 2.1 KB
/
make_scite_api_files_3.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
#!python3
'''Make scitestyles.api file from SciTEGlobal.properties and others.properties.'''
import os, re
import common
settings = common.settings
# Access which SciTEGlobal.properties and others.properties.
# True=From modified files, False=From scite\src files.
settings['use_output_files'] = False
if __name__ == '__main__':
# Set output path.
output = settings['output']
if not os.path.isdir(output):
os.makedirs(output)
# Set paths of SciTEGlobal.properties and others.properties.
if settings['use_output_files']:
global_file = os.path.join(output, 'external_properties', 'SciTEGlobal.properties')
others_file = os.path.join(output, 'external_properties', 'others.properties')
else:
global_file = ''
others_file = ''
if not os.path.isfile(global_file) or not os.path.isfile(others_file):
print('read from the source files')
global_file = os.path.join('scite', 'src', 'SciTEGlobal.properties')
others_file = os.path.join('scite', 'src', 'others.properties')
else:
print('read from the output files')
# Exclude these known property names.
exclude = ['font.locale', 'font.monospace', 'font.monospaced.list',
'font.override', 'font.quality']
# Get property names.
scitestyles = set()
for file in (global_file, others_file):
with open(file) as r:
content = r.read()
matches = re.findall(r'^\s*((?:colour|font)\..+?)=', content, re.M)
if matches:
for item in matches:
if item not in exclude:
scitestyles.add(item)
scitestyles = sorted(scitestyles)
print('output:')
# Write to scitestyles.api.
if scitestyles:
print(' scitestyles.api')
with open(os.path.join(output, 'scitestyles.api'), 'w', encoding='utf-8') as w:
for item in scitestyles:
if item.startswith('colour.'):
w.write(item + ' (-) [style]\\n Colour style.\n')
else:
w.write(item + ' (-) [style]\\n Font style.\n')
print('done')