101 lines
3.8 KiB
Python
101 lines
3.8 KiB
Python
# Call this manually every time the metadata in pkg/credits changes.
|
|
# Commit the generated files.
|
|
|
|
# Requires:
|
|
# - ImageMagick
|
|
# - Git Bash (on Windows)
|
|
|
|
# Usage: python pkg/generate-credits.py
|
|
|
|
from glob import glob
|
|
from os.path import basename, splitext
|
|
from subprocess import run
|
|
|
|
def get_confirmed_names(filename):
|
|
with open(filename, 'r') as file:
|
|
lines = [line.rstrip() for line in file]
|
|
# The first line should always be Confirmed:
|
|
lines = lines[1:]
|
|
# After the confirmed names, there may be Not Confirmed: names.
|
|
if 'Not Confirmed:' in lines:
|
|
lines = lines[0:lines.index('Not Confirmed:')]
|
|
return [line.replace('- ', '') for line in lines if len(line) > 0]
|
|
|
|
def main():
|
|
# Generate about-boe.xml from about-boe-template.xml:
|
|
with open('pkg/credits/about-boe-template.xml', 'r') as template_file:
|
|
template = template_file.read()
|
|
content = template
|
|
|
|
name_files = glob('pkg/credits/*.txt')
|
|
name_dict = {}
|
|
num_dict = {}
|
|
total_num = 0
|
|
for name_file in name_files:
|
|
heading, _ = splitext(basename(name_file))
|
|
name_dict[heading] = get_confirmed_names(name_file)
|
|
num_dict[heading] = len(name_dict[heading])
|
|
total_num += len(name_dict[heading])
|
|
|
|
def replace_tabbed_lines(placeholder, lines, tabs):
|
|
return content.replace(placeholder, ('\n' + ('\t' * tabs)).join(lines.splitlines()))
|
|
|
|
# {{Warning}}:
|
|
content = replace_tabbed_lines('{{Warning}}', 'WARNING! This file is generated by pkg/generate-credits.py from\ntpkg/credits/about-boe-template.xml. Do not modify it manually!', 1)
|
|
|
|
# {{Height}}: 10 * (total # of lines, which includes 2 at the top and 4 per section break)
|
|
content = content.replace('{{Height}}', str(10 * (total_num + 10)))
|
|
|
|
# {{0}}: '<br/>' * (total # of confirmed names in pkg/credits/*.txt)
|
|
content = content.replace('{{0}}', '<br/>' * total_num)
|
|
|
|
# {{1}}: '<br/>' * (# of programmers)
|
|
content = content.replace('{{1}}', '<br/>' * num_dict['Programming'])
|
|
|
|
# {{2}}: '<br/>' * (# of artists)
|
|
content = content.replace('{{2}}', '<br/>' * num_dict['Graphics'])
|
|
|
|
# {{3}}: '<br/>' * (# of testers)
|
|
content = content.replace('{{3}}', '<br/>' * num_dict['Testing'])
|
|
|
|
# {{4}}: '<br/>' * (# of donors)
|
|
content = content.replace('{{4}}', '<br/>' * num_dict['Funding'])
|
|
|
|
list_break = ' <br/>\n'
|
|
|
|
# {{5}}: Programmer name lines
|
|
name_lines = list_break.join(name_dict["Programming"]) + list_break
|
|
content = replace_tabbed_lines('{{5}}', name_lines, 8)
|
|
|
|
# {{6}}: Artist name lines
|
|
name_lines = list_break.join(name_dict["Graphics"]) + list_break
|
|
content = replace_tabbed_lines('{{6}}', name_lines, 7)
|
|
|
|
# {{7}}: Tester name lines
|
|
name_lines = list_break.join(name_dict["Testing"]) + list_break
|
|
content = replace_tabbed_lines('{{7}}', name_lines, 12)
|
|
|
|
# {{8}}: Donor names
|
|
name_lines = list_break.join(name_dict["Funding"]) + list_break
|
|
content = replace_tabbed_lines('{{8}}', name_lines, 7)
|
|
|
|
with open('rsrc/dialogs/about-boe.xml', 'w') as output_file:
|
|
output_file.write(content)
|
|
|
|
# Generate startanim.png using ImageMagick
|
|
image_lines = ['* OPEN SOURCE CREDITS *', ' ', ' ']
|
|
def add_heading(heading):
|
|
image_lines.append(f'- {heading.upper()} -')
|
|
image_lines.extend(" ")
|
|
image_lines.extend(name_dict[heading])
|
|
image_lines.extend(" ")
|
|
|
|
add_heading('Programming')
|
|
add_heading('Graphics')
|
|
add_heading('Testing')
|
|
add_heading('Funding')
|
|
|
|
run(['bash', 'pkg/generate-startanim.sh'], input='\n'.join(image_lines), encoding='ascii')
|
|
|
|
if __name__ == "__main__":
|
|
main() |