forked from advancedfx/advancedfx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake_credits.py
More file actions
101 lines (82 loc) · 3.21 KB
/
make_credits.py
File metadata and controls
101 lines (82 loc) · 3.21 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env python
import sys
import os
import re
tpl_credits = '''# Credits
## Team
### Current
{team}
### Past
{team_past}
## Contributors
{contributors}
## Donors
Thanks to our donors:
* Open Collective
https://opencollective.com/advancedfx/
* GitHub
https://github.com/sponsors/advancedfx
(Money is sent to our OpenCollective account.)
## Additonal Credits
Additional credits are included with e.g. the main download in the readme.txt file [(or see version on github.com)](https://github.com/advancedfx/advancedfx/blob/master/misc/readme_head.txt).
'''
md_regex = re.compile(r'---(.*)---(.*)', re.DOTALL | re.MULTILINE)
md_props_regex = re.compile(r'^\s*([^\:]*)\s*\:\s*(.*)$', re.MULTILINE)
contrib_members_current = []
contrib_members_past = []
contrib_others = []
contrib_dir = os.fspath('deps/release/contrib')
md_filenames = list(filter(lambda x: x.endswith('.md'), os.listdir(contrib_dir)))
for md_filename in md_filenames:
with open(os.path.join(contrib_dir, md_filename), 'r') as md_file:
contrib = {}
md_content = md_file.read()
md_match = md_regex.match(md_content)
content_props, content_extra = md_match.groups((1,2))
content_props = content_props.strip('\r\n')
content_extra = content_extra.strip('\r\n')
if(0 < len(content_extra)):
contrib['content'] = content_extra
md_props_matches = md_props_regex.findall(content_props)
member = False
past = False
for match in md_props_matches:
prop_k = match[0].strip("\"")
prop_v = match[1].strip("\"")
contrib[prop_k] = prop_v
if 'member' == prop_k:
member = 'true' == prop_v
elif 'date_to' == prop_k and 0 < len(prop_v):
past = True
if member:
if past:
contrib_members_past.append(contrib)
else:
contrib_members_current.append(contrib)
else:
contrib_others.append(contrib)
def mk_members_string(members):
result = ''
for m in sorted(members, key=lambda item: (int(item.get('weight','0')), item.get('date_from',None), item.get('date_to', None))):
result += '\n'
result += '#### ' + m.get('name','') + '\n'
val = m.get('date_from', None)
if val is not None:
result += '\n' + val
val2 = m.get('date_to', None)
if val2 is not None:
result += ' - ' + val2
result += '\n'
val = m.get('contributions', None)
if val is not None:
result += '\n' + val + '\n'
val = m.get('content', None)
if val is not None:
result += '\n' + val.replace('\n', '\n'+' ') + '\n'
val = m.get('links', None)
if val is not None:
result += '\n' + val + '\n'
return result
credits_content = tpl_credits.format(team=mk_members_string(contrib_members_current),team_past=mk_members_string(contrib_members_past),contributors= mk_members_string(contrib_others))
with open('CREDITS.md', 'w') as f:
f.write(credits_content)