-
Notifications
You must be signed in to change notification settings - Fork 2
/
licenseProcessor.py
executable file
·52 lines (47 loc) · 1.54 KB
/
licenseProcessor.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
includes = 'includedLicenses.txt'
extra_includes = {
'includedLicensesPlusAspose.txt': ['Aspose EULA'],
'includedLicensesPlusNashorn.txt': ['GPL-2.0-only (from Nashorn)']
}
merges = 'licenseMerges.txt'
overrides = 'override-THIRD-PARTY.properties'
# Sort the includes file.
with open(includes) as f:
includes_lines = f.readlines()
with open(includes, 'w') as f:
includes_lines = sorted(includes_lines, key=str.casefold)
for line in includes_lines:
line = line.strip()
if line:
f.write(line + '\n')
# Generate extra includes files based on the original.
for extra_file, extra_licenses in extra_includes.items():
with open(extra_file, 'w') as f:
extra_file_lines = sorted(includes_lines + extra_licenses, key=str.casefold)
for line in extra_file_lines:
line = line.strip()
if line:
f.write(line + '\n')
# Sort the merges file.
with open(merges) as f:
lines = f.readlines()
with open(merges, 'w') as f:
lines = sorted(lines, key=lambda line: str.casefold(line.split('|')[0]))
for line in lines:
line = line.strip()
if line:
licenses = line.split('|')
licenses = licenses[:1] + sorted(licenses[1:], key=str.casefold)
f.write('|'.join(licenses) + '\n')
# Sort the overrides file.
with open(overrides) as f:
lines = f.readlines()
lines = list(filter(lambda line: line.strip(), lines))
pairs = zip(lines[::2], lines[1::2])
with open(overrides, 'w') as f:
pairs = sorted(pairs, key=lambda pair: str.casefold(pair[1]))
for pair in pairs:
for line in pair:
f.write(line.strip() + '\n')