extended maintenance script

This commit is contained in:
Trilarion
2017-12-06 17:21:16 +01:00
parent 75c435a7ac
commit f793026a14
7 changed files with 101 additions and 56 deletions

View File

@ -11,12 +11,12 @@ See also the list of [popular games on Github](https://github.com/leereilly/game
## Contents ## Contents
- [Libraries](library/_toc.md) (19) - [Adventure games & Visual novels](adventure/_toc.md) (8)
- [Frameworks](framework/_toc.md) (44) - [Game frameworks](framework/_toc.md) (44)
- [Adventures & Visual Novels](adventure/_toc.md) (8) - [Popular required libraries](library/_toc.md) (19)
- [RPGs](rpg/_toc.md) (7) - [Role Playing Games](rpg/_toc.md) (7)
- [Simulation](simulation/_toc.md) (8) - [Simulation games](simulation/_toc.md) (8)
- [Strategy](strategy/_toc.md) (29) - [Strategy games](strategy/_toc.md) (29)
## Contributing ## Contributing

View File

@ -4,6 +4,7 @@
- [Blender game engine](blender_game_engine.md) - [Blender game engine](blender_game_engine.md)
- [COCOS2D-X](cocos2dx.md) - [COCOS2D-X](cocos2dx.md)
- [Dash Engine](dash.md) - [Dash Engine](dash.md)
- [Delta Engine](deltaengine.md)
- [ENIGMA](enigma.md) - [ENIGMA](enigma.md)
- [EasyRPG Player](easyrpgplayer.md) - [EasyRPG Player](easyrpgplayer.md)
- [Flare Engine](flare_engine.md) - [Flare Engine](flare_engine.md)
@ -40,5 +41,6 @@
- [libGDX](libgdx.md) - [libGDX](libgdx.md)
- [mkxp](mkxp.md) - [mkxp](mkxp.md)
- [pygame](pygame.md) - [pygame](pygame.md)
- [rpge](rpge.md)
- [sandbox Game Maker](sandboxgamemaker.md) - [sandbox Game Maker](sandboxgamemaker.md)
- [xoreos](xoreos.md) - [xoreos](xoreos.md)

View File

@ -1,7 +1,7 @@
# Popular required libraries # Popular required libraries
- [Allegro](allegro.md) - [Allegro](allegro.md)
- [Boost](boost.md) - [Boost (C++ Libraries)](boost.md)
- [Crypto++](crypto.md) - [Crypto++](crypto.md)
- [FreeType](freetype.md) - [FreeType](freetype.md)
- [HarfBuzz](harfbuzz.md) - [HarfBuzz](harfbuzz.md)
@ -10,8 +10,10 @@
- [Lua](lua.md) - [Lua](lua.md)
- [Open AL](openal.md) - [Open AL](openal.md)
- [Open AL Soft](openalsoft.md) - [Open AL Soft](openalsoft.md)
- [OpenSSL](openssl.md)
- [Pthreads-win32](pthreads_win32.md) - [Pthreads-win32](pthreads_win32.md)
- [Simple DirectMedia Layer (SDL 2)](sdl_2.md) - [Ragel](ragel.md)
- [Simple DirectMedia Layer](sdl_2.md)
- [Simple and Fast Multimedia Library](sfml.md) - [Simple and Fast Multimedia Library](sfml.md)
- [XZ Utils](xz.md) - [XZ Utils](xz.md)
- [libpng](libpng.md) - [libpng](libpng.md)

View File

@ -8,73 +8,111 @@
import os import os
import re import re
readme_regex = re.compile(r"- \[(.+)\]\((.+)\/_toc.md\)") def read_first_line_from_file(file):
toc_regex = re.compile(r"- \[(.+)\]\((.+)\)") with open(file, 'r') as f:
line = f.readline()
return line
if __name__ == "__main__": def update_readme():
"""
Recounts entries in subcategories and writes them to the readme
"""
print('update readme file')
# readme file location # load readme
base_path = os.path.abspath(os.path.dirname(__file__))
readme_path = os.path.join(base_path, 'README.md') readme_path = os.path.join(base_path, 'README.md')
# read readme # read readme
with open(readme_path) as f: with open(readme_path) as f:
readme_lines = f.readlines() readme_text = f.read()
# apply regex search on all lines # compile regex for identifying the building blocks
matched_lines = [readme_regex.findall(line) for line in readme_lines] regex = re.compile(r"(.*## Contents\n\n)(.*)(\n## Contributing.*)", re.DOTALL)
# empty subfolder list # apply regex
subfolders = [] matches = regex.findall(readme_text)
matches = matches[0]
start = matches[0]
middle = matches[1]
end = matches[2]
# loop over the lines # get sub folders
for line, match in enumerate(matched_lines): subfolders = [x for x in os.listdir(base_path) if x != '.git' and os.path.isdir(os.path.join(base_path, x))]
if match:
# get first group (should be only one)
match = match[0]
# add to subfolders list # get number of files (minus 1) in each sub folder
subfolders.append(match[1]) n = [len(os.listdir(os.path.join(base_path, folder))) - 1 for folder in subfolders]
# subfolder path # assemble paths
subfolder_path = os.path.join(base_path, match[1]) paths = [os.path.join(base_path, folder, '_toc.md') for folder in subfolders]
# get number of files in that path (-1 for _toc.md) # get titles (discarding first two ("# ") and last ("\n") characters)
n = len(os.listdir(subfolder_path)) - 1 titles = [read_first_line_from_file(path)[2:-1] for path in paths]
# generate new line # combine folder name, number, titles in one list
readme_lines[line] = "- [{}]({}/_toc.md) ({})\n".format(match[0], match[1], n) info = zip(titles, subfolders, n)
# write readme again # sort according to title
with open(readme_path, "w") as f: info.sort(key=lambda x:x[0])
f.writelines(readme_lines)
# loop over all subfolders # assemble output
for subfolder in subfolders: update = ['- [{}]({}/_toc.md) ({})\n'.format(*entry) for entry in info]
update = "".join(update)
# get contents file of that subfolder # insert new text in the middle
toc_path = os.path.join(base_path, subfolder, '_toc.md') text = start + update + end
# read contents file # write to readme
with open(toc_path) as f: with open(readme_path, 'w') as f:
toc = f.readlines() f.write(text)
# only if there are at least 4 lines (header, empty, two entries) def update_category_tocs():
if len(toc) >= 4: """
Lists all entries in all sub folders and generates the list in the toc file
"""
# get sub folders
subfolders = [x for x in os.listdir(base_path) if x != '.git' and os.path.isdir(os.path.join(base_path, x))]
# apply regex search on all entries (should work on all) # for each subfolder
matched_entries = [toc_regex.findall(line)[0] for line in toc[2:]] for folder in subfolders:
print('generate toc for {}'.format(folder))
# sort according to first entry # read toc header line
matched_entries.sort(key=lambda x: x[0]) toc_folder = os.path.join(base_path, folder)
toc_file = os.path.join(toc_folder, '_toc.md')
toc_header = read_first_line_from_file(toc_file)
# generate links again # get all files
lines = ["- [{}]({})\n".format(*match) for match in matched_entries] files = [x for x in os.listdir(toc_folder) if x != '_toc.md' and os.path.isfile(os.path.join(toc_folder, x))]
paths = [os.path.join(toc_folder, file) for file in files]
# reassemble toc # get titles (discarding first two ("# ") and last ("\n") characters)
toc = toc[0:2] titles = [read_first_line_from_file(path)[2:-1] for path in paths]
toc.extend(lines)
# combine name and file name
info = zip(titles, files)
# sort according to title
info.sort(key=lambda x:x[0])
# assemble output
update = ['- [{}]({})\n'.format(*entry) for entry in info]
update = "".join(update)
# combine toc header
text = toc_header + '\n' + update
# write to toc file
with open(toc_file, 'w') as f:
f.write(text)
if __name__ == "__main__":
# base path
base_path = os.path.abspath(os.path.dirname(__file__))
# recount and write to readme
update_readme()
# generate list in toc files
update_category_tocs()
# write contents file again
with open(toc_path, "w") as f:
f.writelines(toc)

View File

@ -2,6 +2,8 @@
- [Arx Libertatis](arx_libertatis.md) - [Arx Libertatis](arx_libertatis.md)
- [BrowserQuest](browserquest.md) - [BrowserQuest](browserquest.md)
- [Crossfire](crossfire.md)
- [Egoboo](egoboo.md) - [Egoboo](egoboo.md)
- [FreedroidRPG](freedroid.md) - [FreedroidRPG](freedroid.md)
- [Hero of Allacrost](allacrost.md) - [Hero of Allacrost](allacrost.md)
- [VegaTrek](vegatrek.md)

View File

@ -20,6 +20,7 @@
- [Open Imperium Galactica](open_imperium_galactica.md) - [Open Imperium Galactica](open_imperium_galactica.md)
- [OpenRA](openra.md) - [OpenRA](openra.md)
- [OpenXcom](openxcom.md) - [OpenXcom](openxcom.md)
- [Pax Britannica](pax_britannica.md)
- [Spring RTS engine](spring.md) - [Spring RTS engine](spring.md)
- [Star Control II: The Ur-Quan Masters](star_control_2.md) - [Star Control II: The Ur-Quan Masters](star_control_2.md)
- [TripleA](triplea.md) - [TripleA](triplea.md)

View File

@ -5,7 +5,7 @@ _{One line description}_
- Home: {URL} - Home: {URL}
- Wikipedia: {URL} - Wikipedia: {URL}
- Download: {URL} - Download: {URL}
- State: beta, mature - State: beta, mature (inactive since)
- Keywords: single player, multi player, RTS, TBS (if none, remove the line) - Keywords: single player, multi player, RTS, TBS (if none, remove the line)
- Code: primary repository (type if not git), other repositories (type if not git) - Code: primary repository (type if not git), other repositories (type if not git)
- Language(s): {XX} - Language(s): {XX}