-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake_modules_json.py
More file actions
79 lines (54 loc) · 2.04 KB
/
Copy pathmake_modules_json.py
File metadata and controls
79 lines (54 loc) · 2.04 KB
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
#!python3
'''Read property files and save into 1 json file.'''
import glob, json, os, re
import common
def properties_to_json(src):
r'''Read properties from src directory.'''
# Get a list of property files.
files = []
if os.path.isfile(os.path.join(src, 'SciTEGlobal.properties')):
files.append('SciTEGlobal.properties')
for path in glob.iglob(os.path.join(src, '*.properties')):
file = os.path.basename(path)
if file in ('abbrev.properties',
'Embedded.properties',
'SciTE.properties',
'SciTEGlobal.properties'):
continue
files.append(file)
# Prepare the dictionary.
dic = {'version': '', 'module': {}}
# Get the editor version.
version = common.scite_version('.')
if not version:
version = input('Enter editor version: ')
if version:
dic['version'] = version.replace(',', '.')
# Create the json file.
for file in files:
with open(os.path.join(src, file)) as r:
module = os.path.splitext(file)[0]
content = r.read().replace('\t', ' ' * 4).strip('\n') + '\n'
content = re.sub(r'\n{3,}', r'\n\n', content)
dic['module'][module] = content
with open('modules.json', 'w') as w:
json.dump(dic, w, indent=4)
return dic
if __name__ == '__main__':
# Set output path.
output = common.settings['output']
if not os.path.isdir(output):
os.makedirs(output)
# Get initial directory, then change directory to output.
initial_dir = os.getcwd()
os.chdir(output)
# Read properties and create json file.
for item in (('modified', os.path.join(output, 'external_properties')),
('default', os.path.join(initial_dir, 'scite', 'src'))):
if os.path.isdir(item[1]):
print('read files from', item[0], 'dir')
properties_to_json(item[1])
break
if os.path.isfile('modules.json'):
print('output:\n modules.json')
print('done')