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
- [Libraries](library/_toc.md) (19)
- [Frameworks](framework/_toc.md) (44)
- [Adventures & Visual Novels](adventure/_toc.md) (8)
- [RPGs](rpg/_toc.md) (7)
- [Simulation](simulation/_toc.md) (8)
- [Strategy](strategy/_toc.md) (29)
- [Adventure games & Visual novels](adventure/_toc.md) (8)
- [Game frameworks](framework/_toc.md) (44)
- [Popular required libraries](library/_toc.md) (19)
- [Role Playing Games](rpg/_toc.md) (7)
- [Simulation games](simulation/_toc.md) (8)
- [Strategy games](strategy/_toc.md) (29)
## Contributing

View File

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

View File

@ -1,7 +1,7 @@
# Popular required libraries
- [Allegro](allegro.md)
- [Boost](boost.md)
- [Boost (C++ Libraries)](boost.md)
- [Crypto++](crypto.md)
- [FreeType](freetype.md)
- [HarfBuzz](harfbuzz.md)
@ -10,8 +10,10 @@
- [Lua](lua.md)
- [Open AL](openal.md)
- [Open AL Soft](openalsoft.md)
- [OpenSSL](openssl.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)
- [XZ Utils](xz.md)
- [libpng](libpng.md)

View File

@ -8,73 +8,111 @@
import os
import re
readme_regex = re.compile(r"- \[(.+)\]\((.+)\/_toc.md\)")
toc_regex = re.compile(r"- \[(.+)\]\((.+)\)")
def read_first_line_from_file(file):
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
base_path = os.path.abspath(os.path.dirname(__file__))
# load readme
readme_path = os.path.join(base_path, 'README.md')
# read readme
with open(readme_path) as f:
readme_lines = f.readlines()
readme_text = f.read()
# apply regex search on all lines
matched_lines = [readme_regex.findall(line) for line in readme_lines]
# compile regex for identifying the building blocks
regex = re.compile(r"(.*## Contents\n\n)(.*)(\n## Contributing.*)", re.DOTALL)
# empty subfolder list
subfolders = []
# apply regex
matches = regex.findall(readme_text)
matches = matches[0]
start = matches[0]
middle = matches[1]
end = matches[2]
# loop over the lines
for line, match in enumerate(matched_lines):
if match:
# get first group (should be only one)
match = match[0]
# 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))]
# add to subfolders list
subfolders.append(match[1])
# get number of files (minus 1) in each sub folder
n = [len(os.listdir(os.path.join(base_path, folder))) - 1 for folder in subfolders]
# subfolder path
subfolder_path = os.path.join(base_path, match[1])
# assemble paths
paths = [os.path.join(base_path, folder, '_toc.md') for folder in subfolders]
# get number of files in that path (-1 for _toc.md)
n = len(os.listdir(subfolder_path)) - 1
# get titles (discarding first two ("# ") and last ("\n") characters)
titles = [read_first_line_from_file(path)[2:-1] for path in paths]
# generate new line
readme_lines[line] = "- [{}]({}/_toc.md) ({})\n".format(match[0], match[1], n)
# combine folder name, number, titles in one list
info = zip(titles, subfolders, n)
# write readme again
with open(readme_path, "w") as f:
f.writelines(readme_lines)
# sort according to title
info.sort(key=lambda x:x[0])
# loop over all subfolders
for subfolder in subfolders:
# assemble output
update = ['- [{}]({}/_toc.md) ({})\n'.format(*entry) for entry in info]
update = "".join(update)
# get contents file of that subfolder
toc_path = os.path.join(base_path, subfolder, '_toc.md')
# insert new text in the middle
text = start + update + end
# read contents file
with open(toc_path) as f:
toc = f.readlines()
# write to readme
with open(readme_path, 'w') as f:
f.write(text)
# only if there are at least 4 lines (header, empty, two entries)
if len(toc) >= 4:
def update_category_tocs():
"""
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)
matched_entries = [toc_regex.findall(line)[0] for line in toc[2:]]
# for each subfolder
for folder in subfolders:
print('generate toc for {}'.format(folder))
# sort according to first entry
matched_entries.sort(key=lambda x: x[0])
# read toc header line
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
lines = ["- [{}]({})\n".format(*match) for match in matched_entries]
# get all files
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
toc = toc[0:2]
toc.extend(lines)
# get titles (discarding first two ("# ") and last ("\n") characters)
titles = [read_first_line_from_file(path)[2:-1] for path in paths]
# 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)
- [BrowserQuest](browserquest.md)
- [Crossfire](crossfire.md)
- [Egoboo](egoboo.md)
- [FreedroidRPG](freedroid.md)
- [Hero of Allacrost](allacrost.md)
- [VegaTrek](vegatrek.md)

View File

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

View File

@ -5,7 +5,7 @@ _{One line description}_
- Home: {URL}
- Wikipedia: {URL}
- Download: {URL}
- State: beta, mature
- State: beta, mature (inactive since)
- 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)
- Language(s): {XX}