From daa9cd44704cf4c201a0f20641f0719bb9d480d9 Mon Sep 17 00:00:00 2001 From: lxgr-linux Date: Fri, 21 Jun 2024 15:33:12 +0200 Subject: [PATCH 01/26] feat(#287): Added pokete utility --- util.py | 47 ++++ util/__init__.py | 3 + util/arguments.py | 28 ++ util/pages.py | 427 ++++++++++++++++++++++++++++++ util/wiki.py | 652 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 1157 insertions(+) create mode 100644 util.py create mode 100644 util/__init__.py create mode 100644 util/arguments.py create mode 100644 util/pages.py create mode 100755 util/wiki.py diff --git a/util.py b/util.py new file mode 100644 index 00000000..2f3e48e4 --- /dev/null +++ b/util.py @@ -0,0 +1,47 @@ +import sys +from util import parse, gen_wiki, prepare_pages + + +def show_help(name: str): + print(f"""{name} -- Pokete utility +Usage: + {name} [command] [options]... + +Commands: + wiki\t\tGenerates wiki.md + prpare-pages\tPrepares github pages + release\t\tCreates a release commit + help\t\tShows this help + +Flags: + --help\t\tShows help for a specific command + +Copyright (c) lxgr-linux 2024""") + + +def main(): + args = sys.argv + command, options, flags = parse(args) + + arg_tup = (args[0], command, options, flags) + + match command: + case "help": + show_help(args[0]) + case "wiki": + gen_wiki(*arg_tup) + case "prepare-pages": + prepare_pages(*arg_tup) + case _: + if "--help" in flags: + show_help(args[0]) + else: + print( + f":: Error: Command '{command}' not found, " + f"try `{args[0]} help`" + ) + sys.exit(2) + + +if __name__ == "__main__": + main() diff --git a/util/__init__.py b/util/__init__.py new file mode 100644 index 00000000..734da6a4 --- /dev/null +++ b/util/__init__.py @@ -0,0 +1,3 @@ +from .arguments import parse +from .wiki import gen as gen_wiki +from .pages import prepare as prepare_pages diff --git a/util/arguments.py b/util/arguments.py new file mode 100644 index 00000000..bd4decbb --- /dev/null +++ b/util/arguments.py @@ -0,0 +1,28 @@ +def parse(args) -> tuple[str, list[str], dict[str, list[str]]]: + if len(args) == 0: + return "", [], {} + options: list[str] = [] + flags: dict[str, list[str]] = {} + idx = 0 + for arg in args[2:]: + if arg.startswith("--"): + break + idx += 1 + options.append(arg) + __index_flags(0, args[2 + idx:], "", flags) + + return args[1], options, flags + + +def __index_flags( + idx: int, arr: list[str], flag: str, + flags: dict[str, list[str]] +): + if idx == len(arr): + return + if arr[idx].startswith("--"): + flag = arr[idx] + flags[flag] = flags.get(flag, []) + else: + flags[flag].append(arr[idx]) + __index_flags(idx + 1, arr, flag, flags) diff --git a/util/pages.py b/util/pages.py new file mode 100644 index 00000000..75ba2e9d --- /dev/null +++ b/util/pages.py @@ -0,0 +1,427 @@ +#!/usr/bin/env python +""" +Prepare pages prepares all files in "files" for GitHub Pages + +This script takes one argument, which specifies if the actions it should take are before the command +"git switch gh-pages" or afterwards. "before" means that it will the pre-change actions and "after" the after-change +actions. + +This script processes files on how they are configured in the "files" dictionary: If the type is documentation +if will call pdoc3 to create the documentation for it. If the type is "page", the argument "convert_with_pandoc" +is a boolean which specifies, if the file should be converted into HTML by pandoc (True) or GitHub Pages' Jekyll +(False). If set to false, it is advised to set "convert_tables" to True, as Jekyll can not handle markdown tables. +Afterwards this script will replace all the links specified in the list "replace_links". There the first argument of +the Tuple specifies the old link and the second argument the new link. With "new_name" the file will be renamed on the +website. + +Usage: +----- +- python3 prepare_pages.py before + - Invokes actions before the branch switch +- python3 prepare_pages.py after + - Invokes actions after the branch switch + +Exit Codes: +---------- +- 0: Everything is OK. +- 1: An internal error occurred +- 2: The user did not specify the right/enough arguments +""" +import os +from os.path import exists +import sys +import json +from urllib import request +from util.wiki import Wiki + +""" +The files dictionary specifies how and which files should be processed. + +Structure: +--------- +- Filename or directory (directory only with type=documentation) + - type: + - page: Converts into static webpage + - documentation: calls pdoc3 to create a documentation for it + - replace_tables: Boolean: If tables should be replaced by HTML-Tables + - replace_links: A list of tuples for links th be replaced in this document + - element one: The link that should be replaced + - element two: The link that element one should be replaced with + - convert_with_pandoc: boolean: If the page should be converted with pandoc (True) or Jekyll (False) + - new_name: the new filename and the name on the website. If convert_with_pandoc is set to true, + make the extension .html. If the name should not be changed, put in None. +""" +files = {} + + +def replace_tables(_text: str) -> str: + """Replaces all markdown tables in _text with html tables + + This function writes the mardkwon table to a temporary file in /tmp/, calls pandoc to convert this file to html and + reads the text back in. + + Arguments: + --------- + - _text: The text in which all the tables should be converted. + + Returns: + ------- + The input string, but with replaced markdown tables. + """ + out = '' + table = '' + in_table = False + for line in _text.split('\n'): + if '|' in line: + in_table = True + table += line + table += '\n' + else: + if in_table: + in_table = False + with open('/tmp/pandoc_convert.md', 'w') as _f: + _f.write(table) + os.system( + 'pandoc /tmp/pandoc_convert.md -o /tmp/pandoc_convert.html') + with open('/tmp/pandoc_convert.html', 'r') as _f: + md_text = _f.read() + table = '' + out += md_text + out += '\n' + else: + out += line + out += '\n' + return out + + +def get_header(url: str = r'https://lxgr-linux.github.io/pokete', + header_end: str = r'
') -> str: + """Gets the first part of a webpage + + Arguments: + --------- + - url: The URL to get the first part of. + - header_end: the end of the "header". + + Returns: + ------- + The start of this webpage. + """ + result = request.urlopen(url) + _text = result.read().decode('UTF-8').split(header_end)[0] + return _text + header_end + '\n' + + +def get_footer(url: str = r'https://lxgr-linux.github.io/pokete', + footer_start: str = r'
') -> str: + """Gets the last part of a webpage + + Arguments: + --------- + - url: The URL to get the last part of. + - footer_start: Where the "footer"/the end of the webpage begins. + + Returns: + ------- + The end of this webpage. + """ + result = request.urlopen(url) + _text = result.read().decode('UTF-8').split(footer_start)[1] + _text = footer_start + _text + return _text + + +def create_documentation() -> None: + """Creates documentation for all tagged files + + This function creates python documentation for all files and folders in the files dictionary that have the type + "documentation". This function will call pdoc to create the documentation for it. + """ + modules = [file for file in files if files[file]["type"] == "documentation"] + pdoc_path = "/home/runner/.local/bin/pdoc" + + for module in modules: + print(f" -> {module}") + os.system( + f"{pdoc_path} --html {module} --output-dir \"/tmp/doc/\" --force") + + +def add_folder(folder: str, add_tmp_folder: bool = False) -> None: + """Creates a folder, if not does not already exist + + This function creates a folder in the current working directory. + It also creates a folder with the same name in /tmp, if needed. + + Arguments + --------- + folder: The name of the folder to create + add_tmp_folder If a folder in /tmp should be creates as well. + """ + if not os.path.isdir(folder): + os.mkdir(folder) + tmp_folder = os.path.join("/tmp", folder) + if not os.path.isdir(tmp_folder): + os.mkdir(tmp_folder) + files.update({ + folder: { + "type": "folder" + } + }) + + +def create_wiki() -> None: + """Creates a multi-page and a single-page wiki. + + This function calls the multi-page and single-page methods from the + gen_wiki file to add to the gh-pages. + """ + Wiki.multi("./wiki-multi-md/") + Wiki.single("./wiki-single.md") + + +def add_wiki_folder(folder_name: str) -> list: + """Gives out all markdown files in current and subdirectories as a list + + This function adds all markdown files in the current directory to the list + is gives back. It also calls itself for each sub-directory and appends the + markdown files from itself to the output list as well. + + Arguments + --------- + folder_name: The folder to add + + Returns: + -------- + A list of all markdown files in the current and all subdirectories. + """ + items = os.listdir(folder_name) + out = [] + for item in items: + file = os.path.join(folder_name, item) + if os.path.isdir(file): + add_folder(file.replace("./wiki-multi-md/", "./wiki-multi-html/"), + True) + for f in add_wiki_folder(file): + out.append(f) + elif os.path.isfile(file): + if item.endswith(".md"): + out.append(file) + else: + print(f"{file} is not a markdown file!") + else: + print(f"Unrecognized type: {file}") + return out + + +def add_wiki_to_files() -> None: + """Add files from multi-page wiki to files dictionary + + This function adds all markdown files from the directory ./wiki-multi-md + and its subdirectories into the files dictionary to be processed by the other functions as well. + """ + if not os.path.isdir("./wiki-multi-html"): + os.mkdir("./wiki-multi-html") + if not os.path.isdir("/tmp/wiki-multi-html"): + os.mkdir("/tmp/wiki-multi-html") + wiki_files = add_wiki_folder("./wiki-multi-md/") + print(wiki_files) + for wiki_file in wiki_files: + files.update({ + wiki_file: { + "type": "page", + "replace_tables": False, + "convert_with_pandoc": True, + "replace_links": [], + "new_name": str(wiki_file.replace(".md", ".html")).replace( + "./wiki-multi-md/", "./wiki-multi-html/") + } + }) + print(files) + + +def before() -> None: + """The actions that should be executed before the brach switch + + This functions creates documentation for all the files, replaces tables if necessary or converts the files with + pandoc. All the files are then moved into the /mp directory. + """ + print(':: Preparing files for gh-pages...') + print("==> Generating documentation with pdoc...") + create_documentation() + print("==> Creating Wiki...") + create_wiki() + print("==> Adding Multi-page Wiki...") + add_wiki_to_files() + for file in files.keys(): + print(f"==> Preparing {file}") + properties = files[file] + + if properties["type"] == "documentation" or properties[ + "type"] == "folder": + continue + + new_name = properties["new_name"] if properties[ + "new_name"] is not None else file + + # Jekyll can not handle double open/closing brackets (e.g. {{) , so we + # need to manually convert these pages. + # We do this by using pandoc and adding the start and end of the + # root page to the start and the end of the + if properties["convert_with_pandoc"]: + print(" -> Converting to html...") + os.system( + f"pandoc --from gfm --to html5 -o \"{new_name}\" \"{file}\"") + + # Tables only need to be replaced, if the file is not converted with + # pandoc, as pandoc is converting the tables automatically. + elif properties["replace_tables"]: + print(" -> Replacing Tables...") + with open(file, 'r') as f: + text = f.read() + text = replace_tables(text) + with open(new_name, 'w') as f: + f.write(text) + + # If no operation was performed, we need to move the file, in order to + # not interrupt the workflow. + else: + os.system(f"mv \"{file}\" \"{new_name}\"") + + print(" -> Copying to /tmp...") + os.system(f"cp \"{new_name}\" \"/tmp/{new_name}\"") + + files[file]["new_name"] = new_name + + print("Saving configuration...") + with open('/tmp/prepare_pages_saves.py', 'w') as f: + f.write(str(files)) + + print(':: Done!') + + +def after() -> None: + """The actions that shall be executed in the gh-pages branch. + + This function copies all previously created files from /tmp/ to the current + working directory and adds the start and end of the gh-pages index website + to the files which have been converted with pandoc. This achieves a universal + look on all gh-pages pages. This function then replaces all the links for + each file. + """ + print(':: After processing files for gh-pages...') + print(':: Acquiring assets...') + print('==> header') + header = get_header(url='https://lxgr-linux.github.io/pokete', + header_end='
') + print(header) + print('==> footer') + footer = get_footer(url='https://lxgr-linux.github.io/pokete', + footer_start='
') + print(footer) + # We need to store the configuration to keep the "new_name" attribute from + # the before run. + print(":: Loading configuration...") + with open('/tmp/prepare_pages_saves.py', 'r') as f: + text = f.read() + new_files = eval(text) + + print(':: Processing files...') + print('==> Making directories...') + print(' -> wiki-multi-html') + add_folder('wiki-multi-html', False) + for file in new_files.keys(): + properties = new_files[file] + if properties["type"] == "folder": + print(' -> ' + file) + add_folder(file, False) + documentation_copied = False + for file in new_files.keys(): + properties = new_files[file] + + # Copy documentation folder from /tmp/doc/ to current directory + if properties["type"] == "documentation": + if not documentation_copied: + print("==> Copying Documentation folder...") + if exists("./doc/"): + print(" -> Removing old documentation folder...") + os.system(f"rm -rf doc") + print(" -> Copying new documentation files...") + os.system("cp -r /tmp/doc/ .") + documentation_copied = True # Only copy the directory once + continue + elif properties["type"] == "folder": + continue + + new_name = properties["new_name"] if properties[ + "new_name"] is not None else file + print(f'==> After processing {new_name}') + + # If a file was converted with pandoc, it needs the stylesheet + # (in the header) and a footer. + if properties["convert_with_pandoc"]: + print("-> Applying Styles...") + with open(f"/tmp/{new_name}", 'r') as f: + text = f.read() + with open(new_name, 'w') as f: + f.write(header + text + footer) + else: + print(" -> Copying to current directory...") + os.system(f"cp \"/tmp/{new_name}\" .") + + # Links need to be replaced from directory and markdown direct links + # (wiki.md) into website links (./wiki) + if properties["replace_links"]: + print(" -> Replacing links...") + for old in properties["replace_links"].keys(): + new = properties["replace_links"][old] + if old != list(properties["replace_links"].keys())[-1]: + print(f" |-> Replacing {old} with {new}...") + else: + print(f" `-> Replacing {old} with {new}...") + # Need to use sed, as str.replace somehow misses some link + # changes? + os.system(f"sed -i 's#]({old}#]({new}#g' {new_name}") + print("==> Renaming 'wiki-multi-html' to 'wiki-multi'...") + os.system("mv './wiki-multi-html/' './wiki-multi'") + print(':: Done!') + + +def show_help(ex: str, command: str): + print(f"""{ex} {command} -- Prepare for github pages +Usage: + {ex} {command} [after|before] + +Flags: + --help\t\tShows help for a specific command + +Copyright (c) lxgr-linux 2024""") + + +def prepare( + ex: str, command: str, options: list[str], + flags: dict[str, list[str]] +): + global files + if "--help" in flags: + show_help(ex, command) + + elif len(options) == 0: + print( + ":: Error: Not enough arguments, " + f"try `{ex} {command} help`" + ) + sys.exit(2) + else: + match opt := options[0]: + case 'before': + with open('.gh-pages.json', 'r') as config_file: + files = json.loads(config_file.read()) + before() + case 'after': + after() + case _: + print( + f":: Error: Option '{opt}' not found, " + f"try `{ex} {command} help`" + ) + sys.exit(2) diff --git a/util/wiki.py b/util/wiki.py new file mode 100755 index 00000000..83785959 --- /dev/null +++ b/util/wiki.py @@ -0,0 +1,652 @@ +#!/usr/bin/env python3 +"""This script generates the Pokete wiki""" +import os +from os.path import exists, isdir +import sys +import scrap_engine as se +import release +from pokete_classes.effects import effects, effect_list +from pokete_data import pokes, attacks, types, items, maps + +SILENT = False +QUIET = False +VERBOSE = True + + +class Wiki: + """The class in which wiki generation behaviour is defined""" + + @staticmethod + def start() -> str: + """The start and title of the wiki + + Returns + --- + The title of the wiki page. + """ + return f"""v{release.VERSION} + +# Pokete Wiki +This wiki/documentation is a compilation of all Poketes, attacks, and types present in the Pokete game. +The wiki can be generated using ```$ ./gen_wiki.py```. + +Use ```$ ./gen_wiki.py help``` to get more information about different wikis. + +You can find different versions of this wiki: + +- A single-page version can be found [here](wiki.md) +- A multi-page version can be found [here](https://lxgr-linux.github.io/pokete/wiki-multi/) + +""" + + @staticmethod + def overview(multi_page: bool = False) -> str: + """A short overview of what the wiki contains. + + Arguments + --------- + - multi_page (boolean): if the item info should be made for a multi-page wiki or not. + + Returns + ------- + An overview for a multi-page wiki. + """ + return "Table of contents\n" + \ + "\n".join( + f"{i + 1}. [{name.capitalize()}]({'' if multi_page else '#'}{name})" + for i, name in enumerate(["poketes", "attacks", "types", "item", + "effects"])) + "\n" + + @staticmethod + def get_name(poke): + """Returns the name of a Pokete to display in headings""" + additional = "" + if "_night" in poke: + additional = " night" + elif "_day" in poke: + additional = " day" + return pokes[poke]['name'] + additional + + @staticmethod + def table_of_contents(multi_page: bool = False) -> str: + """The table of contents of the pokete wiki + + Arguments + --------- + - multi_page (boolean): if the item info should be made for a multi-page wiki or not. + + Returns + ------- + A Table of contents for a single page wiki. + """ + out = '' + + # Table of contents + if not multi_page: + out += """## Table of contents +1. [Poketes](#poketes) +""" + for i, typ in enumerate(sorted(types)): + out += f""" {i + 1}. [{typ.capitalize()} Poketes](#{typ}-poketes)\n""" + for j, poke in enumerate([k for k in sorted(list(pokes)[1:]) if + pokes[k]["types"][0] == typ]): + out += f""" {j + 1}. [{Wiki.get_name(poke)}](#{poke.replace("_", "-")})\n""" + out += "2. [Attacks](#attacks)\n" + for i, typ in enumerate(sorted(types)): + out += f""" {i + 1}. [{typ.capitalize()} attacks](#{typ}-attacks)\n""" + for j, atc in enumerate([k for k in sorted(attacks) if + attacks[k]["types"][0] == typ]): + out += f""" {j + 1}. [{attacks[atc]["name"]}](#{attacks[atc]["name"] + .replace(" ", "-").lower()})\n""" + out += """3. [Types](#types) +4. [Items](#items) +""" + for j, item in enumerate(sorted(items)): + out += f""" {j + 1}. [{items[item]["pretty_name"]}](#{item.replace("_", "-")})\n""" + out += """5. [Effects](#effects) +""" + for j, effect in enumerate(effect_list): + out += f""" {j + 1}. [{effect.c_name.capitalize()}](#{effect.c_name.replace("_", "-")}) +""" + + else: + out += """## Table of contents +1. [Poketes](./poketes) +""" + for i, typ in enumerate(sorted(types)): + out += f""" {i + 1}. [{typ.capitalize()} Poketes](./poketes/{typ})\n""" + for j, poke in enumerate([k for k in sorted(list(pokes)[1:]) if + pokes[k]["types"][0] == typ]): + out += f""" {j + 1}. [{Wiki.get_name(poke)}](./poketes/{typ}#{poke.replace("_", "-")})\n""" + out += "2. [Attacks](./attacks)\n" + for i, typ in enumerate(sorted(types)): + out += f""" {i + 1}. [{typ.capitalize()} attacks](./attacks/{typ})\n""" + for j, atc in enumerate([k for k in sorted(attacks) if + attacks[k]["types"][0] == typ]): + out += f""" {j + 1}. [{attacks[atc]["name"]}](./attack/{typ}#{atc.replace("_", "-")})\n""" + out += """3. [Types](./types) +4. [Items](./items) +""" + for j, item in enumerate(sorted(items)): + out += f""" {j + 1}. [{items[item]["pretty_name"]}](./items#{item.replace("_", "-")})\n""" + out += """5. [Effects](./effects) +""" + for j, effect in enumerate(effect_list): + out += f""" {j + 1}. [{effect.c_name.capitalize()}](./effects#{effect.c_name.replace("_", "-")}) +""" + return out + + @staticmethod + def poketes(page_mode='single', pokete_type=None) -> str: + """The function to add all poketes and their attributes to the wiki. + + Arguments: + ---------- + - page_mode (string): Defines for what the output will be used. Can be: + - single: all poketes listed by their types with single-page links + - index: Just the index of all pokete types with multi-page links + - multi: Information about the pokete type definied in pokete_type + with multi-page links. + - pokete_type: Only necessary if page_mode is set to 'index': Then + defines the pokete type to get the information and links of. + + Returns + ------- + All poketes and their attributes as a markdown string. + """ + if page_mode == 'single': + out = """ +## Poketes +In the following all Poketes with their attributes are displayed. + +""" + for typ in sorted(types): + out += f"### {typ.capitalize()} Poketes" + for poke in [k for k in sorted(list(pokes)[1:]) if + pokes[k]["types"][0] == typ]: + if VERBOSE: + print(f' -> Adding {pokes[poke]["name"]}') + out += Wiki.poke_info(poke) + return out + elif page_mode == 'index': + out = """# Poketes +In the following all Poketes with their attributes are displayed. + +""" + for typ in sorted(types): + out += f"- [{typ.capitalize()} Poketes](./{typ})\n" + out += "\n---\n\n## All poketes sorted by their type:\n" + for typ in sorted(types): + out += f"- [{typ.capitalize()} Poketes](./{typ})\n" + for poke in [k for k in sorted(list(pokes)[1:]) if + pokes[k]["types"][0] == typ]: + out += f""" - [{pokes[poke]["name"].capitalize()}](./{typ}#{poke})\n""" + return out + elif page_mode == 'multi': + if pokete_type is not None: + out = f"# {pokete_type.capitalize()} Poketes" + for poke in [k for k in sorted(list(pokes)[1:]) if + pokes[k]["types"][0] == pokete_type]: + if poke == sorted(list(pokes)[1:])[-1]: + if VERBOSE: + print(f' `-> Adding {pokes[poke]["name"]}') + else: + if VERBOSE: + print(f' |-> Adding {pokes[poke]["name"]}') + out += Wiki.poke_info(poke=poke, multi_page=True) + return out + raise AttributeError( + "Pokete_type can not be none, if mode 'multi' is selected.") + raise AttributeError("Please select a valid page mode of: 'single'," + "'index' or 'multi'!") + + @staticmethod + def poke_info(poke: str, multi_page: bool = False) -> str: + """Generates information about a specific pokete + + Arguments: + --------- + - poke (string): The pokete to get the information of. + - multi_page (boolean): if the item info should be made for a multi-page + wiki or not. + + Returns + ------- + A markdown string of all the attributes and information of the pokete. + """ + if (evolve_pokete := pokes[poke]["evolve_poke"]) == "": + evolve_txt = "- Does not evolve\n" + else: + evolve_txt = f"""- Evolves to [{Wiki.get_name(evolve_pokete)}]({f'./{pokes[evolve_pokete]["types"][0]}' + if multi_page else ""}#{evolve_pokete.replace("_", "-")}) at level {pokes[poke]['evolve_lvl']}""" + + md_attacks = "\n + " + "\n + ".join(f"""[{attacks[atc]["name"]}]({ + f'../attacks/{attacks[atc]["types"][0].capitalize()}' + if multi_page else "" + }#{attacks[atc]["name"] + .replace(" ", "-").lower()})""" + for atc in + pokes[poke]["attacks"]) + # ico + ico_map = se.Map(4, 11, background=" ") + for ico in pokes[poke]["ico"]: + se.Text(ico["txt"], state="float", ignore=" ").add(ico_map, 0, 0) + ico = "".join("".join(arr) + "\n" for arr in ico_map.map) + + active = { + True: "Night", + False: "Day", + None: "Always", + }[pokes[poke].get("night_active")] + + md_locations = "\n + ".join(maps[i]["pretty_name"] for i in maps + if maps[i]["poke_args"] is not None + and poke in maps[i]["poke_args"]["pokes"] + or "w_poke_args" in maps[i] + and poke in maps[i]["w_poke_args"][ + "pokes"]) + + return f""" +##{'' if multi_page else '##'} {Wiki.get_name(poke)} +{pokes[poke]["desc"]} + +``` +{ico} +``` + +- Type: [{pokes[poke]["types"][0].capitalize()}]({'../types' if multi_page + else '#types'}) +- Health points: {pokes[poke]["hp"]} +- Attack factor: {pokes[poke]["atc"]} +- Defense factor: {pokes[poke]["defense"]} +- Initiative: {pokes[poke]["initiative"]} +- Missing chance: {pokes[poke]["miss_chance"]} +- Rarity: {pokes[poke]["rarity"]} +- Loosing experience: {pokes[poke]["lose_xp"]} +- Attacks:{md_attacks} +- Active: {active} +- Can be found in: + + {md_locations if md_locations != "" else "Nowhere"} +{evolve_txt} +""" + + @staticmethod + def attacks(multi_page: bool = False) -> str or list: + """The function to all attacks to the wiki. + + Arguments + --------- + - multi_page (boolean): if the item info should be made for a multi-page + wiki or not. + + Returns + ------- + A markdown string of all attacks with their attributes and informations. + """ + if multi_page: + index = """# Attacks +Those are all attacks present in the game. +""" + pages = [] + for typ in sorted(types): + if VERBOSE: + print(f" -> Adding {typ}") + index += f"\n- [{typ.capitalize()}](./{typ})" + page = f"# {typ.capitalize()} attacks" + for atc in [k for k in attacks if + attacks[k]["types"][0] == typ]: + if multi_page: + if atc == [k for k in attacks if + attacks[k]["types"][0] == typ][-1]: + if VERBOSE: + print(f' `-> Adding {attacks[atc]["name"]}') + else: + if VERBOSE: + print(f' |-> Adding {attacks[atc]["name"]}') + else: + if VERBOSE: + print(f' -> Adding {attacks[atc]["name"]}') + page += Wiki.attack_info(atc, True) + pages.append((f"{typ}.md", page)) + index += "\n\n---\n\n## All attacks sorted by their type:\n" + for typ in sorted(types): + index += f"- [{typ.capitalize()} Attacks](./{typ})\n" + for atc in [k for k in attacks if + attacks[k]["types"][0] == typ]: + index += f""" - [{attacks[atc]["name"].capitalize()}](./{typ}#{atc.replace('_', '-')})\n""" + + index += '\n' + pages.insert(0, ("index.md", index)) + return pages + out = """ +## Attacks +Those are all attacks present in the game. +""" + for typ in sorted(types): + out += f"\n### {typ.capitalize()} attacks" + for atc in [k for k in attacks if + attacks[k]["types"][0] == typ]: + if atc == \ + [k for k in attacks if attacks[k]["types"][0] == typ][ + -1]: + if VERBOSE: + print(f' `-> Adding {attacks[atc]["name"]}') + else: + if VERBOSE: + print(f' |-> Adding {attacks[atc]["name"]}') + out += Wiki.attack_info(atc) + + return out + + @staticmethod + def attack_info(attack: str, multi_page: bool = False) -> str: + """The function to collect information and attributes of a specific + attack + + Arguments + --------- + - attacks (string): The attack to collect the information of. + - multi_page (boolean): if the item info should be made for a multi-page + wiki or not. + + Returns + ------- + A markdown string with the information about the attack. + """ + eff = None if attacks[attack]["effect"] is None \ + else getattr(effects, attacks[attack]["effect"]) + return f"""\n##{"" if multi_page else "##"} {attacks[attack]["name"]} +{attacks[attack]["desc"]} + +- Type: [{attacks[attack]["types"][0].capitalize()}]({"../types" if multi_page + else "#types"}) +- Minimum Level: {attacks[attack]["min_lvl"]} +- Attack factor: {attacks[attack]["factor"]} +- Missing chance: {attacks[attack]["miss_chance"]} +- Attack points: {attacks[attack]["ap"]} +- Effect: {"None" if eff is None else f'[{eff.c_name.capitalize()}]({"../effects" if multi_page else ""}#{eff.c_name.replace("_", "-")})'} +""" + + @staticmethod + def types(multi_page: bool = False) -> str: + """The function to add all types to the wiki. + + Arguments + --------- + - multi_page (boolean): if the item info should be made for a multi-page + wiki or not. + + Returns + ------- + A markdown string of all available types. + """ + out = f""" +#{'' if multi_page else '#'} Types +Those are all the Pokete/Attack types that are present in the game with all their (in)effectivities against other types. + +|Type|Effective against|Ineffective against| +|---|---|---| +""" + + for poke_type in types: + effective, ineffective = ("".join([i.capitalize() + (", " + if i != types[ + poke_type][j][-1] + else "") + for i in types[poke_type][j]]) + for j in ["effective", "ineffective"]) + out += f"|{poke_type.capitalize()}|{effective}|{ineffective}|\n" + + return out + '\n' + + @staticmethod + def items(multi_page: bool = False) -> str: + """The function to add all items to the wiki. + + Arguments + --------- + - multi_page (boolean): if the item info should be made for a multi-page + wiki or not. + + Returns + ------- + A markdown string that contains information about all items. + """ + return f"""#{'' if multi_page else '#'} Items +Those are all items present in the game, that can be traded or found. + +""" + '\n'.join(Wiki.item_info(item=item, multi_page=multi_page) + for item in sorted(items)) + + @staticmethod + def item_info(item: str, multi_page: bool = False) -> str: + """The function to collect information and attributes of a specific item + + Arguments + --------- + - item (string): The item to collect the information of. + - multi_page (boolean): if the item info should be made for a multi-page + wiki or not. + + Returns + ------- + A markdown string with the information about the item. + """ + return f"""##{'' if multi_page else '#'} {items[item]["pretty_name"]} +{items[item]["desc"]} + +- Price: {items[item]["price"]} +- Can be used in fights: {"Yes" if items[item]["fn"] is not None else "No"} +""" + + @staticmethod + def effects(multi_page: bool = False) -> str: + """The function to add all effects to the wiki. + + Arguments + --------- + - multi_page (boolean): if the item info should be made for a multi-page + wiki or not. + + Returns + ------- + A markdown string of all the effects in the game. + """ + if multi_page: + out = """# Effects +Those effects can be given to a Pokete through an attack. +""" + out += str.join("", [effect.ret_md() for effect in + effect_list]).replace("###", "##") + else: + out = """ +## Effects +Those effects can be given to a Pokete through an attack. +""" + out += str.join("", [effect.ret_md() for effect in effect_list]) + return out + + @staticmethod + def single(filename: str = "wiki.md") -> None: + """The function to generate a single page wiki. + + This function creates the pokete wiki in a single file and adds the + following to it: + - title + - table of contents + - all poketes with information on them + - all attacks with information on them + - all types with information on them + - all items with information on them + - all effects with information on them + + Arguments: + --------- + - filename (string): The file to save the wiki to. + """ + if QUIET or VERBOSE: + print(":: Generating wiki.md...") + md_str: str = "" + for _text, obj in zip(["page start", "table of contents", "poketes", + "attacks", "types", "items", "effects"], + [Wiki.start, Wiki.table_of_contents, Wiki.poketes, + Wiki.attacks, Wiki.types, Wiki.items, + Wiki.effects]): + if QUIET or VERBOSE: + print(f"==> Adding {_text}...") + md_str += obj() + + # writing to file + if QUIET or VERBOSE: + print("==> Writing to wiki.md...") + with open(filename, mode="w+", encoding="utf-8") as file: + file.write(md_str) + + @staticmethod + def multi(folder_name: str = "wiki") -> None: + """The function to generate the wiki in multiple pages in a folder + + This function creates the pokete wiki in a single file and adds the + following to it: + - title + - table of contents + - all poketes with information on them + - all attacks with information on them + - all types with information on them + - all items with information on them + - all effects with information on them + + Arguments: + --------- + - folder_name (string): The folder to save the wiki to. + """ + if QUIET or VERBOSE: + print(":: Generating multi-page wiki...") + print("==> Checking if old wiki exists...") + for folder in ['', '/poketes', '/attacks']: + if VERBOSE: + print(f' -> Checking "{folder_name}{folder}": ', end='') + if exists(folder_name + folder): + if not isdir(folder_name + folder): + if VERBOSE: + print("Does not exist. Making...") + os.mkdir(folder_name + folder) + else: + if VERBOSE: + print("Exists. Deleting and making new...") + else: + os.mkdir(folder_name + folder) + if VERBOSE: + print("Does not exist. Making...") + + if QUIET or VERBOSE: + print("==> Adding page start...") + if VERBOSE: + print(" -> Adding index...") + index: str = Wiki.start() + if VERBOSE: + print(" -> Adding overview...") + index += Wiki.overview(multi_page=True) + "\n---\n" + if VERBOSE: + print(" -> Adding table of contents...") + index += Wiki.table_of_contents(multi_page=True) + if VERBOSE: + print(f' -> Writing to "{folder_name}/index.md"...') + with open(f"{folder_name}/index.md", 'w') as file: + file.write(index) + + if QUIET or VERBOSE: + print("==> Adding poketes...") + if VERBOSE: + print(" -> Adding index.md...") + with open(f"{folder_name}/poketes/index.md", 'w') as file: + file.write(Wiki.poketes(page_mode='index')) + for typ in types: + with open(f"{folder_name}/poketes/{typ}.md", 'w') as file: + file.write(Wiki.poketes(page_mode='multi', pokete_type=typ)) + + if QUIET or VERBOSE: + print("==> Adding attacks...") + for page in Wiki.attacks(multi_page=True): + file_name, file_contents = page + with open(f"{folder_name}/attacks/{file_name}", 'w') as file: + file.write(file_contents) + + for name in ["types", "items", "effects"]: + if QUIET or VERBOSE: + print(f"==> Adding {name}...") + with open(f"{folder_name}/{name}.md", 'w') as file: + file.write(getattr(Wiki, name)(multi_page=True)) + + +def gen_pics(): + """The function to generate a markdown file with some example pictures.""" + if QUIET or VERBOSE: + print(":: Generating pics.md...") + md_str = """# Example pictures +""" + "\n\n".join(f"![{i}](ss/{i})" for i in sorted(os.listdir("assets/ss"))) + + # writing to file + with open("assets/pics.md", "w+") as file: + file.write(md_str) + + +def show_help(ex: str, command: str): + print(f"""{ex} {command} -- Generate a markdown wiki +Usage: + {ex} {command} [options]... + +Options: + silent:\t\tPrints no statements at all + quite:\t\tPrints only some minimal statements + verbose:\tPrints everything that it's doing + single:\t\tGenerated the `wiki.md` as a single file + multi:\t\tGenerates a folder `wiki` with the wiki files + \t\t(Warning: Links are for html pages, not markdown pages!) + pics:\t\tGenerates the `assets/pics.md` file with all sample pictures + +Flags: + --help\t\tShows help for a specific command + +Examples: + - {ex} {command} silent single verbose multi + Creates wiki.md silently and the multi-wiki verbosely + - {ex} {command} quite single multi pics + Creates wiki.md, the multi-page wiki and pics.md quitely + +Copyright (c) lxgr-linux 2024""") + + +def gen(ex: str, command: str, options: list[str], + flags: dict[str, list[str]]): + global SILENT, QUIET, VERBOSE + + if "--help" in flags: + show_help(ex, command) + elif len(options) == 0: + SILENT, QUIET, VERBOSE = False, True, False + Wiki.single() + gen_pics() + else: + for opt in options: + match opt := opt.lower(): + case "silent", "quite", "verbose": + SILENT, QUIET, VERBOSE = False, False, False + if opt == "silent": + SILENT = True + elif opt == "quite": + QUIET = True + else: + VERBOSE = True + case "single": + Wiki.single() + case "multi": + Wiki.multi("wiki") + case "pics": + gen_pics() + case _: + print( + f":: Error: Option '{opt}' not found, " + f"try `{ex} {command} help`" + ) + sys.exit(2) From 57380a9dcbb1ff644fa5338e759d4c323eada791 Mon Sep 17 00:00:00 2001 From: lxgr-linux Date: Fri, 21 Jun 2024 16:01:25 +0200 Subject: [PATCH 02/26] feat(#287): Fixed actions --- .gh-pages.json | 6 +- .github/workflows/documentation.yml | 8 +- .github/workflows/main.yml | 8 +- README.md | 5 +- assets/AppImageBuilder.yml | 3 +- gen_wiki.py | 641 ---------------------------- prepare_pages.py | 395 ----------------- util.py | 2 + util/pages.py | 24 +- util/wiki.py | 4 +- wiki.md | 4 +- 11 files changed, 26 insertions(+), 1074 deletions(-) delete mode 100755 gen_wiki.py delete mode 100644 prepare_pages.py mode change 100644 => 100755 util.py diff --git a/.gh-pages.json b/.gh-pages.json index a278a459..6e01ef77 100644 --- a/.gh-pages.json +++ b/.gh-pages.json @@ -49,16 +49,16 @@ "convert_with_pandoc": true, "new_name": "DevGuide.html" }, - "gen_wiki.py": { + "util.py": { "type": "documentation" }, "pokete.py": { "type": "documentation" }, - "prepare_pages.py": { + "pokete_general_use_fns.py": { "type": "documentation" }, - "pokete_general_use_fns.py": { + "util/": { "type": "documentation" }, "pokete_classes/": { diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index 34c6f559..bc1462b1 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -42,9 +42,9 @@ jobs: - name: Preprocess page files run: | - python3 ./prepare_pages.py before + python3 util.py prepare-pages before cp -r ./assets/ /tmp/assets - cp ./prepare_pages.py /tmp/prepare_pages.py + cp ./* /tmp/pokete - name: Switch branch to gh-pages uses: actions/checkout/@v2 with: @@ -53,7 +53,7 @@ jobs: run: | rm -rf ./assets ./wiki-multi mv '/tmp/assets/' . - python3 /tmp/prepare_pages.py after + python3 /tmp/pokete/util.py prepare-pages after # Push to github_pages - name: Release documentation run: | @@ -98,7 +98,7 @@ jobs: - name: Make multipage wiki run: | - python3 gen_wiki.py verbose single multi pics + python3 util.py wiki verbose single multi pics mkdir /tmp/gen-wiki cp -r HowToPlay.md DevGuide.md wiki.md /tmp/gen-wiki - name: Switch to wiki repository diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8e7ff676..f958e4cc 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -14,13 +14,13 @@ jobs: steps: - uses: actions/checkout@v2 - + - name: install deps run: pip3 install scrap_engine - name: gen-wiki - run: python3 ./gen_wiki.py - + run: python3 util.py wiki + - name: Commit files run: | git config --local user.name ${{ github.actor }} @@ -30,7 +30,7 @@ jobs: git add ./wiki.md git commit -m "Updated wiki" fi - + - name: Push changes # push the output folder to your repo uses: ad-m/github-push-action@master with: diff --git a/README.md b/README.md index b4ca15ee..11935a3f 100644 --- a/README.md +++ b/README.md @@ -163,8 +163,7 @@ On Windows `pynput` has to be installed too. - [Documentation for pokete_classes](https://lxgr-linux.github.io/pokete/doc/pokete_classes/index.html) - [Documentation for pokete_data](https://lxgr-linux.github.io/pokete/doc/pokete_data/index.html) -- [Documentation for the gen-wiki file](https://lxgr-linux.github.io/pokete/doc/gen_wiki.html "gen_wiki.py") -- [Documentation for the prepare_pages file](https://lxgr-linux.github.io/pokete/doc/prepare_pages.html "prepare_pages.py") +- [Documentation for the util file](https://lxgr-linux.github.io/pokete/doc/util.html) - [Documentation for the pokete_general_use_fns](https://lxgr-linux.github.io/pokete/doc/pokete_general_use_fns.html "pokete_general_use_fns.py") - [Documentation for the main file "pokete.py"](https://lxgr-linux.github.io/pokete/doc/pokete.html "pokete.py") @@ -182,7 +181,7 @@ To learn how to add more poketes/types/attacks to the game, see [the development After adding new Poketes and/or attacks you may want to run ```shell -$ ./gen_wiki.py +$ ./util.py wiki ``` to regenerate the wiki and adding them to it. diff --git a/assets/AppImageBuilder.yml b/assets/AppImageBuilder.yml index 17581adc..546e75fd 100644 --- a/assets/AppImageBuilder.yml +++ b/assets/AppImageBuilder.yml @@ -37,8 +37,7 @@ AppDir: - usr/share/man - usr/share/pokete/bash - usr/share/pokete/.git - - usr/share/pokete/prepare_pages.py - - usr/share/pokete/gen_wiki.py./ + - usr/share/pokete/util.py - usr/share/pokete/*.md - usr/share/scrap_engine - usr/share/pokete/playsound/libplaysound.dll diff --git a/gen_wiki.py b/gen_wiki.py deleted file mode 100755 index 4a1e037f..00000000 --- a/gen_wiki.py +++ /dev/null @@ -1,641 +0,0 @@ -#!/usr/bin/env python3 -"""This script generates the Pokete wiki""" -import os -from os.path import exists, isdir -import sys -import scrap_engine as se -import release -from pokete_classes.effects import effects, effect_list -from pokete_data import pokes, attacks, types, items, maps - -SILENT = False -QUIET = False -VERBOSE = True - - -class Wiki: - """The class in which wiki generation behaviour is defined""" - - @staticmethod - def start() -> str: - """The start and title of the wiki - - Returns - --- - The title of the wiki page. - """ - return f"""v{release.VERSION} - -# Pokete Wiki -This wiki/documentation is a compilation of all Poketes, attacks, and types present in the Pokete game. -The wiki can be generated using ```$ ./gen_wiki.py```. - -Use ```$ ./gen_wiki.py help``` to get more information about different wikis. - -You can find different versions of this wiki: - -- A single-page version can be found [here](wiki.md) -- A multi-page version can be found [here](https://lxgr-linux.github.io/pokete/wiki-multi/) - -""" - - @staticmethod - def overview(multi_page: bool = False) -> str: - """A short overview of what the wiki contains. - - Arguments - --------- - - multi_page (boolean): if the item info should be made for a multi-page wiki or not. - - Returns - ------- - An overview for a multi-page wiki. - """ - return "Table of contents\n" + \ - "\n".join( - f"{i + 1}. [{name.capitalize()}]({'' if multi_page else '#'}{name})" - for i, name in enumerate(["poketes", "attacks", "types", "item", - "effects"])) + "\n" - - @staticmethod - def get_name(poke): - """Returns the name of a Pokete to display in headings""" - additional = "" - if "_night" in poke: - additional = " night" - elif "_day" in poke: - additional = " day" - return pokes[poke]['name'] + additional - - @staticmethod - def table_of_contents(multi_page: bool = False) -> str: - """The table of contents of the pokete wiki - - Arguments - --------- - - multi_page (boolean): if the item info should be made for a multi-page wiki or not. - - Returns - ------- - A Table of contents for a single page wiki. - """ - out = '' - - # Table of contents - if not multi_page: - out += """## Table of contents -1. [Poketes](#poketes) -""" - for i, typ in enumerate(sorted(types)): - out += f""" {i + 1}. [{typ.capitalize()} Poketes](#{typ}-poketes)\n""" - for j, poke in enumerate([k for k in sorted(list(pokes)[1:]) if - pokes[k]["types"][0] == typ]): - out += f""" {j + 1}. [{Wiki.get_name(poke)}](#{poke.replace("_", "-")})\n""" - out += "2. [Attacks](#attacks)\n" - for i, typ in enumerate(sorted(types)): - out += f""" {i + 1}. [{typ.capitalize()} attacks](#{typ}-attacks)\n""" - for j, atc in enumerate([k for k in sorted(attacks) if - attacks[k]["types"][0] == typ]): - out += f""" {j + 1}. [{attacks[atc]["name"]}](#{attacks[atc]["name"] - .replace(" ", "-").lower()})\n""" - out += """3. [Types](#types) -4. [Items](#items) -""" - for j, item in enumerate(sorted(items)): - out += f""" {j + 1}. [{items[item]["pretty_name"]}](#{item.replace("_", "-")})\n""" - out += """5. [Effects](#effects) -""" - for j, effect in enumerate(effect_list): - out += f""" {j + 1}. [{effect.c_name.capitalize()}](#{effect.c_name.replace("_", "-")}) -""" - - else: - out += """## Table of contents -1. [Poketes](./poketes) -""" - for i, typ in enumerate(sorted(types)): - out += f""" {i + 1}. [{typ.capitalize()} Poketes](./poketes/{typ})\n""" - for j, poke in enumerate([k for k in sorted(list(pokes)[1:]) if - pokes[k]["types"][0] == typ]): - out += f""" {j + 1}. [{Wiki.get_name(poke)}](./poketes/{typ}#{poke.replace("_", "-")})\n""" - out += "2. [Attacks](./attacks)\n" - for i, typ in enumerate(sorted(types)): - out += f""" {i + 1}. [{typ.capitalize()} attacks](./attacks/{typ})\n""" - for j, atc in enumerate([k for k in sorted(attacks) if - attacks[k]["types"][0] == typ]): - out += f""" {j + 1}. [{attacks[atc]["name"]}](./attack/{typ}#{atc.replace("_", "-")})\n""" - out += """3. [Types](./types) -4. [Items](./items) -""" - for j, item in enumerate(sorted(items)): - out += f""" {j + 1}. [{items[item]["pretty_name"]}](./items#{item.replace("_", "-")})\n""" - out += """5. [Effects](./effects) -""" - for j, effect in enumerate(effect_list): - out += f""" {j + 1}. [{effect.c_name.capitalize()}](./effects#{effect.c_name.replace("_", "-")}) -""" - return out - - @staticmethod - def poketes(page_mode='single', pokete_type=None) -> str: - """The function to add all poketes and their attributes to the wiki. - - Arguments: - ---------- - - page_mode (string): Defines for what the output will be used. Can be: - - single: all poketes listed by their types with single-page links - - index: Just the index of all pokete types with multi-page links - - multi: Information about the pokete type definied in pokete_type - with multi-page links. - - pokete_type: Only necessary if page_mode is set to 'index': Then - defines the pokete type to get the information and links of. - - Returns - ------- - All poketes and their attributes as a markdown string. - """ - if page_mode == 'single': - out = """ -## Poketes -In the following all Poketes with their attributes are displayed. - -""" - for typ in sorted(types): - out += f"### {typ.capitalize()} Poketes" - for poke in [k for k in sorted(list(pokes)[1:]) if - pokes[k]["types"][0] == typ]: - if VERBOSE: - print(f' -> Adding {pokes[poke]["name"]}') - out += Wiki.poke_info(poke) - return out - elif page_mode == 'index': - out = """# Poketes -In the following all Poketes with their attributes are displayed. - -""" - for typ in sorted(types): - out += f"- [{typ.capitalize()} Poketes](./{typ})\n" - out += "\n---\n\n## All poketes sorted by their type:\n" - for typ in sorted(types): - out += f"- [{typ.capitalize()} Poketes](./{typ})\n" - for poke in [k for k in sorted(list(pokes)[1:]) if - pokes[k]["types"][0] == typ]: - out += f""" - [{pokes[poke]["name"].capitalize()}](./{typ}#{poke})\n""" - return out - elif page_mode == 'multi': - if pokete_type is not None: - out = f"# {pokete_type.capitalize()} Poketes" - for poke in [k for k in sorted(list(pokes)[1:]) if - pokes[k]["types"][0] == pokete_type]: - if poke == sorted(list(pokes)[1:])[-1]: - if VERBOSE: - print(f' `-> Adding {pokes[poke]["name"]}') - else: - if VERBOSE: - print(f' |-> Adding {pokes[poke]["name"]}') - out += Wiki.poke_info(poke=poke, multi_page=True) - return out - raise AttributeError( - "Pokete_type can not be none, if mode 'multi' is selected.") - raise AttributeError("Please select a valid page mode of: 'single'," - "'index' or 'multi'!") - - @staticmethod - def poke_info(poke: str, multi_page: bool = False) -> str: - """Generates information about a specific pokete - - Arguments: - --------- - - poke (string): The pokete to get the information of. - - multi_page (boolean): if the item info should be made for a multi-page - wiki or not. - - Returns - ------- - A markdown string of all the attributes and information of the pokete. - """ - if (evolve_pokete := pokes[poke]["evolve_poke"]) == "": - evolve_txt = "- Does not evolve\n" - else: - evolve_txt = f"""- Evolves to [{Wiki.get_name(evolve_pokete)}]({f'./{pokes[evolve_pokete]["types"][0]}' - if multi_page else ""}#{evolve_pokete.replace("_", "-")}) at level {pokes[poke]['evolve_lvl']}""" - - md_attacks = "\n + " + "\n + ".join(f"""[{attacks[atc]["name"]}]({ - f'../attacks/{attacks[atc]["types"][0].capitalize()}' - if multi_page else "" - }#{attacks[atc]["name"] - .replace(" ", "-").lower()})""" - for atc in - pokes[poke]["attacks"]) - # ico - ico_map = se.Map(4, 11, background=" ") - for ico in pokes[poke]["ico"]: - se.Text(ico["txt"], state="float", ignore=" ").add(ico_map, 0, 0) - ico = "".join("".join(arr) + "\n" for arr in ico_map.map) - - active = { - True: "Night", - False: "Day", - None: "Always", - }[pokes[poke].get("night_active")] - - md_locations = "\n + ".join(maps[i]["pretty_name"] for i in maps - if maps[i]["poke_args"] is not None - and poke in maps[i]["poke_args"]["pokes"] - or "w_poke_args" in maps[i] - and poke in maps[i]["w_poke_args"][ - "pokes"]) - - return f""" -##{'' if multi_page else '##'} {Wiki.get_name(poke)} -{pokes[poke]["desc"]} - -``` -{ico} -``` - -- Type: [{pokes[poke]["types"][0].capitalize()}]({'../types' if multi_page - else '#types'}) -- Health points: {pokes[poke]["hp"]} -- Attack factor: {pokes[poke]["atc"]} -- Defense factor: {pokes[poke]["defense"]} -- Initiative: {pokes[poke]["initiative"]} -- Missing chance: {pokes[poke]["miss_chance"]} -- Rarity: {pokes[poke]["rarity"]} -- Loosing experience: {pokes[poke]["lose_xp"]} -- Attacks:{md_attacks} -- Active: {active} -- Can be found in: - + {md_locations if md_locations != "" else "Nowhere"} -{evolve_txt} -""" - - @staticmethod - def attacks(multi_page: bool = False) -> str or list: - """The function to all attacks to the wiki. - - Arguments - --------- - - multi_page (boolean): if the item info should be made for a multi-page - wiki or not. - - Returns - ------- - A markdown string of all attacks with their attributes and informations. - """ - if multi_page: - index = """# Attacks -Those are all attacks present in the game. -""" - pages = [] - for typ in sorted(types): - if VERBOSE: - print(f" -> Adding {typ}") - index += f"\n- [{typ.capitalize()}](./{typ})" - page = f"# {typ.capitalize()} attacks" - for atc in [k for k in attacks if - attacks[k]["types"][0] == typ]: - if multi_page: - if atc == [k for k in attacks if - attacks[k]["types"][0] == typ][-1]: - if VERBOSE: - print(f' `-> Adding {attacks[atc]["name"]}') - else: - if VERBOSE: - print(f' |-> Adding {attacks[atc]["name"]}') - else: - if VERBOSE: - print(f' -> Adding {attacks[atc]["name"]}') - page += Wiki.attack_info(atc, True) - pages.append((f"{typ}.md", page)) - index += "\n\n---\n\n## All attacks sorted by their type:\n" - for typ in sorted(types): - index += f"- [{typ.capitalize()} Attacks](./{typ})\n" - for atc in [k for k in attacks if - attacks[k]["types"][0] == typ]: - index += f""" - [{attacks[atc]["name"].capitalize()}](./{typ}#{atc.replace('_', '-')})\n""" - - index += '\n' - pages.insert(0, ("index.md", index)) - return pages - out = """ -## Attacks -Those are all attacks present in the game. -""" - for typ in sorted(types): - out += f"\n### {typ.capitalize()} attacks" - for atc in [k for k in attacks if - attacks[k]["types"][0] == typ]: - if atc == \ - [k for k in attacks if attacks[k]["types"][0] == typ][ - -1]: - if VERBOSE: - print(f' `-> Adding {attacks[atc]["name"]}') - else: - if VERBOSE: - print(f' |-> Adding {attacks[atc]["name"]}') - out += Wiki.attack_info(atc) - - return out - - @staticmethod - def attack_info(attack: str, multi_page: bool = False) -> str: - """The function to collect information and attributes of a specific - attack - - Arguments - --------- - - attacks (string): The attack to collect the information of. - - multi_page (boolean): if the item info should be made for a multi-page - wiki or not. - - Returns - ------- - A markdown string with the information about the attack. - """ - eff = None if attacks[attack]["effect"] is None \ - else getattr(effects, attacks[attack]["effect"]) - return f"""\n##{"" if multi_page else "##"} {attacks[attack]["name"]} -{attacks[attack]["desc"]} - -- Type: [{attacks[attack]["types"][0].capitalize()}]({"../types" if multi_page - else "#types"}) -- Minimum Level: {attacks[attack]["min_lvl"]} -- Attack factor: {attacks[attack]["factor"]} -- Missing chance: {attacks[attack]["miss_chance"]} -- Attack points: {attacks[attack]["ap"]} -- Effect: {"None" if eff is None else f'[{eff.c_name.capitalize()}]({"../effects" if multi_page else ""}#{eff.c_name.replace("_", "-")})'} -""" - - @staticmethod - def types(multi_page: bool = False) -> str: - """The function to add all types to the wiki. - - Arguments - --------- - - multi_page (boolean): if the item info should be made for a multi-page - wiki or not. - - Returns - ------- - A markdown string of all available types. - """ - out = f""" -#{'' if multi_page else '#'} Types -Those are all the Pokete/Attack types that are present in the game with all their (in)effectivities against other types. - -|Type|Effective against|Ineffective against| -|---|---|---| -""" - - for poke_type in types: - effective, ineffective = ("".join([i.capitalize() + (", " - if i != types[ - poke_type][j][-1] - else "") - for i in types[poke_type][j]]) - for j in ["effective", "ineffective"]) - out += f"|{poke_type.capitalize()}|{effective}|{ineffective}|\n" - - return out + '\n' - - @staticmethod - def items(multi_page: bool = False) -> str: - """The function to add all items to the wiki. - - Arguments - --------- - - multi_page (boolean): if the item info should be made for a multi-page - wiki or not. - - Returns - ------- - A markdown string that contains information about all items. - """ - return f"""#{'' if multi_page else '#'} Items -Those are all items present in the game, that can be traded or found. - -""" + '\n'.join(Wiki.item_info(item=item, multi_page=multi_page) - for item in sorted(items)) - - @staticmethod - def item_info(item: str, multi_page: bool = False) -> str: - """The function to collect information and attributes of a specific item - - Arguments - --------- - - item (string): The item to collect the information of. - - multi_page (boolean): if the item info should be made for a multi-page - wiki or not. - - Returns - ------- - A markdown string with the information about the item. - """ - return f"""##{'' if multi_page else '#'} {items[item]["pretty_name"]} -{items[item]["desc"]} - -- Price: {items[item]["price"]} -- Can be used in fights: {"Yes" if items[item]["fn"] is not None else "No"} -""" - - @staticmethod - def effects(multi_page: bool = False) -> str: - """The function to add all effects to the wiki. - - Arguments - --------- - - multi_page (boolean): if the item info should be made for a multi-page - wiki or not. - - Returns - ------- - A markdown string of all the effects in the game. - """ - if multi_page: - out = """# Effects -Those effects can be given to a Pokete through an attack. -""" - out += str.join("", [effect.ret_md() for effect in - effect_list]).replace("###", "##") - else: - out = """ -## Effects -Those effects can be given to a Pokete through an attack. -""" - out += str.join("", [effect.ret_md() for effect in effect_list]) - return out - - @staticmethod - def single(filename: str = "wiki.md") -> None: - """The function to generate a single page wiki. - - This function creates the pokete wiki in a single file and adds the - following to it: - - title - - table of contents - - all poketes with information on them - - all attacks with information on them - - all types with information on them - - all items with information on them - - all effects with information on them - - Arguments: - --------- - - filename (string): The file to save the wiki to. - """ - if QUIET or VERBOSE: - print(":: Generating wiki.md...") - md_str: str = "" - for _text, obj in zip(["page start", "table of contents", "poketes", - "attacks", "types", "items", "effects"], - [Wiki.start, Wiki.table_of_contents, Wiki.poketes, - Wiki.attacks, Wiki.types, Wiki.items, - Wiki.effects]): - if QUIET or VERBOSE: - print(f"==> Adding {_text}...") - md_str += obj() - - # writing to file - if QUIET or VERBOSE: - print("==> Writing to wiki.md...") - with open(filename, mode="w+", encoding="utf-8") as file: - file.write(md_str) - - @staticmethod - def multi(folder_name: str = "wiki") -> None: - """The function to generate the wiki in multiple pages in a folder - - This function creates the pokete wiki in a single file and adds the - following to it: - - title - - table of contents - - all poketes with information on them - - all attacks with information on them - - all types with information on them - - all items with information on them - - all effects with information on them - - Arguments: - --------- - - folder_name (string): The folder to save the wiki to. - """ - if QUIET or VERBOSE: - print(":: Generating multi-page wiki...") - print("==> Checking if old wiki exists...") - for folder in ['', '/poketes', '/attacks']: - if VERBOSE: - print(f' -> Checking "{folder_name}{folder}": ', end='') - if exists(folder_name + folder): - if not isdir(folder_name + folder): - if VERBOSE: - print("Does not exist. Making...") - os.mkdir(folder_name + folder) - else: - if VERBOSE: - print("Exists. Deleting and making new...") - else: - os.mkdir(folder_name + folder) - if VERBOSE: - print("Does not exist. Making...") - - if QUIET or VERBOSE: - print("==> Adding page start...") - if VERBOSE: - print(" -> Adding index...") - index: str = Wiki.start() - if VERBOSE: - print(" -> Adding overview...") - index += Wiki.overview(multi_page=True) + "\n---\n" - if VERBOSE: - print(" -> Adding table of contents...") - index += Wiki.table_of_contents(multi_page=True) - if VERBOSE: - print(f' -> Writing to "{folder_name}/index.md"...') - with open(f"{folder_name}/index.md", 'w') as file: - file.write(index) - - if QUIET or VERBOSE: - print("==> Adding poketes...") - if VERBOSE: - print(" -> Adding index.md...") - with open(f"{folder_name}/poketes/index.md", 'w') as file: - file.write(Wiki.poketes(page_mode='index')) - for typ in types: - with open(f"{folder_name}/poketes/{typ}.md", 'w') as file: - file.write(Wiki.poketes(page_mode='multi', pokete_type=typ)) - - if QUIET or VERBOSE: - print("==> Adding attacks...") - for page in Wiki.attacks(multi_page=True): - file_name, file_contents = page - with open(f"{folder_name}/attacks/{file_name}", 'w') as file: - file.write(file_contents) - - for name in ["types", "items", "effects"]: - if QUIET or VERBOSE: - print(f"==> Adding {name}...") - with open(f"{folder_name}/{name}.md", 'w') as file: - file.write(getattr(Wiki, name)(multi_page=True)) - - -def gen_pics(): - """The function to generate a markdown file with some example pictures.""" - if QUIET or VERBOSE: - print(":: Generating pics.md...") - md_str = """# Example pictures -""" + "\n\n".join(f"![{i}](ss/{i})" for i in sorted(os.listdir("assets/ss"))) - - # writing to file - with open("assets/pics.md", "w+") as file: - file.write(md_str) - - -if __name__ == "__main__": - if len(sys.argv) == 1: - SILENT, QUIET, VERBOSE = False, True, False - Wiki.single() - gen_pics() - else: - for arg in sys.argv[1:]: - if arg.lower() in ["silent", "quite", "verbose"]: - SILENT, QUIET, VERBOSE = False, False, False - if arg.lower() == "silent": - SILENT = True - elif arg.lower() == "quite": - QUIET = True - else: - VERBOSE = True - elif arg.lower() == "single": - Wiki.single() - elif arg.lower() == "multi": - Wiki.multi("wiki") - elif arg.lower() == "pics": - gen_pics() - else: - print(f"""gen_wiki.py: - -Usage: ------- -{sys.argv[0]} OPTION1 (OPTION2 OPTION3 ...) - -Options: --------- -silent:\t\tPrints no statements at all -quite:\t\tPrints only some minimal statements -verbose:\tPrints everything that it's doing -single:\t\tGenerated the `wiki.md` as a single file -multi:\t\tGenerates a folder `wiki` with the wiki files -\t\t(Warning: Links are for html pages, not markdown pages!) -pics:\t\tGenerates the `assets/pics.md` file with all sample pictures - -Examples: ---------- -- {sys.argv[0]} silent single verbose multi -\t`-> Creates wiki.md silently and the multi-wiki verbosely -- {sys.argv[0]} quite single multi pics -\t`-> Creates wiki.md, the multi-page wiki and pics.md quitely - -Copyright (c) lxgr-linux 2021""") - if arg.lower() not in ["-h", "--help", "help"]: - sys.exit(2) diff --git a/prepare_pages.py b/prepare_pages.py deleted file mode 100644 index e23064e4..00000000 --- a/prepare_pages.py +++ /dev/null @@ -1,395 +0,0 @@ -#!/usr/bin/env python -""" -Prepare pages prepares all files in "files" for GitHub Pages - -This script takes one argument, which specifies if the actions it should take are before the command -"git switch gh-pages" or afterwards. "before" means that it will the pre-change actions and "after" the after-change -actions. - -This script processes files on how they are configured in the "files" dictionary: If the type is documentation -if will call pdoc3 to create the documentation for it. If the type is "page", the argument "convert_with_pandoc" -is a boolean which specifies, if the file should be converted into HTML by pandoc (True) or GitHub Pages' Jekyll -(False). If set to false, it is advised to set "convert_tables" to True, as Jekyll can not handle markdown tables. -Afterwards this script will replace all the links specified in the list "replace_links". There the first argument of -the Tuple specifies the old link and the second argument the new link. With "new_name" the file will be renamed on the -website. - -Usage: ------ -- python3 prepare_pages.py before - - Invokes actions before the branch switch -- python3 prepare_pages.py after - - Invokes actions after the branch switch - -Exit Codes: ----------- -- 0: Everything is OK. -- 1: An internal error occurred -- 2: The user did not specify the right/enough arguments -""" -import os -from os.path import exists -import sys -import json -from urllib import request - -""" -The files dictionary specifies how and which files should be processed. - -Structure: ---------- -- Filename or directory (directory only with type=documentation) - - type: - - page: Converts into static webpage - - documentation: calls pdoc3 to create a documentation for it - - replace_tables: Boolean: If tables should be replaced by HTML-Tables - - replace_links: A list of tuples for links th be replaced in this document - - element one: The link that should be replaced - - element two: The link that element one should be replaced with - - convert_with_pandoc: boolean: If the page should be converted with pandoc (True) or Jekyll (False) - - new_name: the new filename and the name on the website. If convert_with_pandoc is set to true, - make the extension .html. If the name should not be changed, put in None. -""" -files = {} - - -def replace_tables(_text: str) -> str: - """Replaces all markdown tables in _text with html tables - - This function writes the mardkwon table to a temporary file in /tmp/, calls pandoc to convert this file to html and - reads the text back in. - - Arguments: - --------- - - _text: The text in which all the tables should be converted. - - Returns: - ------- - The input string, but with replaced markdown tables. - """ - out = '' - table = '' - in_table = False - for line in _text.split('\n'): - if '|' in line: - in_table = True - table += line - table += '\n' - else: - if in_table: - in_table = False - with open('/tmp/pandoc_convert.md', 'w') as _f: - _f.write(table) - os.system('pandoc /tmp/pandoc_convert.md -o /tmp/pandoc_convert.html') - with open('/tmp/pandoc_convert.html', 'r') as _f: - md_text = _f.read() - table = '' - out += md_text - out += '\n' - else: - out += line - out += '\n' - return out - - -def get_header(url: str = r'https://lxgr-linux.github.io/pokete', - header_end: str = r'
') -> str: - """Gets the first part of a webpage - - Arguments: - --------- - - url: The URL to get the first part of. - - header_end: the end of the "header". - - Returns: - ------- - The start of this webpage. - """ - result = request.urlopen(url) - _text = result.read().decode('UTF-8').split(header_end)[0] - return _text + header_end + '\n' - - -def get_footer(url: str = r'https://lxgr-linux.github.io/pokete', - footer_start: str = r'
') -> str: - """Gets the last part of a webpage - - Arguments: - --------- - - url: The URL to get the last part of. - - footer_start: Where the "footer"/the end of the webpage begins. - - Returns: - ------- - The end of this webpage. - """ - result = request.urlopen(url) - _text = result.read().decode('UTF-8').split(footer_start)[1] - _text = footer_start + _text - return _text - - -def create_documentation() -> None: - """Creates documentation for all tagged files - - This function creates python documentation for all files and folders in the files dictionary that have the type - "documentation". This function will call pdoc to create the documentation for it. - """ - modules = [file for file in files if files[file]["type"] == "documentation"] - pdoc_path = "/home/runner/.local/bin/pdoc" - - for module in modules: - print(f" -> {module}") - os.system(f"{pdoc_path} --html {module} --output-dir \"/tmp/doc/\" --force") - - -def add_folder(folder: str, add_tmp_folder: bool = False) -> None: - """Creates a folder, if not does not already exist - - This function creates a folder in the current working directory. - It also creates a folder with the same name in /tmp, if needed. - - Arguments - --------- - folder: The name of the folder to create - add_tmp_folder If a folder in /tmp should be creates as well. - """ - if not os.path.isdir(folder): - os.mkdir(folder) - tmp_folder = os.path.join("/tmp", folder) - if not os.path.isdir(tmp_folder): - os.mkdir(tmp_folder) - files.update({ - folder: { - "type": "folder" - } - }) - - -def create_wiki() -> None: - """Creates a multi-page and a single-page wiki. - - This function calls the multi-page and single-page methods from the - gen_wiki file to add to the gh-pages. - """ - from gen_wiki import Wiki - Wiki.multi("./wiki-multi-md/") - Wiki.single("./wiki-single.md") - - -def add_wiki_folder(folder_name: str) -> list: - """Gives out all markdown files in current and subdirectories as a list - - This function adds all markdown files in the current directory to the list - is gives back. It also calls itself for each sub-directory and appends the - markdown files from itself to the output list as well. - - Arguments - --------- - folder_name: The folder to add - - Returns: - -------- - A list of all markdown files in the current and all subdirectories. - """ - items = os.listdir(folder_name) - out = [] - for item in items: - file = os.path.join(folder_name, item) - if os.path.isdir(file): - add_folder(file.replace("./wiki-multi-md/", "./wiki-multi-html/"), True) - for f in add_wiki_folder(file): - out.append(f) - elif os.path.isfile(file): - if item.endswith(".md"): - out.append(file) - else: - print(f"{file} is not a markdown file!") - else: - print(f"Unrecognized type: {file}") - return out - - -def add_wiki_to_files() -> None: - """Add files from multi-page wiki to files dictionary - - This function adds all markdown files from the directory ./wiki-multi-md - and its subdirectories into the files dictionary to be processed by the other functions as well. - """ - if not os.path.isdir("./wiki-multi-html"): - os.mkdir("./wiki-multi-html") - if not os.path.isdir("/tmp/wiki-multi-html"): - os.mkdir("/tmp/wiki-multi-html") - wiki_files = add_wiki_folder("./wiki-multi-md/") - print(wiki_files) - for wiki_file in wiki_files: - files.update({ - wiki_file: { - "type": "page", - "replace_tables": False, - "convert_with_pandoc": True, - "replace_links": [], - "new_name": str(wiki_file.replace(".md", ".html")).replace("./wiki-multi-md/", "./wiki-multi-html/") - } - }) - print(files) - - -def before() -> None: - """The actions that should be executed before the brach switch - - This functions creates documentation for all the files, replaces tables if necessary or converts the files with - pandoc. All the files are then moved into the /mp directory. - """ - print(':: Preparing files for gh-pages...') - print("==> Generating documentation with pdoc...") - create_documentation() - print("==> Creating Wiki...") - create_wiki() - print("==> Adding Multi-page Wiki...") - add_wiki_to_files() - for file in files.keys(): - print(f"==> Preparing {file}") - properties = files[file] - - if properties["type"] == "documentation" or properties["type"] == "folder": - continue - - new_name = properties["new_name"] if properties["new_name"] is not None else file - - # Jekyll can not handle double open/closing brackets (e.g. {{) , so we - # need to manually convert these pages. - # We do this by using pandoc and adding the start and end of the - # root page to the start and the end of the - if properties["convert_with_pandoc"]: - print(" -> Converting to html...") - os.system(f"pandoc --from gfm --to html5 -o \"{new_name}\" \"{file}\"") - - # Tables only need to be replaced, if the file is not converted with - # pandoc, as pandoc is converting the tables automatically. - elif properties["replace_tables"]: - print(" -> Replacing Tables...") - with open(file, 'r') as f: - text = f.read() - text = replace_tables(text) - with open(new_name, 'w') as f: - f.write(text) - - # If no operation was performed, we need to move the file, in order to - # not interrupt the workflow. - else: - os.system(f"mv \"{file}\" \"{new_name}\"") - - print(" -> Copying to /tmp...") - os.system(f"cp \"{new_name}\" \"/tmp/{new_name}\"") - - files[file]["new_name"] = new_name - - print("Saving configuration...") - with open('/tmp/prepare_pages_saves.py', 'w') as f: - f.write(str(files)) - - print(':: Done!') - - -def after() -> None: - """The actions that shall be executed in the gh-pages branch. - - This function copies all previously created files from /tmp/ to the current - working directory and adds the start and end of the gh-pages index website - to the files which have been converted with pandoc. This achieves a universal - look on all gh-pages pages. This function then replaces all the links for - each file. - """ - print(':: After processing files for gh-pages...') - print(':: Acquiring assets...') - print('==> header') - header = get_header(url='https://lxgr-linux.github.io/pokete', - header_end='
') - print(header) - print('==> footer') - footer = get_footer(url='https://lxgr-linux.github.io/pokete', - footer_start='
') - print(footer) - # We need to store the configuration to keep the "new_name" attribute from - # the before run. - print(":: Loading configuration...") - with open('/tmp/prepare_pages_saves.py', 'r') as f: - text = f.read() - new_files = eval(text) - - print(':: Processing files...') - print('==> Making directories...') - print(' -> wiki-multi-html') - add_folder('wiki-multi-html', False) - for file in new_files.keys(): - properties = new_files[file] - if properties["type"] == "folder": - print(' -> ' + file) - add_folder(file, False) - documentation_copied = False - for file in new_files.keys(): - properties = new_files[file] - - # Copy documentation folder from /tmp/doc/ to current directory - if properties["type"] == "documentation": - if not documentation_copied: - print("==> Copying Documentation folder...") - if exists("./doc/"): - print(" -> Removing old documentation folder...") - os.system(f"rm -rf doc") - print(" -> Copying new documentation files...") - os.system("cp -r /tmp/doc/ .") - documentation_copied = True # Only copy the directory once - continue - elif properties["type"] == "folder": - continue - - new_name = properties["new_name"] if properties["new_name"] is not None else file - print(f'==> After processing {new_name}') - - # If a file was converted with pandoc, it needs the stylesheet - # (in the header) and a footer. - if properties["convert_with_pandoc"]: - print("-> Applying Styles...") - with open(f"/tmp/{new_name}", 'r') as f: - text = f.read() - with open(new_name, 'w') as f: - f.write(header + text + footer) - else: - print(" -> Copying to current directory...") - os.system(f"cp \"/tmp/{new_name}\" .") - - # Links need to be replaced from directory and markdown direct links - # (wiki.md) into website links (./wiki) - if properties["replace_links"]: - print(" -> Replacing links...") - for old in properties["replace_links"].keys(): - new = properties["replace_links"][old] - if old != list(properties["replace_links"].keys())[-1]: - print(f" |-> Replacing {old} with {new}...") - else: - print(f" `-> Replacing {old} with {new}...") - # Need to use sed, as str.replace somehow misses some link - # changes? - os.system(f"sed -i 's#]({old}#]({new}#g' {new_name}") - print("==> Renaming 'wiki-multi-html' to 'wiki-multi'...") - os.system("mv './wiki-multi-html/' './wiki-multi'") - print(':: Done!') - - -if __name__ == '__main__': - if len(sys.argv) == 1: - print('Error! Not enough arguments:') - print(f"Usage: '{sys.argv[0]}' ") - sys.exit(2) - if sys.argv[1] == 'before': - with open('.gh-pages.json', 'r') as config_file: - files = json.loads(config_file.read()) - before() - elif 'after' == sys.argv[1]: - after() - else: - print('Error! Unrecognised first argument:') - print(f"Usage: '{sys.argv[0]}' ") - sys.exit(2) diff --git a/util.py b/util.py old mode 100644 new mode 100755 index 2f3e48e4..1ec9fd33 --- a/util.py +++ b/util.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python3 + import sys from util import parse, gen_wiki, prepare_pages diff --git a/util/pages.py b/util/pages.py index 75ba2e9d..c851958b 100644 --- a/util/pages.py +++ b/util/pages.py @@ -1,7 +1,4 @@ -#!/usr/bin/env python """ -Prepare pages prepares all files in "files" for GitHub Pages - This script takes one argument, which specifies if the actions it should take are before the command "git switch gh-pages" or afterwards. "before" means that it will the pre-change actions and "after" the after-change actions. @@ -13,19 +10,6 @@ Afterwards this script will replace all the links specified in the list "replace_links". There the first argument of the Tuple specifies the old link and the second argument the new link. With "new_name" the file will be renamed on the website. - -Usage: ------ -- python3 prepare_pages.py before - - Invokes actions before the branch switch -- python3 prepare_pages.py after - - Invokes actions after the branch switch - -Exit Codes: ----------- -- 0: Everything is OK. -- 1: An internal error occurred -- 2: The user did not specify the right/enough arguments """ import os from os.path import exists @@ -387,12 +371,16 @@ def after() -> None: def show_help(ex: str, command: str): - print(f"""{ex} {command} -- Prepare for github pages + print(f"""{ex} {command} -- Prepare pages prepares all files in "files" for GitHub Pages Usage: {ex} {command} [after|before] +Options: + before\tActions run pre branch switch + after\tActions run pre branch switch + Flags: - --help\t\tShows help for a specific command + --help\tShows help for a specific command Copyright (c) lxgr-linux 2024""") diff --git a/util/wiki.py b/util/wiki.py index 83785959..35854974 100755 --- a/util/wiki.py +++ b/util/wiki.py @@ -28,9 +28,9 @@ def start() -> str: # Pokete Wiki This wiki/documentation is a compilation of all Poketes, attacks, and types present in the Pokete game. -The wiki can be generated using ```$ ./gen_wiki.py```. +The wiki can be generated using ```$ ./util.py wiki```. -Use ```$ ./gen_wiki.py help``` to get more information about different wikis. +Use ```$ ./util.py wiki --help``` to get more information about different wikis. You can find different versions of this wiki: diff --git a/wiki.md b/wiki.md index a7abfead..78e4142b 100644 --- a/wiki.md +++ b/wiki.md @@ -2,9 +2,9 @@ v0.9.2 # Pokete Wiki This wiki/documentation is a compilation of all Poketes, attacks, and types present in the Pokete game. -The wiki can be generated using ```$ ./gen_wiki.py```. +The wiki can be generated using ```$ ./util.py wiki```. -Use ```$ ./gen_wiki.py help``` to get more information about different wikis. +Use ```$ ./util.py wiki --help``` to get more information about different wikis. You can find different versions of this wiki: From f9c1d54cd4ee950b08df91f3f6cf5e39697d15f2 Mon Sep 17 00:00:00 2001 From: lxgr-linux Date: Sun, 23 Jun 2024 00:47:31 +0200 Subject: [PATCH 03/26] feat(#287): Added automatic metainfo gen --- Changelog.md | 3 +- assets/pokete.metainfo.xml | 526 +++++++++++++++++++++++++++++++------ util.py | 4 +- util/__init__.py | 1 + util/changelog.py | 134 ++++++++++ util/release.py | 51 ++++ 6 files changed, 631 insertions(+), 88 deletions(-) create mode 100644 util/changelog.py create mode 100644 util/release.py diff --git a/Changelog.md b/Changelog.md index 1ab5c418..7aa0961d 100644 --- a/Changelog.md +++ b/Changelog.md @@ -141,7 +141,8 @@ What changed until this release? - Added multipage wiki - Completely rewrote gen_wiki.py - Reformated, moved, outsourced, chnages a lot of code - Again special thanks to MaFeLP + +Again special thanks to MaFeLP ## [0.5.1] - 2021-09-19 diff --git a/assets/pokete.metainfo.xml b/assets/pokete.metainfo.xml index 75cb9a34..6c06edf8 100644 --- a/assets/pokete.metainfo.xml +++ b/assets/pokete.metainfo.xml @@ -1,88 +1,442 @@ - + - com.github.lxgr_linux.pokete - - lxgr-linux - - MIT - GPL-3.0 - Pokete - A terminal based Pokemon like game - -

- Pokete is a small terminal based game in the style of a very popular and old game by Gamefreak. Imagine you're a Pokete-Trainer and your goal is it to run around in the world and catch/train as many Poketes as possible and to get the best trainer. -

-
- - Game - - - game - python - pokemon - console-game - - https://github.com/lxgr-linux/pokete/ - https://github.com/lxgr-linux/pokete/issues - - com.github.lxgr_linux.pokete - - com.github.lxgr_linux.pokete.desktop - - - Fight against other poketes - https://lxgr-linux.github.io/pokete/assets/ss/ss01.png - - - Conversation with a trainer on Map Route 2 - https://lxgr-linux.github.io/pokete/assets/ss/ss05.png - - - - - -

Quite a lot of bugs were fixed: Added more documentation. #278: Fixed random dor in flowytown arena. #279: Fixed warnings at startup due to new python versions. #281: Fixed trainer name conflicts

-
- https://github.com/lxgr-linux/pokete/releases/tag/0.9.2 -
- - -

Quite a lot happened until this release: Moved some NPCs out of the way. Fixed a small bug with `gen_wiki.py` on windows. Added new `first evolution` achievement. Added new Poketes (Pavous, Uberpavous, Kartmen, Kakraholt, Bablbam). Volume settings with a funky new volumeslider. A new `--no_audio` commandline option to supress all audio. Stats for Poketes. Infos about the effect an attack has. The complete game is now resizable. Reduced stack traces. This release now requires `scrap_engine` on v1.4.0. Many thanks to @ondrejmyska for your many contributions.

-
- https://github.com/lxgr-linux/pokete/releases/tag/0.9.0 -
- - -

Version 0.8.2 fixes a display bug of the release notes on flatpak. Version 0.8.1 on the other hand brought the following improvements: This version brings a new cross-platform implementation of how the audio is played, written in go. This makes the installation size of pokete significantly smaller, as less dependencies are required. The first map has been reworked, to make it easier for new players to understand the game.

-
- https://github.com/lxgr-linux/pokete/releases/tag/0.8.2 -
- - -

This version brings a new cross-platform implementation of how the audio is played, written in go. This makes the installation size of pokete significantly smaller, as less dependencies are required. The first map has been reworked, to make it easier for new players to understand the game.

-
- https://github.com/lxgr-linux/pokete/releases/tag/0.8.1 -
- - -

We are constantly developing pokete further and with version 0.8.0 added a low of improvements and new features, such as music and sound effects. Running away from wild poketes can now fail and trainers can now have more than one pokete. Controls and hotkeys can now be remapped for different keyboard layouts. The default safe-file location has been moved to .local/share and some minor bugs have been fixed as well!

-
- https://github.com/lxgr-linux/pokete/releases/tag/0.8.0 -
- - -

Preparation release for flatpaks. Includes: A svg image of the pokete logo, A metainfo.xml file for pokete -

-
- https://github.com/lxgr-linux/pokete/releases/tag/0.7.3 -
-
- - mild - mild - intense - moderate - -
- + com.github.lxgr_linux.pokete + + lxgr-linux + + MIT + GPL-3.0 + Pokete + Terminal based Pokemon like game + +

Pokete is a small terminal based game in the style of a very popular and old game by Gamefreak. Imagine you're a Pokete-Trainer and your goal is it to run around in the world and catch/train as many Poketes as possible and to get the best trainer.

+
+ + Game + + + game + python + pokemon + console-game + + https://github.com/lxgr-linux/pokete/ + https://github.com/lxgr-linux/pokete/issues + + com.github.lxgr_linux.pokete + + com.github.lxgr_linux.pokete.desktop + + + Fight against other poketes + https://lxgr-linux.github.io/pokete/assets/ss/ss01.png + + + Conversation with a trainer on Map Route 2 + https://lxgr-linux.github.io/pokete/assets/ss/ss05.png + + + + + +

Quite a lot of bugs were fixed:

+
    +
  • Added more documentation
  • +
  • #278: Fixed random dor in flowytown arena
  • +
  • #279: Fixed warnings at startup due to new python versions
  • +
  • #281: Fixed trainer name conflicts
  • +
+
+ https://github.com/lxgr-linux/pokete/releases/tag/0.9.2 +
+ + +
    +
  • Fixed a bug with fightmap not resozing
  • +
  • Did some reformating
  • +
+
+ https://github.com/lxgr-linux/pokete/releases/tag/0.9.1 +
+ + +

Quite a lot happened until this release:

+
    +
  • Moved some NPCs out of the way
  • +
  • + Fixed a small bug with + gen_wiki.py + on windows +
  • +
  • + Added new + first evolution + achievement +
  • +
  • Added new Poketes (Pavous, Uberpavous, Kartmen, Kakraholt, Bablbam)
  • +
  • Volume settings with a funky new volumeslider
  • +
  • + A new + --no_audio + commandline option to supress all audio +
  • +
  • Stats for Poketes
  • +
  • Infos about the effect an attack has
  • +
  • The complete game is now resizable
  • +
  • Reduced stack traces
  • +
+

+ This release now requires + scrap_engine + on v1.4.0 +

+

Many thanks to @ondrejmyska for your many contributions.

+
+ https://github.com/lxgr-linux/pokete/releases/tag/0.9.0 +
+ + +

Fixes a small bug in the representation of pokete on flathub.

+
+ https://github.com/lxgr-linux/pokete/releases/tag/0.8.2 +
+ + +

The distribution size was shrinked extremely compared to 0.8.0

+
    +
  • Made all wav files mp3s
  • +
  • Added new audio library and replaced playsound
  • +
  • Reduced the Appimage size
  • +
  • The first map got a bigger overhaul to make an entrance into the game easier
  • +
+
+ https://github.com/lxgr-linux/pokete/releases/tag/0.8.1 +
+ + +
    +
  • Added audio
  • +
  • Removed pynput as a dependency on windows
  • +
  • A lot of spelling and grammar fixes
  • +
  • Fixed Poketes not beeing freeable
  • +
  • Added some game ballancing
  • +
  • Trainers can now obtain more than one Pokete
  • +
  • Made run away random
  • +
  • Added remappable controls
  • +
  • Save location is now based on XDG dirs, no intervention needed
  • +
  • + Added quick attacks using + yzcv + so the attackamenu can be skipped +
  • +
+

Many thanks to everybody who contributed to this release!

+
+ https://github.com/lxgr-linux/pokete/releases/tag/0.8.0 +
+ + +

Preparation release for flatpaks. Includes:

+
    +
  • A svg image of the pokete logo
  • +
  • A metainfo.xml file for pokete
  • +
+
+ https://github.com/lxgr-linux/pokete/releases/tag/0.7.3 +
+ + +

Crucial bugfix related to natures and pokete dex.

+
+ https://github.com/lxgr-linux/pokete/releases/tag/0.7.2 +
+ + +

Just some small bugfixes.

+
+ https://github.com/lxgr-linux/pokete/releases/tag/0.7.1 +
+ + +

Under the hood

+
    +
  • Massive code reorganisation
  • +
  • + Added + PeriodicEventManager + , introducing a centralized approach to handling periodically occurring events +
  • +
  • Enabled pipenv support
  • +
+

Game design and behaviour

+
    +
  • After all Poketes are dead, players are now transported back to the last visited Pokete center
  • +
  • Multiple Poketes in a fight are now automatically possible
  • +
  • NPCs are way smarter now and support multi-answer chats
  • +
  • Added achievements visible via a submenu
  • +
  • Added commandline options
  • +
  • Several new Poketes have been added:
  • +
      +
    • Voglus
    • +
    • Ratatat
    • +
    • Crabbat
    • +
    • Rustacean
    • +
    • Saugh
    • +
    • Corcos day
    • +
    • Corcos night
    • +
    • Raupathor day
    • +
    • Raupathor night
    • +
    • Mothor
    • +
    +
  • Also the maps "Agrawos" and "Sunny Beach" have been added
  • +
  • Weather influencing effectivities has been added
  • +
  • Added notifications
  • +
  • Ingame time was added:
  • +
      +
    • Day and Night active Poketes
    • +
    • A clock
    • +
    • Time stops after a certain period of idling
    • +
    +
  • Treats and the Pokete-Care where added to make leveling easier
  • +
  • The game is now available as an AppImage
  • +
  • The newly added natures now influence a Poketes stats on an individual basis
  • +
+

This article summarises the changes further.

+

Again very special thanks to @MaFeLP for supporting me!

+
+ https://github.com/lxgr-linux/pokete/releases/tag/0.7.0 +
+ + +

What changed until this release?

+
    +
  • Added Diamondos, Dia stab,
  • +
  • Dazzle, Dia spikes
  • +
  • Added Megapois, Poison thorn
  • +
  • Added Dicko, Lil nut
  • +
  • Added Mowcow, Supercow power
  • +
  • Added Wheeto, Special smell
  • +
  • Added Flowy Town, Mowcow Meadow, The Fields of Agrawos
  • +
  • Reformated files
  • +
  • Added Github pages, special thanks to MaFeLP
  • +
  • Added validation action
  • +
  • Made the savefile json
  • +
  • Added subtypes to better organise generic attacks
  • +
  • Added Devguide
  • +
  • Added modloader
  • +
  • Added .editorconfig
  • +
  • Added Pipfile and Pipfile.lock
  • +
  • Overhauled Roadmap
  • +
  • Added multipage wiki
  • +
  • Completely rewrote gen_wiki.py
  • +
  • Reformated, moved, outsourced, chnages a lot of code
  • +
+

Again special thanks to MaFeLP

+
+ https://github.com/lxgr-linux/pokete/releases/tag/0.6.0 +
+ + +

Some minor changes due to API changes in scrap_engine v1.0.0.

+

scrap_engine v1.0.0 is now required.

+
+ https://github.com/lxgr-linux/pokete/releases/tag/0.5.1 +
+ + +

What changed until this release?

+
    +
  • Improve Help
  • +
  • Added CODENAME: Grey Edition
  • +
  • Now unvisited maps names are not displayed in Roadmap anymore
  • +
  • Added question when exiting
  • +
  • Added startuptime to savefile
  • +
  • Added Route 7
  • +
  • Added coloured Minimap
  • +
  • Added Spikes, Bubble gun,
  • +
  • Flame throw, Toe breaker, Wind blow, Storm gust, Rock smash
  • +
  • Added Dicki, Dick energy,
  • +
  • Ground hit, Hiding
  • +
  • Added Schmetterling, Schmetter
  • +
  • Added abbility to learn a new attack very fifth level
  • +
  • Added second type
  • +
  • Added savable attacks
  • +
  • Added Poison Type
  • +
  • Added Learn Discs that can be used to teach new attack to Poketes
  • +
  • Added abilities
  • +
  • Added flying
  • +
  • scrap_engine v0.3.3 is now needed
  • +
+
+ https://github.com/lxgr-linux/pokete/releases/tag/0.5.0 +
+ + +

What changed until this release?

+
    +
  • Added EffectFreezing
  • +
  • Added ice Poketes (Cubl, Spikl) andattacks (freeze, Snow storm, Sword of ice)
  • +
  • Added some more new Poketes (Confuso, Poisopla) andattacks (Confusion, Posion spores, Root slap)
  • +
  • Added shiny Poketes
  • +
  • Outsourced all map information to maps.py
  • +
  • Added version checking to warn about data loss when downgrading
  • +
  • Sorted the Poketes and attacks in the wiki by types
  • +
  • Fixed the effectivity of EffectBurning
  • +
  • Fixed logic bug in most effects, so that some types are not affected by some effects
  • +
  • Added Pokete dex for the user to keep track of all Pokete 'races' they have ever caught regardless of wether or notthe Poketes are in the deck or not
  • +
  • Cleaned up save file to be more readable for humans
  • +
  • Changed development flow
  • +
+
+ https://github.com/lxgr-linux/pokete/releases/tag/0.4.1 +
+ + +

What changed until this release?

+
    +
  • Added confirmation for running away
  • +
  • Made playmap_1 way easier
  • +
  • Changed attack list to start with 1 and not 0
  • +
  • Renamed attacs to attacks
  • +
  • Added several new attacks
  • +
  • Added several new moves (downgrade...)
  • +
  • Added Rock-ville
  • +
  • Added new mechanic that moves movemap to ensure all text fits on movemap
  • +
  • Fixed bug with exclamations out of movemap
  • +
  • Added support for more than one move per attack
  • +
  • Increased attack AP to avoid running back to the Pokete-center as often
  • +
  • Changed roadmap mechanism
  • +
  • Added effects
  • +
  • Added coloured output for OutP (scrap_engine >= v0.3.1 is now needed)
  • +
  • Fixed bug with saving in shops
  • +
  • Fixed bug with moves when confused
  • +
  • Outsourced general-use functions
  • +
  • Made some functions a class
  • +
  • Made some other quality of life changes
  • +
+
+ https://github.com/lxgr-linux/pokete/releases/tag/0.4.0 +
+ + +

What changed until this release?

+
    +
  • Added coloured type tags and attack labels
  • +
  • Added ice type
  • +
  • Added about
  • +
  • Added a now Pokete
  • +
  • Made some minor fixes and changes
  • +
+
+ https://github.com/lxgr-linux/pokete/releases/tag/0.3.8 +
+ + +

What changed until this release?

+
    +
  • Added trading with other players in the same network
  • +
  • Simplified some code
  • +
+
+ https://github.com/lxgr-linux/pokete/releases/tag/0.3.7 +
+ + +

What changed until this release?

+
    +
  • scrap_engine 0.3.0 in now needed
  • +
  • Added initiative attribute for Poketes to determine which Pokete attacks first
  • +
  • Several minor fixed and additions
  • +
+
+ https://github.com/lxgr-linux/pokete/releases/tag/0.3.6 +
+ + +

What changed until this release?

+
    +
  • Compatibility with scrap_engine 0.2.0
  • +
  • Added validation for pokete_data
  • +
  • Added Intro
  • +
+
+ https://github.com/lxgr-linux/pokete/releases/tag/0.3.5 +
+ + +

What changed until this release?

+
    +
  • Added Changelog.md
  • +
  • Added Route 6, bigmountain see and bigmountain cave
  • +
  • Improved wiki.md
  • +
  • Added Wolfiro
  • +
  • Added saving Poketeballs
  • +
  • Added some new attacks
  • +
  • Fixed some bugs
  • +
+
+ https://github.com/lxgr-linux/pokete/releases/tag/0.3.4 +
+ + +

What changed until this release?

+
    +
  • Trainers are now more likely to use effective attacks
  • +
  • Added autosave
  • +
  • Added a proper settings system
  • +
  • Added undead type
  • +
  • Added some new Poketes and attacks
  • +
  • Added HowToPlay.md
  • +
  • Added trainer saving
  • +
  • Added Route 5
  • +
  • Added confirmation texts when doing sensible stuff
  • +
  • Moved some stuff around
  • +
  • Fixed some bugs
  • +
+
+ https://github.com/lxgr-linux/pokete/releases/tag/0.3.3 +
+ + +

What changed until this release?

+
    +
  • Added route 3
  • +
  • Added route 4
  • +
  • Added Deepest forest
  • +
  • minor fixes
  • +
  • Added pics
  • +
  • Fixed some values
  • +
  • Fixed some bugs with trainers
  • +
+
+ https://github.com/lxgr-linux/pokete/releases/tag/0.3.2 +
+ + +

What changed until this release?

+
    +
  • Added Abandoned village
  • +
  • Added clampi
  • +
  • Added more NPCs
  • +
  • Added .desktop (MaFeLP) and logo
  • +
  • Made additions to the item system
  • +
+
+ https://github.com/lxgr-linux/pokete/releases/tag/0.3.1 +
+ + +

This is the first real release of Pokete, because at this point most of the key game mechanics are implemented and most

+

stuff that's still missing is just game content.

+
+ https://github.com/lxgr-linux/pokete/releases/tag/0.3.0 +
+
+ + mild + mild + intense + moderate + + \ No newline at end of file diff --git a/util.py b/util.py index 1ec9fd33..a8055aa5 100755 --- a/util.py +++ b/util.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import sys -from util import parse, gen_wiki, prepare_pages +from util import parse, gen_wiki, prepare_pages, make_release def show_help(name: str): @@ -34,6 +34,8 @@ def main(): gen_wiki(*arg_tup) case "prepare-pages": prepare_pages(*arg_tup) + case "release": + make_release(*arg_tup) case _: if "--help" in flags: show_help(args[0]) diff --git a/util/__init__.py b/util/__init__.py index 734da6a4..23873aa6 100644 --- a/util/__init__.py +++ b/util/__init__.py @@ -1,3 +1,4 @@ from .arguments import parse from .wiki import gen as gen_wiki from .pages import prepare as prepare_pages +from .release import main as make_release diff --git a/util/changelog.py b/util/changelog.py new file mode 100644 index 00000000..444a7524 --- /dev/null +++ b/util/changelog.py @@ -0,0 +1,134 @@ +import re +import xml.dom.minidom + +RawRelease = tuple[str, list[str]] +RawReleases = list[RawRelease] + +LIST_STARTERS = ("- ", "+ ") + + +def __get_raw_releases(content) -> RawReleases: + raw_releases: RawReleases = [] + for line in content.split("\n"): + if line.startswith("## "): + raw_releases.append((line, [])) + elif len(raw_releases) != 0: + raw_releases[-1][1].append(line) + return raw_releases + + +def __parse_line(line: str, idx=0, in_code_block=False, illegal_link="") -> str: + if idx == len(line): + return "" + this_segment = "" + segment = line[idx] + if segment == "`": + if in_code_block: + this_segment += "" + in_code_block = False + else: + this_segment += "" + in_code_block = True + elif segment == "[": + illegal_link += segment + elif illegal_link: + if segment == ")" and "]" in illegal_link: + this_segment += illegal_link.split("[")[1].split("]")[0] + illegal_link = "" + elif segment != "(" and illegal_link[-1] == "]": + this_segment += illegal_link + illegal_link = "" + else: + illegal_link += segment + else: + this_segment += segment + + return (this_segment + __parse_line( + line, idx + 1, in_code_block, illegal_link + )).replace("", "") + + +def __parse_markup( + lines: list[str], idx: int = 0, ul_depth: int = 0, + curr_ul_sep="", curr_line_depth=0 +) -> str: + if idx == len(lines): + return "" + parsed_line = "" + line = lines[idx].lstrip() + line_depth = len(lines[idx]) - len(line) + if line.startswith(LIST_STARTERS): + ul_sep = line[0:2] + if ul_sep != curr_ul_sep: + curr_ul_sep = ul_sep + if line_depth >= curr_line_depth: + ul_depth += 1 + parsed_line += "
    " + else: + ul_depth -= 1 + parsed_line += "
" + parsed_line += f"
  • {__parse_line(line.lstrip(ul_sep))}
  • " + elif line_depth == curr_line_depth + 2 and curr_ul_sep != "": + parsed_line += f"{__parse_line(line)}" + else: + line = line.lstrip("#") + if ul_depth != 0: + parsed_line += "" * ul_depth + ul_depth = 0 + curr_ul_sep = "" + if line.strip() != "": + parsed_line += f"

    {__parse_line(line)}

    " + + return ( + parsed_line + + __parse_markup( + lines, idx + 1, ul_depth, + curr_ul_sep, line_depth + ) + ).replace("", "") + + +def __parse_version_date(heading: str) -> tuple[str, str]: + heading = heading.strip("##").strip() + version_sub, date = heading.split(" - ") + + return version_sub.split("[")[1].split("]")[0].strip(), date.strip() + + +def __parse_release_xml(release: tuple[str, list[str]]) -> str: + version, date = __parse_version_date(release[0]) + + markup = __parse_markup(release[1]) + + urgency = "medium" if version.endswith(".0") else "low" + + return f""" + + {markup} + + https://github.com/lxgr-linux/pokete/releases/tag/{version} +""" + + +def __get_full_releases(releases: list[str]): + return f""" + {"\n".join(releases)} +""" + + +def write_changelog(): + with open("Changelog.md", "r") as changelog_file: + changelog_content = changelog_file.read() + raw_releases = __get_raw_releases(changelog_content) + releases = [__parse_release_xml(r) for r in raw_releases] + full_releases = __get_full_releases(releases) + with open("assets/pokete.metainfo.xml", "r") as metainfo_file: + content = metainfo_file.read() + new_content = re.sub(r'.*?', full_releases, + content, flags=re.DOTALL) + with open("assets/pokete.metainfo.xml", "w") as metainfo_file: + metainfo_file.write( + "\n".join(line for line in xml.dom.minidom.parseString( + new_content.replace("\n", "") + ).toprettyxml().split("\n") if line.strip()) + ) diff --git a/util/release.py b/util/release.py new file mode 100644 index 00000000..e2fd8521 --- /dev/null +++ b/util/release.py @@ -0,0 +1,51 @@ +import re +import sys + +from util.changelog import write_changelog + +TAG_REGEX = r"^v([0-9]+)\.([0-9]+)\.([0-9]+)(-[0-9A-Za-z-]+)?$" + + +def __release(tag: str): + write_changelog() + pass + + +def __is_tag_valid(tag: str) -> bool: + return re.fullmatch(TAG_REGEX, tag) is not None + + +def show_help(ex: str, command: str): + print(f"""{ex} {command} -- Prepare all relevant files for release +Usage: + {ex} {command} [tag] + +Tags have to follow the `vMAJOR.MINOR.PATCH-RELEASE` semantic. + +Flags: + --help\t\tShows help for a specific command + +Copyright (c) lxgr-linux 2024""") + + +def main( + ex: str, command: str, options: list[str], + flags: dict[str, list[str]] +): + if "--help" in flags: + show_help(ex, command) + elif len(options) == 0: + print( + ":: Error: Not enough arguments, a tag has to be given, " + f"try `{ex} {command} help`" + ) + sys.exit(2) + else: + tag = options[0] + if not __is_tag_valid(tag): + print( + ":: Error: Invalid tag, " + f"try `{ex} {command} help`" + ) + sys.exit(2) + __release(tag) From 0e3b71b777833420c89caeb38776d1ceda1c42df Mon Sep 17 00:00:00 2001 From: lxgr-linux Date: Sun, 23 Jun 2024 01:19:21 +0200 Subject: [PATCH 04/26] feat(#287): Fixed appstream issues --- assets/pokete.metainfo.xml | 30 +++++++++++++----------------- util/changelog.py | 8 +++++++- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/assets/pokete.metainfo.xml b/assets/pokete.metainfo.xml index 6c06edf8..1c542a13 100644 --- a/assets/pokete.metainfo.xml +++ b/assets/pokete.metainfo.xml @@ -177,27 +177,23 @@
  • Added achievements visible via a submenu
  • Added commandline options
  • Several new Poketes have been added:
  • -
      -
    • Voglus
    • -
    • Ratatat
    • -
    • Crabbat
    • -
    • Rustacean
    • -
    • Saugh
    • -
    • Corcos day
    • -
    • Corcos night
    • -
    • Raupathor day
    • -
    • Raupathor night
    • -
    • Mothor
    • -
    +
  • Voglus
  • +
  • Ratatat
  • +
  • Crabbat
  • +
  • Rustacean
  • +
  • Saugh
  • +
  • Corcos day
  • +
  • Corcos night
  • +
  • Raupathor day
  • +
  • Raupathor night
  • +
  • Mothor
  • Also the maps "Agrawos" and "Sunny Beach" have been added
  • Weather influencing effectivities has been added
  • Added notifications
  • Ingame time was added:
  • -
      -
    • Day and Night active Poketes
    • -
    • A clock
    • -
    • Time stops after a certain period of idling
    • -
    +
  • Day and Night active Poketes
  • +
  • A clock
  • +
  • Time stops after a certain period of idling
  • Treats and the Pokete-Care where added to make leveling easier
  • The game is now available as an AppImage
  • The newly added natures now influence a Poketes stats on an individual basis
  • diff --git a/util/changelog.py b/util/changelog.py index 444a7524..c54c8e4c 100644 --- a/util/changelog.py +++ b/util/changelog.py @@ -59,7 +59,11 @@ def __parse_markup( line_depth = len(lines[idx]) - len(line) if line.startswith(LIST_STARTERS): ul_sep = line[0:2] - if ul_sep != curr_ul_sep: + if curr_ul_sep == "": + curr_ul_sep = ul_sep + ul_depth += 1 + parsed_line += "
      " + '''if ul_sep != curr_ul_sep: curr_ul_sep = ul_sep if line_depth >= curr_line_depth: ul_depth += 1 @@ -67,6 +71,8 @@ def __parse_markup( else: ul_depth -= 1 parsed_line += "
    " + # Since Appstream does not support nested lists ind their standart, this is left out + ''' parsed_line += f"
  • {__parse_line(line.lstrip(ul_sep))}
  • " elif line_depth == curr_line_depth + 2 and curr_ul_sep != "": parsed_line += f"{__parse_line(line)}" From 7ce95071b386d772e42ff825de88a7708268234b Mon Sep 17 00:00:00 2001 From: lxgr-linux Date: Sun, 23 Jun 2024 01:30:02 +0200 Subject: [PATCH 05/26] feat(#287): Fixed encoding issues --- assets/pokete.metainfo.xml | 2 +- util/changelog.py | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/assets/pokete.metainfo.xml b/assets/pokete.metainfo.xml index 1c542a13..1584c2d2 100644 --- a/assets/pokete.metainfo.xml +++ b/assets/pokete.metainfo.xml @@ -1,4 +1,4 @@ - + com.github.lxgr_linux.pokete diff --git a/util/changelog.py b/util/changelog.py index c54c8e4c..cc284951 100644 --- a/util/changelog.py +++ b/util/changelog.py @@ -134,7 +134,12 @@ def write_changelog(): content, flags=re.DOTALL) with open("assets/pokete.metainfo.xml", "w") as metainfo_file: metainfo_file.write( - "\n".join(line for line in xml.dom.minidom.parseString( - new_content.replace("\n", "") - ).toprettyxml().split("\n") if line.strip()) + "\n".join( + line for line in xml.dom.minidom.parseString( + new_content.replace("\n", "") + ) + .toprettyxml(encoding="UTF-8") + .decode("UTF-8") + .split("\n") + if line.strip()) ) From 0e4820d47823dacaa35989e94661eb8334c1fc05 Mon Sep 17 00:00:00 2001 From: lxgr-linux Date: Sun, 23 Jun 2024 01:31:53 +0200 Subject: [PATCH 06/26] feat(#287): Fixed editor config --- .editorconfig | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.editorconfig b/.editorconfig index 24448d86..f98fda1b 100644 --- a/.editorconfig +++ b/.editorconfig @@ -15,6 +15,9 @@ indent_size = 4 tab_width = 4 max_line_length = 80 +[*.xml] +indent_style = tab + [pokete_data/{map_data,npcs}.py] max_line_length = off From 1ee3c06eefb7467fa4aa8eeed1b8c3418042ae8d Mon Sep 17 00:00:00 2001 From: lxgr-linux Date: Sun, 23 Jun 2024 11:53:32 +0200 Subject: [PATCH 07/26] feat(#287): Cleaned up the icon situation --- ...chirmfoto_2021-06-04_09-04-44 (Kopie 1).kra~ | Bin 33845 -> 0 bytes assets/Bildschirmfoto_2021-06-04_09-04-44.png | Bin 3120 -> 0 bytes assets/pokete.desktop | 2 +- ...04_09-04-44 (Kopie 1).kra => pokete.png.kra} | Bin ...o_2021-06-04_09-04-44.kra => pokete_old.kra} | Bin util/changelog.py | 3 ++- 6 files changed, 3 insertions(+), 2 deletions(-) delete mode 100644 assets/Bildschirmfoto_2021-06-04_09-04-44 (Kopie 1).kra~ delete mode 100644 assets/Bildschirmfoto_2021-06-04_09-04-44.png rename assets/{Bildschirmfoto_2021-06-04_09-04-44 (Kopie 1).kra => pokete.png.kra} (100%) rename assets/{Bildschirmfoto_2021-06-04_09-04-44.kra => pokete_old.kra} (100%) diff --git a/assets/Bildschirmfoto_2021-06-04_09-04-44 (Kopie 1).kra~ b/assets/Bildschirmfoto_2021-06-04_09-04-44 (Kopie 1).kra~ deleted file mode 100644 index ce561d153ce0e278d5b1a172f31d90e212baf319..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 33845 zcmeIb1z23kwkX`)xN8VbW5M0EaS0mSB{&2N?(PIgu;2s|AOs8UP9Q)aXpjIMB)A8+ z*JNhSnVEaexpVIK-goc)e+qVW)v8@<@4a@_lB%_u`yTxW|<6!P+#_DPRBw54IafTh=Z?}B!vUA`-S|W&HT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21eUI>qN%JR<(rPsSXf$Z~ggw#Sh3`mx z*SP+dcc*r@dpf$h({3yM$s?6GFEveeOH}qeK~>0G(@Qr&Ri0j3dcZL=syoi{Kaf|t ziWzMmvo{RR3+?24&^ofamzpjDVfhorxVq*l0%#P-f4 zDOg1pGSxzUY#85Hg_N~&xQ zepuzg)K&6S5@RcoJz|htd?U@uyumP ztdy*jt%lR>^M!1WEhgDgRf{BX!R*38#^Ve*db`zpO)I-On3c^CEl9R!vn{5WNmUOj=!1q5a_o;Q9nQsOF^c?^+noI!S#lEfG~R7Rv{%5##d9r> zyQ}z|xKr?ZeKkbFI*ymMZPD4x*3H@7het+N&b>K%c*B&OcqBfUrtF`>RJ2ZZLN^qk zu{ol*6U>g+fP_aFD`q8W)g3RC`CVYs3$8eRg0Io1baJ}}bHe*=ijd3D7{V~+t%y}o_-OZi2w-2y1i>OPFr+E6vJ z*0#O6FIF|@8Lx&WHr~Cy#!YE}Ti+NvhpenL=MY`?+-?sKke61LDw8k?zI7@8y|%Ba z00fc4;RBFifAC2YYOnU-3JGE7Ptoe!ovW%!K$E zfUuY*NEsH}o7yL%&-;X({!2w_*vhSc-qiljwST`W?QfU8y*BJ- zVGCIQZrAibSG+w5bQ{6K?WVQA1)87|7@mJ`3)?^A{{6y|w_Dc!7HEP{VOxCtW87SS zM)Lb5ByZQC{4LM~`Lq91B!5_u^3NE5{~f{Y(v!ahnxN@_ff4rgz`sIt``N*7fhOny xY}w_%Ki{7|LijV9-#5Zrlk>Mg6Xfjn9}G}c1%#hgCMp0GPyl;zUO!vo{{c+j-vIys diff --git a/assets/Bildschirmfoto_2021-06-04_09-04-44.png b/assets/Bildschirmfoto_2021-06-04_09-04-44.png deleted file mode 100644 index 7365beedeafee34a10a6badde4f5127e8a664fc3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3120 zcmbtXc{H2p8V}Q!j*E_CC{@~Cbd;b?5xcgGB|(b{VmBz2SW;q%prcd`##E@K++KSH z6&hkG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Bd1AuB7pboil7`SQ#SU0BRev2l`_S!k)VX;SpfUkzQ|-7hND zuhO5YOQkKeWu&I24m>>5OU_BZcaO?=LWxGQHIIebiiwD7A?9{#TU!m-ghGels3_W` zv{c5oGto?OV^5~SY;90BnA%5h&1A7yN;poEq875(raCD}$QT;&;jZ9;XKjoG(BvK& z2J0OA z+$^-LG*WX5fwrk$Tnxf6?~+%Ls-d>&L>C<$of9TO02*6brYd4@-Qr;GbCQ8s9{ei= zu8R<-BSg%A{7shkUk)RThPydC(}sutm1CoN9~dWe`=KX{U&)e|f&?}y>Rfq1KtTTt z`LKWqXeocpo)U`$CZ1R diff --git a/assets/pokete.desktop b/assets/pokete.desktop index f01bc27b..4bd781aa 100755 --- a/assets/pokete.desktop +++ b/assets/pokete.desktop @@ -4,7 +4,7 @@ Type=Application Name=Pokete Comment=A terminal based Pokemon clone, based on the scrap engine. Exec=/usr/bin/pokete.py -Icon=/usr/share/pokete/assets/pokete.png +Icon=/usr/share/pokete/assets/pokete.svg Terminal=true StartupNotify=false Categories=Game; diff --git a/assets/Bildschirmfoto_2021-06-04_09-04-44 (Kopie 1).kra b/assets/pokete.png.kra similarity index 100% rename from assets/Bildschirmfoto_2021-06-04_09-04-44 (Kopie 1).kra rename to assets/pokete.png.kra diff --git a/assets/Bildschirmfoto_2021-06-04_09-04-44.kra b/assets/pokete_old.kra similarity index 100% rename from assets/Bildschirmfoto_2021-06-04_09-04-44.kra rename to assets/pokete_old.kra diff --git a/util/changelog.py b/util/changelog.py index cc284951..1d2fa914 100644 --- a/util/changelog.py +++ b/util/changelog.py @@ -141,5 +141,6 @@ def write_changelog(): .toprettyxml(encoding="UTF-8") .decode("UTF-8") .split("\n") - if line.strip()) + if line.strip() + ) ) From 989f389934a93978dd8c45127c69789e8604b28b Mon Sep 17 00:00:00 2001 From: lxgr-linux Date: Sun, 23 Jun 2024 14:08:09 +0200 Subject: [PATCH 08/26] feat(#287): Added install script --- assets/pokete.desktop | 10 -- assets/pokete.svg | 268 ------------------------------------------ 2 files changed, 278 deletions(-) delete mode 100755 assets/pokete.desktop delete mode 100644 assets/pokete.svg diff --git a/assets/pokete.desktop b/assets/pokete.desktop deleted file mode 100755 index 4bd781aa..00000000 --- a/assets/pokete.desktop +++ /dev/null @@ -1,10 +0,0 @@ -[Desktop Entry] -Version=1.0 -Type=Application -Name=Pokete -Comment=A terminal based Pokemon clone, based on the scrap engine. -Exec=/usr/bin/pokete.py -Icon=/usr/share/pokete/assets/pokete.svg -Terminal=true -StartupNotify=false -Categories=Game; diff --git a/assets/pokete.svg b/assets/pokete.svg deleted file mode 100644 index 4f42bf5e..00000000 --- a/assets/pokete.svg +++ /dev/null @@ -1,268 +0,0 @@ - - - -> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From 9828228cf6cb0681635ba4a487e8f24c6401cf6f Mon Sep 17 00:00:00 2001 From: lxgr-linux Date: Sun, 23 Jun 2024 14:08:16 +0200 Subject: [PATCH 09/26] feat(#287): Added install script --- assets/com.github.lxgr-linux.pokete.desktop | 10 + assets/com.github.lxgr-linux.pokete.svg | 268 ++++++++++++++++++++ util/install.py | 0 util/install.sh | 12 + 4 files changed, 290 insertions(+) create mode 100755 assets/com.github.lxgr-linux.pokete.desktop create mode 100644 assets/com.github.lxgr-linux.pokete.svg create mode 100644 util/install.py create mode 100755 util/install.sh diff --git a/assets/com.github.lxgr-linux.pokete.desktop b/assets/com.github.lxgr-linux.pokete.desktop new file mode 100755 index 00000000..acae60ae --- /dev/null +++ b/assets/com.github.lxgr-linux.pokete.desktop @@ -0,0 +1,10 @@ +[Desktop Entry] +Version=1.0 +Type=Application +Name=Pokete +Comment=A terminal based Pokemon clone, based on the scrap engine. +Exec=/usr/bin/pokete.py +Icon=com.github.lxgr-linux.pokete +Terminal=true +StartupNotify=false +Categories=Game; diff --git a/assets/com.github.lxgr-linux.pokete.svg b/assets/com.github.lxgr-linux.pokete.svg new file mode 100644 index 00000000..4f42bf5e --- /dev/null +++ b/assets/com.github.lxgr-linux.pokete.svg @@ -0,0 +1,268 @@ + + + +> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/util/install.py b/util/install.py new file mode 100644 index 00000000..e69de29b diff --git a/util/install.sh b/util/install.sh new file mode 100755 index 00000000..aaba8812 --- /dev/null +++ b/util/install.sh @@ -0,0 +1,12 @@ +dest=$1 + +install -Dv assets/com.github.lxgr-linux.pokete.desktop "$dest/share/applications/com.github.lxgr-linux.pokete.desktop" +install -Dv assets/com.github.lxgr-linux.pokete.svg "$dest/share/icons/hicolor/scalable/apps/com.github.lxgr_linux.pokete.svg" +install -Dv assets/pokete.metainfo.xml "$dest/share/metainfo/com.github.lxgr_linux.pokete.metainfo.xml" +install -Dv LICENSE "$dest/share/licenses/com.github.lxgr_linux.pokete/LICENSE" +install -dv "$dest/bin/" +find . | grep -E "\.py$|\.so$|\.mp3$" | while read file +do + install -Dv "$file" "$dest/share/pokete/$file" +done +ln -s "../share/pokete/pokete.py" "$dest/bin/" From 426944762b3693d59f72cd67fea3129de17cf3c1 Mon Sep 17 00:00:00 2001 From: lxgr-linux Date: Sun, 23 Jun 2024 14:33:44 +0200 Subject: [PATCH 10/26] feat(#287): Fixed icon --- util/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/install.sh b/util/install.sh index aaba8812..f2e7bb2b 100755 --- a/util/install.sh +++ b/util/install.sh @@ -1,7 +1,7 @@ dest=$1 install -Dv assets/com.github.lxgr-linux.pokete.desktop "$dest/share/applications/com.github.lxgr-linux.pokete.desktop" -install -Dv assets/com.github.lxgr-linux.pokete.svg "$dest/share/icons/hicolor/scalable/apps/com.github.lxgr_linux.pokete.svg" +install -Dvm644 assets/com.github.lxgr-linux.pokete.svg "$dest/share/icons/hicolor/scalable/apps/com.github.lxgr-linux.pokete.svg" install -Dv assets/pokete.metainfo.xml "$dest/share/metainfo/com.github.lxgr_linux.pokete.metainfo.xml" install -Dv LICENSE "$dest/share/licenses/com.github.lxgr_linux.pokete/LICENSE" install -dv "$dest/bin/" From aff2fb51580f6e620ec04bd0a2ae5c78d95856fc Mon Sep 17 00:00:00 2001 From: lxgr-linux Date: Sun, 23 Jun 2024 14:52:38 +0200 Subject: [PATCH 11/26] feat(#287): Added install.py --- ...p => com.github.lxgr_linux.pokete.desktop} | 2 +- ...e.svg => com.github.lxgr_linux.pokete.svg} | 0 util.py | 4 ++- util/__init__.py | 1 + util/install.py | 28 +++++++++++++++++++ util/install.sh | 9 +++--- util/release.py | 6 ++-- util/wiki.py | 2 +- 8 files changed, 42 insertions(+), 10 deletions(-) rename assets/{com.github.lxgr-linux.pokete.desktop => com.github.lxgr_linux.pokete.desktop} (85%) rename assets/{com.github.lxgr-linux.pokete.svg => com.github.lxgr_linux.pokete.svg} (100%) diff --git a/assets/com.github.lxgr-linux.pokete.desktop b/assets/com.github.lxgr_linux.pokete.desktop similarity index 85% rename from assets/com.github.lxgr-linux.pokete.desktop rename to assets/com.github.lxgr_linux.pokete.desktop index acae60ae..f3bc02d3 100755 --- a/assets/com.github.lxgr-linux.pokete.desktop +++ b/assets/com.github.lxgr_linux.pokete.desktop @@ -4,7 +4,7 @@ Type=Application Name=Pokete Comment=A terminal based Pokemon clone, based on the scrap engine. Exec=/usr/bin/pokete.py -Icon=com.github.lxgr-linux.pokete +Icon=com.github.lxgr_linux.pokete Terminal=true StartupNotify=false Categories=Game; diff --git a/assets/com.github.lxgr-linux.pokete.svg b/assets/com.github.lxgr_linux.pokete.svg similarity index 100% rename from assets/com.github.lxgr-linux.pokete.svg rename to assets/com.github.lxgr_linux.pokete.svg diff --git a/util.py b/util.py index a8055aa5..4a924e8a 100755 --- a/util.py +++ b/util.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import sys -from util import parse, gen_wiki, prepare_pages, make_release +from util import parse, gen_wiki, prepare_pages, make_release, install def show_help(name: str): @@ -36,6 +36,8 @@ def main(): prepare_pages(*arg_tup) case "release": make_release(*arg_tup) + case "install": + install(*arg_tup) case _: if "--help" in flags: show_help(args[0]) diff --git a/util/__init__.py b/util/__init__.py index 23873aa6..00625e28 100644 --- a/util/__init__.py +++ b/util/__init__.py @@ -2,3 +2,4 @@ from .wiki import gen as gen_wiki from .pages import prepare as prepare_pages from .release import main as make_release +from .install import install diff --git a/util/install.py b/util/install.py index e69de29b..91b95021 100644 --- a/util/install.py +++ b/util/install.py @@ -0,0 +1,28 @@ +import os +import sys + + +def show_help(ex: str, command: str): + print(f"""{ex} {command} -- Install pokete to a given directory +Usage: + {ex} {command} [dest] + +Flags: + --help\tShows help for a specific command + +Copyright (c) lxgr-linux 2024""") + + +def install(ex: str, command: str, options: list[str], + flags: dict[str, list[str]]): + if "--help" in flags: + show_help(ex, command) + elif len(options) == 0: + print( + ":: Error: Not enough arguments, a destination has to be given, " + f"try `{ex} {command} --help`" + ) + sys.exit(2) + else: + dest = options[0] + print(os.popen(f'sh -c "./util/install.sh {dest}"').read()) diff --git a/util/install.sh b/util/install.sh index f2e7bb2b..4712c40d 100755 --- a/util/install.sh +++ b/util/install.sh @@ -1,9 +1,10 @@ dest=$1 +app_id="com.github.lxgr_linux.pokete" -install -Dv assets/com.github.lxgr-linux.pokete.desktop "$dest/share/applications/com.github.lxgr-linux.pokete.desktop" -install -Dvm644 assets/com.github.lxgr-linux.pokete.svg "$dest/share/icons/hicolor/scalable/apps/com.github.lxgr-linux.pokete.svg" -install -Dv assets/pokete.metainfo.xml "$dest/share/metainfo/com.github.lxgr_linux.pokete.metainfo.xml" -install -Dv LICENSE "$dest/share/licenses/com.github.lxgr_linux.pokete/LICENSE" +install -Dv "assets/$app_id.desktop" "$dest/share/applications/$app_id.desktop" +install -Dvm644 "assets/$app_id.svg" "$dest/share/icons/hicolor/scalable/apps/$app_id.svg" +install -Dv assets/pokete.metainfo.xml "$dest/share/metainfo/$app_id.metainfo.xml" +install -Dv LICENSE "$dest/share/licenses/$app_id/LICENSE" install -dv "$dest/bin/" find . | grep -E "\.py$|\.so$|\.mp3$" | while read file do diff --git a/util/release.py b/util/release.py index e2fd8521..0efa03f2 100644 --- a/util/release.py +++ b/util/release.py @@ -23,7 +23,7 @@ def show_help(ex: str, command: str): Tags have to follow the `vMAJOR.MINOR.PATCH-RELEASE` semantic. Flags: - --help\t\tShows help for a specific command + --help\tShows help for a specific command Copyright (c) lxgr-linux 2024""") @@ -37,7 +37,7 @@ def main( elif len(options) == 0: print( ":: Error: Not enough arguments, a tag has to be given, " - f"try `{ex} {command} help`" + f"try `{ex} {command} --help`" ) sys.exit(2) else: @@ -45,7 +45,7 @@ def main( if not __is_tag_valid(tag): print( ":: Error: Invalid tag, " - f"try `{ex} {command} help`" + f"try `{ex} {command} --help`" ) sys.exit(2) __release(tag) diff --git a/util/wiki.py b/util/wiki.py index 35854974..15abbe8d 100755 --- a/util/wiki.py +++ b/util/wiki.py @@ -647,6 +647,6 @@ def gen(ex: str, command: str, options: list[str], case _: print( f":: Error: Option '{opt}' not found, " - f"try `{ex} {command} help`" + f"try `{ex} {command} --help`" ) sys.exit(2) From f889588f6d47fae6555ed235d222eeda71d1fe30 Mon Sep 17 00:00:00 2001 From: lxgr-linux Date: Sun, 23 Jun 2024 15:10:32 +0200 Subject: [PATCH 12/26] feat(#287): Maybe updated AppImageBuilder.yaml --- assets/AppImageBuilder.yml | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/assets/AppImageBuilder.yml b/assets/AppImageBuilder.yml index 546e75fd..cffb4d3c 100644 --- a/assets/AppImageBuilder.yml +++ b/assets/AppImageBuilder.yml @@ -2,21 +2,19 @@ version: 1 script: - rm -rf AppDir | true - - mkdir -p AppDir/usr/share/icons - - git clone --depth=1 https://github.com/lxgr-linux/pokete AppDir/usr/share/pokete + - git clone --depth=1 https://github.com/lxgr-linux/pokete - git clone --depth=1 https://github.com/lxgr-linux/scrap_engine AppDir/usr/share/scrap_engine - - cp AppDir/usr/share/scrap_engine/scrap_engine.py AppDir/usr/share/pokete/ - - cp AppDir/usr/share/pokete/assets/pokete.svg AppDir/usr/share/icons/pokete.svg + - cd ./pokete && python3.10 ./util.py install AppDir/usr AppDir: path: AppDir app_info: - id: com.github.lxgr-linux.pokete + id: com.github.lxgr_linux.pokete name: Pokete - icon: pokete + icon: com.github.lxgr_linux.pokete version: 0.8.0 exec: usr/bin/python3.10 - exec_args: $APPDIR/usr/share/pokete/pokete.py --log $@ + exec_args: $APPDIR/usr/bin/pokete.py --log $@ # pacman: # include: # - python @@ -34,19 +32,10 @@ AppDir: files: include: [] exclude: - - usr/share/man - - usr/share/pokete/bash - - usr/share/pokete/.git - - usr/share/pokete/util.py - - usr/share/pokete/*.md + - pokete - usr/share/scrap_engine - usr/share/pokete/playsound/libplaysound.dll - usr/share/pokete/playsound/libplaysound.osx.so - - usr/share/pokete/assets/ss - - usr/share/pokete/assets/*.png - - usr/share/pokete/assets/*.kra - - usr/share/pokete/assets/*.svg - - usr/share/doc test: fedora-30: image: appimagecrafters/tests-env:fedora-30 From afae36641b11a8e1f5a85cb8799dc7af02a007bf Mon Sep 17 00:00:00 2001 From: lxgr-linux Date: Thu, 11 Jul 2024 15:42:32 +0200 Subject: [PATCH 13/26] feat(#287): Added roudimentary commandline parser --- util.py | 70 ++++++++++++++++---------------------- util/__init__.py | 2 +- util/arguments.py | 87 +++++++++++++++++++++++++++++++++++++++++++---- util/install.py | 8 ++--- util/pages.py | 52 +++++++--------------------- util/release.py | 15 +++----- util/wiki.py | 13 +++---- 7 files changed, 136 insertions(+), 111 deletions(-) diff --git a/util.py b/util.py index 4a924e8a..7330b1d8 100755 --- a/util.py +++ b/util.py @@ -1,52 +1,40 @@ #!/usr/bin/env python3 import sys -from util import parse, gen_wiki, prepare_pages, make_release, install +from util import gen_wiki, prepare_after, prepare_before, make_release, \ + install +from util.arguments import RootCommand, Command, not_found, not_enough_args -def show_help(name: str): - print(f"""{name} -- Pokete utility -Usage: - {name} [command] [options]... - -Commands: - wiki\t\tGenerates wiki.md - prpare-pages\tPrepares github pages - release\t\tCreates a release commit - help\t\tShows this help - -Flags: - --help\t\tShows help for a specific command - -Copyright (c) lxgr-linux 2024""") +def fallback(ex: str, options: list[str], + flags: dict[str, list[str]]): + if not options: + not_enough_args(ex) + not_found(ex, options[0]) def main(): - args = sys.argv - command, options, flags = parse(args) - - arg_tup = (args[0], command, options, flags) - - match command: - case "help": - show_help(args[0]) - case "wiki": - gen_wiki(*arg_tup) - case "prepare-pages": - prepare_pages(*arg_tup) - case "release": - make_release(*arg_tup) - case "install": - install(*arg_tup) - case _: - if "--help" in flags: - show_help(args[0]) - else: - print( - f":: Error: Command '{command}' not found, " - f"try `{args[0]} help`" - ) - sys.exit(2) + c = RootCommand( + "util", + "Pokete utility", + fallback, + commands=[ + Command("install", "Install pokete to a given directory", install), + Command( + "prepare-pages", "Prepares github pages", fallback, + commands=[ + Command("before", "Actions run pre branch switch", + prepare_before), + Command("after", "Actions run post branch switch", + prepare_after) + ] + ), + Command("release", "Creates a release", make_release), + Command("wiki", "Generate a markdown wiki", gen_wiki) + ] + ) + + c.exec() if __name__ == "__main__": diff --git a/util/__init__.py b/util/__init__.py index 00625e28..9cfd8c16 100644 --- a/util/__init__.py +++ b/util/__init__.py @@ -1,5 +1,5 @@ from .arguments import parse from .wiki import gen as gen_wiki -from .pages import prepare as prepare_pages +from .pages import prepare_after, prepare_before from .release import main as make_release from .install import install diff --git a/util/arguments.py b/util/arguments.py index bd4decbb..3f62ad26 100644 --- a/util/arguments.py +++ b/util/arguments.py @@ -1,17 +1,20 @@ -def parse(args) -> tuple[str, list[str], dict[str, list[str]]]: - if len(args) == 0: - return "", [], {} +import sys + + +def parse(args) -> tuple[list[str], dict[str, list[str]]]: + if len(args) == 1: + return [], {} options: list[str] = [] flags: dict[str, list[str]] = {} idx = 0 - for arg in args[2:]: + for arg in args[1:]: if arg.startswith("--"): break idx += 1 options.append(arg) - __index_flags(0, args[2 + idx:], "", flags) + __index_flags(0, args[1 + idx:], "", flags) - return args[1], options, flags + return options, flags def __index_flags( @@ -26,3 +29,75 @@ def __index_flags( else: flags[flag].append(arr[idx]) __index_flags(idx + 1, arr, flag, flags) + + +def not_found(ex, option): + print( + f":: Error: Command '{option}' not found, " + f"try `{ex} --help`" + ) + sys.exit(2) + + +def not_enough_args(ex): + print( + ":: Error: Not enough arguments, " + f"try `{ex} --help`" + ) + sys.exit(2) + + +class Flag: + def __init__(self, aliases: list[str], desc: str): + self.aliases = aliases + self.desc = desc + + +class Command: + def __init__( + self, + name: str, desc: str, + fn, + flags: list[Flag] | None = None, + commands: list["Command"] | None = None + ): + self.name = name + self.desc = desc + self.fn = fn + self.flags = flags if flags is not None else [] + self.commands = commands if commands is not None else [] + + def print_help(self, exec: str): + print(f"""{self.name} -- {self.desc} + +Usage: + {exec} [command] [options]... +{f""" +Options: +{"\n".join(f"\t{command.name}\t\t{command.desc}" for command in self.commands)} +""" if self.commands else ""} +Flags: + --help\t\tShows help for a specific command + +Copyright (c) lxgr-linux 2024""") + + def run(self, ex: str, options: list[str], + flags: dict[str, list[str]]): + if options: + for c in self.commands: + if c.name == options[0]: + c.run(f"{ex} {options[0]}", + options[1:], + flags) + return + if "--help" in flags: + self.print_help(ex) + else: + self.fn(ex, options, flags) + + +class RootCommand(Command): + def exec(self): + args = sys.argv + options, flags = parse(args) + self.run(args[0], options, flags) diff --git a/util/install.py b/util/install.py index 91b95021..e54d6614 100644 --- a/util/install.py +++ b/util/install.py @@ -13,14 +13,12 @@ def show_help(ex: str, command: str): Copyright (c) lxgr-linux 2024""") -def install(ex: str, command: str, options: list[str], +def install(ex: str, options: list[str], flags: dict[str, list[str]]): - if "--help" in flags: - show_help(ex, command) - elif len(options) == 0: + if len(options) == 0: print( ":: Error: Not enough arguments, a destination has to be given, " - f"try `{ex} {command} --help`" + f"try `{ex} {options} --help`" ) sys.exit(2) else: diff --git a/util/pages.py b/util/pages.py index c851958b..e06f7103 100644 --- a/util/pages.py +++ b/util/pages.py @@ -13,9 +13,10 @@ """ import os from os.path import exists -import sys import json from urllib import request + +from util.arguments import not_enough_args, not_found from util.wiki import Wiki """ @@ -370,46 +371,19 @@ def after() -> None: print(':: Done!') -def show_help(ex: str, command: str): - print(f"""{ex} {command} -- Prepare pages prepares all files in "files" for GitHub Pages -Usage: - {ex} {command} [after|before] - -Options: - before\tActions run pre branch switch - after\tActions run pre branch switch - -Flags: - --help\tShows help for a specific command - -Copyright (c) lxgr-linux 2024""") +def prepare_before( + ex: str, options: list[str], + flags: dict[str, list[str]] +): + global files + with open('.gh-pages.json', 'r') as config_file: + files = json.loads(config_file.read()) + before() -def prepare( - ex: str, command: str, options: list[str], +def prepare_after( + ex: str, options: list[str], flags: dict[str, list[str]] ): global files - if "--help" in flags: - show_help(ex, command) - - elif len(options) == 0: - print( - ":: Error: Not enough arguments, " - f"try `{ex} {command} help`" - ) - sys.exit(2) - else: - match opt := options[0]: - case 'before': - with open('.gh-pages.json', 'r') as config_file: - files = json.loads(config_file.read()) - before() - case 'after': - after() - case _: - print( - f":: Error: Option '{opt}' not found, " - f"try `{ex} {command} help`" - ) - sys.exit(2) + after() diff --git a/util/release.py b/util/release.py index 0efa03f2..00e94cdd 100644 --- a/util/release.py +++ b/util/release.py @@ -1,6 +1,7 @@ import re import sys +from util.arguments import not_enough_args from util.changelog import write_changelog TAG_REGEX = r"^v([0-9]+)\.([0-9]+)\.([0-9]+)(-[0-9A-Za-z-]+)?$" @@ -29,23 +30,17 @@ def show_help(ex: str, command: str): def main( - ex: str, command: str, options: list[str], + ex: str, options: list[str], flags: dict[str, list[str]] ): - if "--help" in flags: - show_help(ex, command) - elif len(options) == 0: - print( - ":: Error: Not enough arguments, a tag has to be given, " - f"try `{ex} {command} --help`" - ) - sys.exit(2) + if len(options) == 0: + not_enough_args(ex) else: tag = options[0] if not __is_tag_valid(tag): print( ":: Error: Invalid tag, " - f"try `{ex} {command} --help`" + f"try `{ex} --help`" ) sys.exit(2) __release(tag) diff --git a/util/wiki.py b/util/wiki.py index 15abbe8d..68925cac 100755 --- a/util/wiki.py +++ b/util/wiki.py @@ -7,6 +7,7 @@ import release from pokete_classes.effects import effects, effect_list from pokete_data import pokes, attacks, types, items, maps +from util.arguments import not_found SILENT = False QUIET = False @@ -617,13 +618,11 @@ def show_help(ex: str, command: str): Copyright (c) lxgr-linux 2024""") -def gen(ex: str, command: str, options: list[str], +def gen(ex: str, options: list[str], flags: dict[str, list[str]]): global SILENT, QUIET, VERBOSE - if "--help" in flags: - show_help(ex, command) - elif len(options) == 0: + if len(options) == 0: SILENT, QUIET, VERBOSE = False, True, False Wiki.single() gen_pics() @@ -645,8 +644,4 @@ def gen(ex: str, command: str, options: list[str], case "pics": gen_pics() case _: - print( - f":: Error: Option '{opt}' not found, " - f"try `{ex} {command} --help`" - ) - sys.exit(2) + not_found(ex, opt) From 18390e05e5ff9e9dd5bce934f1d7fabe23044954 Mon Sep 17 00:00:00 2001 From: lxgr-linux Date: Thu, 11 Jul 2024 18:22:48 +0200 Subject: [PATCH 14/26] feat(#287): Flags are better now --- util.py | 10 +++++++--- util/arguments.py | 26 ++++++++++++++++++++------ util/wiki.py | 47 ++++++++++++++++++++++++++--------------------- 3 files changed, 53 insertions(+), 30 deletions(-) diff --git a/util.py b/util.py index 7330b1d8..8168f4af 100755 --- a/util.py +++ b/util.py @@ -2,8 +2,9 @@ import sys from util import gen_wiki, prepare_after, prepare_before, make_release, \ - install -from util.arguments import RootCommand, Command, not_found, not_enough_args + install, wiki +from util.arguments import RootCommand, Command, not_found, not_enough_args, \ + Flag def fallback(ex: str, options: list[str], @@ -30,7 +31,10 @@ def main(): ] ), Command("release", "Creates a release", make_release), - Command("wiki", "Generate a markdown wiki", gen_wiki) + Command("wiki", "Generate a markdown wiki", gen_wiki, flags=[ + wiki.silent_flag, wiki.quiet_flag, wiki.verbose_flag, + wiki.single_flag, wiki.multi_flag, wiki.pics_flag + ]) ] ) diff --git a/util/arguments.py b/util/arguments.py index 3f62ad26..519ff471 100644 --- a/util/arguments.py +++ b/util/arguments.py @@ -52,6 +52,9 @@ def __init__(self, aliases: list[str], desc: str): self.aliases = aliases self.desc = desc + def is_flag(self, flag: str): + return flag in self.aliases + class Command: def __init__( @@ -64,20 +67,23 @@ def __init__( self.name = name self.desc = desc self.fn = fn - self.flags = flags if flags is not None else [] + self.flags = (flags if flags is not None else []) + [ + Flag(["-h", "--help"], "Shows help for a specific command")] self.commands = commands if commands is not None else [] - def print_help(self, exec: str): + def __print_help(self, ex: str): print(f"""{self.name} -- {self.desc} Usage: - {exec} [command] [options]... + {ex} [command] [options]... {f""" Options: {"\n".join(f"\t{command.name}\t\t{command.desc}" for command in self.commands)} """ if self.commands else ""} +{f""" Flags: - --help\t\tShows help for a specific command +{"\n".join(f"\t{"|".join(flag.aliases)}\t\t{flag.desc}" for flag in self.flags)} +""" if self.flags else ""} Copyright (c) lxgr-linux 2024""") @@ -90,8 +96,16 @@ def run(self, ex: str, options: list[str], options[1:], flags) return - if "--help" in flags: - self.print_help(ex) + all_flags = [i for f in self.flags for i in f.aliases] + for flag in flags: + if flag not in all_flags: + print( + f":: Error: Unknown flag `{flag}`, " + f"try `{ex} --help`" + ) + sys.exit(2) + if "--help" in flags or "-h" in flags: + self.__print_help(ex) else: self.fn(ex, options, flags) diff --git a/util/wiki.py b/util/wiki.py index 68925cac..edaa9635 100755 --- a/util/wiki.py +++ b/util/wiki.py @@ -7,7 +7,7 @@ import release from pokete_classes.effects import effects, effect_list from pokete_data import pokes, attacks, types, items, maps -from util.arguments import not_found +from util.arguments import not_found, Flag SILENT = False QUIET = False @@ -621,27 +621,32 @@ def show_help(ex: str, command: str): def gen(ex: str, options: list[str], flags: dict[str, list[str]]): global SILENT, QUIET, VERBOSE - - if len(options) == 0: + if len(flags) == 0: SILENT, QUIET, VERBOSE = False, True, False Wiki.single() gen_pics() else: - for opt in options: - match opt := opt.lower(): - case "silent", "quite", "verbose": - SILENT, QUIET, VERBOSE = False, False, False - if opt == "silent": - SILENT = True - elif opt == "quite": - QUIET = True - else: - VERBOSE = True - case "single": - Wiki.single() - case "multi": - Wiki.multi("wiki") - case "pics": - gen_pics() - case _: - not_found(ex, opt) + for flag in flags: + print(flag) + if silent_flag.is_flag(flag): + SILENT, QUIET, VERBOSE = True, False, False + elif quiet_flag.is_flag(flag): + SILENT, QUIET, VERBOSE = False, True, False + elif silent_flag.is_flag(flag): + SILENT, QUIET, VERBOSE = False, False, True + elif single_flag.is_flag(flag): + Wiki.single() + elif multi_flag.is_flag(flag): + Wiki.multi("wiki") + elif pics_flag.is_flag(flag): + gen_pics() + + +silent_flag = Flag(["--silent"], "Prints no statements at all") +quiet_flag = Flag(["--quiet"], "Prints only some minimal statements") +verbose_flag = Flag(["--verbose"], "Prints everything it's doing") +single_flag = Flag(["--single"], "Generates the `wiki.md` as a single file") +multi_flag = Flag(["--multi"], + "Generates a folder `wiki` with the wiki files") +pics_flag = Flag(["--pics"], + "Generates the `assets/pics.md` file with all sample pictures") From 14dd7e234085f0af210ba803e8bfef0649fc8925 Mon Sep 17 00:00:00 2001 From: lxgr-linux Date: Thu, 11 Jul 2024 18:24:56 +0200 Subject: [PATCH 15/26] feat(#287): Fixed up github workflow --- .github/workflows/documentation.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index bc1462b1..ebb22d39 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -98,7 +98,7 @@ jobs: - name: Make multipage wiki run: | - python3 util.py wiki verbose single multi pics + python3 util.py wiki --verbose --single --multi --pics mkdir /tmp/gen-wiki cp -r HowToPlay.md DevGuide.md wiki.md /tmp/gen-wiki - name: Switch to wiki repository From 5465c76b2466fe9722f4fd67a3cd4a25665829ee Mon Sep 17 00:00:00 2001 From: lxgr-linux Date: Thu, 11 Jul 2024 19:02:48 +0200 Subject: [PATCH 16/26] feat(#287): Added appimage builder yaml to release flow --- assets/AppImageBuilder.yml | 69 ++++++++---------- util.py | 3 +- util/changelog.py | 146 ------------------------------------- util/release.py | 46 ------------ 4 files changed, 34 insertions(+), 230 deletions(-) delete mode 100644 util/changelog.py delete mode 100644 util/release.py diff --git a/assets/AppImageBuilder.yml b/assets/AppImageBuilder.yml index cffb4d3c..97075fcb 100644 --- a/assets/AppImageBuilder.yml +++ b/assets/AppImageBuilder.yml @@ -1,58 +1,53 @@ -# appimage-builder recipe see https://appimage-builder.readthedocs.io for details -version: 1 -script: - - rm -rf AppDir | true - - git clone --depth=1 https://github.com/lxgr-linux/pokete - - git clone --depth=1 https://github.com/lxgr-linux/scrap_engine AppDir/usr/share/scrap_engine - - cd ./pokete && python3.10 ./util.py install AppDir/usr - AppDir: - path: AppDir app_info: - id: com.github.lxgr_linux.pokete - name: Pokete - icon: com.github.lxgr_linux.pokete - version: 0.8.0 exec: usr/bin/python3.10 exec_args: $APPDIR/usr/bin/pokete.py --log $@ - # pacman: - # include: - # - python - # exclude: [] + icon: com.github.lxgr_linux.pokete + id: com.github.lxgr_linux.pokete + name: Pokete + version: 0.9.2 apt: arch: amd64 - sources: - - sourceline: 'deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ jammy main restricted universe multiverse' - key_url: 'http://keyserver.ubuntu.com/pks/lookup?op=get&search=0x871920d1991bc93c' - include: - - python3.10 exclude: - - perl - - gcc-12-base + - perl + - gcc-12-base + include: + - python3.10 + sources: + - key_url: https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x871920d1991bc93c + sourceline: deb [arch=amd64] https://archive.ubuntu.com/ubuntu/ jammy main restricted + universe multiverse files: - include: [] exclude: - - pokete - - usr/share/scrap_engine - - usr/share/pokete/playsound/libplaysound.dll - - usr/share/pokete/playsound/libplaysound.osx.so + - pokete + - usr/share/scrap_engine + - usr/share/pokete/playsound/libplaysound.dll + - usr/share/pokete/playsound/libplaysound.osx.so + include: [] + path: AppDir test: - fedora-30: - image: appimagecrafters/tests-env:fedora-30 - command: ./AppRun - debian-stable: - image: appimagecrafters/tests-env:debian-stable - command: ./AppRun archlinux-latest: - image: appimagecrafters/tests-env:archlinux-latest command: ./AppRun + image: appimagecrafters/tests-env:archlinux-latest centos-7: + command: ./AppRun image: appimagecrafters/tests-env:centos-7 + debian-stable: command: ./AppRun + image: appimagecrafters/tests-env:debian-stable + fedora-30: + command: ./AppRun + image: appimagecrafters/tests-env:fedora-30 ubuntu-xenial: - image: appimagecrafters/tests-env:ubuntu-xenial command: ./AppRun + image: appimagecrafters/tests-env:ubuntu-xenial AppImage: arch: x86_64 comp: gzip update-information: guess +script: +- rm -rf AppDir | true +- git clone --depth=1 https://github.com/lxgr-linux/pokete +- git clone --depth=1 https://github.com/lxgr-linux/scrap_engine AppDir/usr/share/scrap_engine +- cd ./pokete && python3.10 ./util.py install AppDir/usr +version: 1 diff --git a/util.py b/util.py index 8168f4af..0e4387e7 100755 --- a/util.py +++ b/util.py @@ -30,7 +30,8 @@ def main(): prepare_after) ] ), - Command("release", "Creates a release", make_release), + Command("release", "Prepare all relevant files for release", + make_release), Command("wiki", "Generate a markdown wiki", gen_wiki, flags=[ wiki.silent_flag, wiki.quiet_flag, wiki.verbose_flag, wiki.single_flag, wiki.multi_flag, wiki.pics_flag diff --git a/util/changelog.py b/util/changelog.py deleted file mode 100644 index 1d2fa914..00000000 --- a/util/changelog.py +++ /dev/null @@ -1,146 +0,0 @@ -import re -import xml.dom.minidom - -RawRelease = tuple[str, list[str]] -RawReleases = list[RawRelease] - -LIST_STARTERS = ("- ", "+ ") - - -def __get_raw_releases(content) -> RawReleases: - raw_releases: RawReleases = [] - for line in content.split("\n"): - if line.startswith("## "): - raw_releases.append((line, [])) - elif len(raw_releases) != 0: - raw_releases[-1][1].append(line) - return raw_releases - - -def __parse_line(line: str, idx=0, in_code_block=False, illegal_link="") -> str: - if idx == len(line): - return "" - this_segment = "" - segment = line[idx] - if segment == "`": - if in_code_block: - this_segment += "
    " - in_code_block = False - else: - this_segment += "" - in_code_block = True - elif segment == "[": - illegal_link += segment - elif illegal_link: - if segment == ")" and "]" in illegal_link: - this_segment += illegal_link.split("[")[1].split("]")[0] - illegal_link = "" - elif segment != "(" and illegal_link[-1] == "]": - this_segment += illegal_link - illegal_link = "" - else: - illegal_link += segment - else: - this_segment += segment - - return (this_segment + __parse_line( - line, idx + 1, in_code_block, illegal_link - )).replace("", "") - - -def __parse_markup( - lines: list[str], idx: int = 0, ul_depth: int = 0, - curr_ul_sep="", curr_line_depth=0 -) -> str: - if idx == len(lines): - return "" - parsed_line = "" - line = lines[idx].lstrip() - line_depth = len(lines[idx]) - len(line) - if line.startswith(LIST_STARTERS): - ul_sep = line[0:2] - if curr_ul_sep == "": - curr_ul_sep = ul_sep - ul_depth += 1 - parsed_line += "
      " - '''if ul_sep != curr_ul_sep: - curr_ul_sep = ul_sep - if line_depth >= curr_line_depth: - ul_depth += 1 - parsed_line += "
        " - else: - ul_depth -= 1 - parsed_line += "
      " - # Since Appstream does not support nested lists ind their standart, this is left out - ''' - parsed_line += f"
    • {__parse_line(line.lstrip(ul_sep))}
    • " - elif line_depth == curr_line_depth + 2 and curr_ul_sep != "": - parsed_line += f"{__parse_line(line)}" - else: - line = line.lstrip("#") - if ul_depth != 0: - parsed_line += "
    " * ul_depth - ul_depth = 0 - curr_ul_sep = "" - if line.strip() != "": - parsed_line += f"

    {__parse_line(line)}

    " - - return ( - parsed_line + - __parse_markup( - lines, idx + 1, ul_depth, - curr_ul_sep, line_depth - ) - ).replace("", "") - - -def __parse_version_date(heading: str) -> tuple[str, str]: - heading = heading.strip("##").strip() - version_sub, date = heading.split(" - ") - - return version_sub.split("[")[1].split("]")[0].strip(), date.strip() - - -def __parse_release_xml(release: tuple[str, list[str]]) -> str: - version, date = __parse_version_date(release[0]) - - markup = __parse_markup(release[1]) - - urgency = "medium" if version.endswith(".0") else "low" - - return f""" - - {markup} - - https://github.com/lxgr-linux/pokete/releases/tag/{version} -""" - - -def __get_full_releases(releases: list[str]): - return f""" - {"\n".join(releases)} -""" - - -def write_changelog(): - with open("Changelog.md", "r") as changelog_file: - changelog_content = changelog_file.read() - raw_releases = __get_raw_releases(changelog_content) - releases = [__parse_release_xml(r) for r in raw_releases] - full_releases = __get_full_releases(releases) - with open("assets/pokete.metainfo.xml", "r") as metainfo_file: - content = metainfo_file.read() - new_content = re.sub(r'.*?', full_releases, - content, flags=re.DOTALL) - with open("assets/pokete.metainfo.xml", "w") as metainfo_file: - metainfo_file.write( - "\n".join( - line for line in xml.dom.minidom.parseString( - new_content.replace("\n", "") - ) - .toprettyxml(encoding="UTF-8") - .decode("UTF-8") - .split("\n") - if line.strip() - ) - ) diff --git a/util/release.py b/util/release.py deleted file mode 100644 index 00e94cdd..00000000 --- a/util/release.py +++ /dev/null @@ -1,46 +0,0 @@ -import re -import sys - -from util.arguments import not_enough_args -from util.changelog import write_changelog - -TAG_REGEX = r"^v([0-9]+)\.([0-9]+)\.([0-9]+)(-[0-9A-Za-z-]+)?$" - - -def __release(tag: str): - write_changelog() - pass - - -def __is_tag_valid(tag: str) -> bool: - return re.fullmatch(TAG_REGEX, tag) is not None - - -def show_help(ex: str, command: str): - print(f"""{ex} {command} -- Prepare all relevant files for release -Usage: - {ex} {command} [tag] - -Tags have to follow the `vMAJOR.MINOR.PATCH-RELEASE` semantic. - -Flags: - --help\tShows help for a specific command - -Copyright (c) lxgr-linux 2024""") - - -def main( - ex: str, options: list[str], - flags: dict[str, list[str]] -): - if len(options) == 0: - not_enough_args(ex) - else: - tag = options[0] - if not __is_tag_valid(tag): - print( - ":: Error: Invalid tag, " - f"try `{ex} --help`" - ) - sys.exit(2) - __release(tag) From 012c6c277dad518c30c2481b3f776e22a7639a1b Mon Sep 17 00:00:00 2001 From: lxgr-linux Date: Thu, 11 Jul 2024 19:03:59 +0200 Subject: [PATCH 17/26] feat(#287): Added appimage builder yaml to release flow --- util/release/__init__.py | 47 ++++++++++++ util/release/appimage.py | 13 ++++ util/release/changelog.py | 146 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 206 insertions(+) create mode 100644 util/release/__init__.py create mode 100644 util/release/appimage.py create mode 100644 util/release/changelog.py diff --git a/util/release/__init__.py b/util/release/__init__.py new file mode 100644 index 00000000..f6883e9b --- /dev/null +++ b/util/release/__init__.py @@ -0,0 +1,47 @@ +import re +import sys + +from util.arguments import not_enough_args +from .changelog import write_changelog +from .appimage import write_appimage + +TAG_REGEX = r"^v([0-9]+)\.([0-9]+)\.([0-9]+)(-[0-9A-Za-z-]+)?$" + + +def __release(tag: str): + write_changelog() + write_appimage(tag) + + +def __is_tag_valid(tag: str) -> bool: + return re.fullmatch(TAG_REGEX, tag) is not None + + +def show_help(ex: str, command: str): + print(f"""{ex} {command} -- Prepare all relevant files for release +Usage: + {ex} {command} [tag] + +Tags have to follow the `vMAJOR.MINOR.PATCH-RELEASE` semantic. + +Flags: + --help\tShows help for a specific command + +Copyright (c) lxgr-linux 2024""") + + +def main( + ex: str, options: list[str], + flags: dict[str, list[str]] +): + if len(options) == 0: + not_enough_args(ex) + else: + tag = options[0] + if not __is_tag_valid(tag): + print( + ":: Error: Invalid tag, " + f"try `{ex} --help`" + ) + sys.exit(2) + __release(tag) diff --git a/util/release/appimage.py b/util/release/appimage.py new file mode 100644 index 00000000..10353cb3 --- /dev/null +++ b/util/release/appimage.py @@ -0,0 +1,13 @@ +import yaml + +FILE = "assets/AppImageBuilder.yml" + + +def write_appimage(tag: str): + with open(FILE, 'r') as f: + content = yaml.safe_load(f) + + content["AppDir"]["app_info"]["version"] = tag.lstrip("v") + + with open(FILE, 'w') as f: + yaml.dump(content, f) diff --git a/util/release/changelog.py b/util/release/changelog.py new file mode 100644 index 00000000..1d2fa914 --- /dev/null +++ b/util/release/changelog.py @@ -0,0 +1,146 @@ +import re +import xml.dom.minidom + +RawRelease = tuple[str, list[str]] +RawReleases = list[RawRelease] + +LIST_STARTERS = ("- ", "+ ") + + +def __get_raw_releases(content) -> RawReleases: + raw_releases: RawReleases = [] + for line in content.split("\n"): + if line.startswith("## "): + raw_releases.append((line, [])) + elif len(raw_releases) != 0: + raw_releases[-1][1].append(line) + return raw_releases + + +def __parse_line(line: str, idx=0, in_code_block=False, illegal_link="") -> str: + if idx == len(line): + return "" + this_segment = "" + segment = line[idx] + if segment == "`": + if in_code_block: + this_segment += "
    " + in_code_block = False + else: + this_segment += "" + in_code_block = True + elif segment == "[": + illegal_link += segment + elif illegal_link: + if segment == ")" and "]" in illegal_link: + this_segment += illegal_link.split("[")[1].split("]")[0] + illegal_link = "" + elif segment != "(" and illegal_link[-1] == "]": + this_segment += illegal_link + illegal_link = "" + else: + illegal_link += segment + else: + this_segment += segment + + return (this_segment + __parse_line( + line, idx + 1, in_code_block, illegal_link + )).replace("", "") + + +def __parse_markup( + lines: list[str], idx: int = 0, ul_depth: int = 0, + curr_ul_sep="", curr_line_depth=0 +) -> str: + if idx == len(lines): + return "" + parsed_line = "" + line = lines[idx].lstrip() + line_depth = len(lines[idx]) - len(line) + if line.startswith(LIST_STARTERS): + ul_sep = line[0:2] + if curr_ul_sep == "": + curr_ul_sep = ul_sep + ul_depth += 1 + parsed_line += "
      " + '''if ul_sep != curr_ul_sep: + curr_ul_sep = ul_sep + if line_depth >= curr_line_depth: + ul_depth += 1 + parsed_line += "
        " + else: + ul_depth -= 1 + parsed_line += "
      " + # Since Appstream does not support nested lists ind their standart, this is left out + ''' + parsed_line += f"
    • {__parse_line(line.lstrip(ul_sep))}
    • " + elif line_depth == curr_line_depth + 2 and curr_ul_sep != "": + parsed_line += f"{__parse_line(line)}" + else: + line = line.lstrip("#") + if ul_depth != 0: + parsed_line += "
    " * ul_depth + ul_depth = 0 + curr_ul_sep = "" + if line.strip() != "": + parsed_line += f"

    {__parse_line(line)}

    " + + return ( + parsed_line + + __parse_markup( + lines, idx + 1, ul_depth, + curr_ul_sep, line_depth + ) + ).replace("", "") + + +def __parse_version_date(heading: str) -> tuple[str, str]: + heading = heading.strip("##").strip() + version_sub, date = heading.split(" - ") + + return version_sub.split("[")[1].split("]")[0].strip(), date.strip() + + +def __parse_release_xml(release: tuple[str, list[str]]) -> str: + version, date = __parse_version_date(release[0]) + + markup = __parse_markup(release[1]) + + urgency = "medium" if version.endswith(".0") else "low" + + return f""" + + {markup} + + https://github.com/lxgr-linux/pokete/releases/tag/{version} +""" + + +def __get_full_releases(releases: list[str]): + return f""" + {"\n".join(releases)} +""" + + +def write_changelog(): + with open("Changelog.md", "r") as changelog_file: + changelog_content = changelog_file.read() + raw_releases = __get_raw_releases(changelog_content) + releases = [__parse_release_xml(r) for r in raw_releases] + full_releases = __get_full_releases(releases) + with open("assets/pokete.metainfo.xml", "r") as metainfo_file: + content = metainfo_file.read() + new_content = re.sub(r'.*?', full_releases, + content, flags=re.DOTALL) + with open("assets/pokete.metainfo.xml", "w") as metainfo_file: + metainfo_file.write( + "\n".join( + line for line in xml.dom.minidom.parseString( + new_content.replace("\n", "") + ) + .toprettyxml(encoding="UTF-8") + .decode("UTF-8") + .split("\n") + if line.strip() + ) + ) From 034fc85947dbe0323f08fdf489c564cabbb81485 Mon Sep 17 00:00:00 2001 From: lxgr-linux Date: Thu, 11 Jul 2024 19:23:05 +0200 Subject: [PATCH 18/26] feat(#287): Added release.py to release workflow --- util/release/__init__.py | 2 ++ util/release/release_py.py | 10 ++++++++++ 2 files changed, 12 insertions(+) create mode 100644 util/release/release_py.py diff --git a/util/release/__init__.py b/util/release/__init__.py index f6883e9b..762748a1 100644 --- a/util/release/__init__.py +++ b/util/release/__init__.py @@ -4,6 +4,7 @@ from util.arguments import not_enough_args from .changelog import write_changelog from .appimage import write_appimage +from .release_py import write_release_py TAG_REGEX = r"^v([0-9]+)\.([0-9]+)\.([0-9]+)(-[0-9A-Za-z-]+)?$" @@ -11,6 +12,7 @@ def __release(tag: str): write_changelog() write_appimage(tag) + write_release_py(tag) def __is_tag_valid(tag: str) -> bool: diff --git a/util/release/release_py.py b/util/release/release_py.py new file mode 100644 index 00000000..5c35ed06 --- /dev/null +++ b/util/release/release_py.py @@ -0,0 +1,10 @@ +def write_release_py(tag: str): + with open("release.py", "r") as f: + content = f.readlines() + + for idx, line in enumerate(content): + if line.startswith('VERSION = "'): + content[idx] = f'VERSION = "{tag.lstrip("v")}"\n' + + with open("release.py", "w") as f: + f.writelines(content) From 7d888e7b3254defe9249e4a4c73bfe5ad6a321e6 Mon Sep 17 00:00:00 2001 From: lxgr-linux Date: Sat, 13 Jul 2024 10:42:49 +0200 Subject: [PATCH 19/26] feat(#287): Added warnings to changelog generations --- util/release/__init__.py | 5 ++++- util/release/changelog.py | 10 +++++++++- util/release/release_py.py | 1 + 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/util/release/__init__.py b/util/release/__init__.py index 762748a1..de8d764e 100644 --- a/util/release/__init__.py +++ b/util/release/__init__.py @@ -10,8 +10,11 @@ def __release(tag: str): - write_changelog() + print(":: Writing appstream data...") + write_changelog(tag) + print(":: Writing appimage builder file...") write_appimage(tag) + print(":: Writing release.py...") write_release_py(tag) diff --git a/util/release/changelog.py b/util/release/changelog.py index 1d2fa914..38df20ed 100644 --- a/util/release/changelog.py +++ b/util/release/changelog.py @@ -122,10 +122,18 @@ def __get_full_releases(releases: list[str]): """ -def write_changelog(): +def check_versions(tag: str, raw_releases: RawReleases): + all_versions = [__parse_version_date(release[0])[0] + for release in raw_releases] + if tag.lstrip("v") not in all_versions: + print(f":: Warning: release tag `{tag}` has no changelog entry!") + + +def write_changelog(tag: str): with open("Changelog.md", "r") as changelog_file: changelog_content = changelog_file.read() raw_releases = __get_raw_releases(changelog_content) + check_versions(tag, raw_releases) releases = [__parse_release_xml(r) for r in raw_releases] full_releases = __get_full_releases(releases) with open("assets/pokete.metainfo.xml", "r") as metainfo_file: diff --git a/util/release/release_py.py b/util/release/release_py.py index 5c35ed06..03967d07 100644 --- a/util/release/release_py.py +++ b/util/release/release_py.py @@ -5,6 +5,7 @@ def write_release_py(tag: str): for idx, line in enumerate(content): if line.startswith('VERSION = "'): content[idx] = f'VERSION = "{tag.lstrip("v")}"\n' + break with open("release.py", "w") as f: f.writelines(content) From afe07dc258b08367fa816ddf036a113c80a6d596 Mon Sep 17 00:00:00 2001 From: lxgr-linux Date: Sat, 13 Jul 2024 11:08:22 +0200 Subject: [PATCH 20/26] feat(#287): Restructured command structure --- util.py | 4 +- util/__init__.py | 1 - util/arguments.py | 117 --------------------------------------- util/pages.py | 1 - util/release/__init__.py | 2 +- util/wiki.py | 2 +- 6 files changed, 3 insertions(+), 124 deletions(-) delete mode 100644 util/arguments.py diff --git a/util.py b/util.py index 0e4387e7..afe694df 100755 --- a/util.py +++ b/util.py @@ -1,10 +1,8 @@ #!/usr/bin/env python3 -import sys from util import gen_wiki, prepare_after, prepare_before, make_release, \ install, wiki -from util.arguments import RootCommand, Command, not_found, not_enough_args, \ - Flag +from util.command import RootCommand, Command, not_enough_args, not_found def fallback(ex: str, options: list[str], diff --git a/util/__init__.py b/util/__init__.py index 9cfd8c16..706700bb 100644 --- a/util/__init__.py +++ b/util/__init__.py @@ -1,4 +1,3 @@ -from .arguments import parse from .wiki import gen as gen_wiki from .pages import prepare_after, prepare_before from .release import main as make_release diff --git a/util/arguments.py b/util/arguments.py deleted file mode 100644 index 519ff471..00000000 --- a/util/arguments.py +++ /dev/null @@ -1,117 +0,0 @@ -import sys - - -def parse(args) -> tuple[list[str], dict[str, list[str]]]: - if len(args) == 1: - return [], {} - options: list[str] = [] - flags: dict[str, list[str]] = {} - idx = 0 - for arg in args[1:]: - if arg.startswith("--"): - break - idx += 1 - options.append(arg) - __index_flags(0, args[1 + idx:], "", flags) - - return options, flags - - -def __index_flags( - idx: int, arr: list[str], flag: str, - flags: dict[str, list[str]] -): - if idx == len(arr): - return - if arr[idx].startswith("--"): - flag = arr[idx] - flags[flag] = flags.get(flag, []) - else: - flags[flag].append(arr[idx]) - __index_flags(idx + 1, arr, flag, flags) - - -def not_found(ex, option): - print( - f":: Error: Command '{option}' not found, " - f"try `{ex} --help`" - ) - sys.exit(2) - - -def not_enough_args(ex): - print( - ":: Error: Not enough arguments, " - f"try `{ex} --help`" - ) - sys.exit(2) - - -class Flag: - def __init__(self, aliases: list[str], desc: str): - self.aliases = aliases - self.desc = desc - - def is_flag(self, flag: str): - return flag in self.aliases - - -class Command: - def __init__( - self, - name: str, desc: str, - fn, - flags: list[Flag] | None = None, - commands: list["Command"] | None = None - ): - self.name = name - self.desc = desc - self.fn = fn - self.flags = (flags if flags is not None else []) + [ - Flag(["-h", "--help"], "Shows help for a specific command")] - self.commands = commands if commands is not None else [] - - def __print_help(self, ex: str): - print(f"""{self.name} -- {self.desc} - -Usage: - {ex} [command] [options]... -{f""" -Options: -{"\n".join(f"\t{command.name}\t\t{command.desc}" for command in self.commands)} -""" if self.commands else ""} -{f""" -Flags: -{"\n".join(f"\t{"|".join(flag.aliases)}\t\t{flag.desc}" for flag in self.flags)} -""" if self.flags else ""} - -Copyright (c) lxgr-linux 2024""") - - def run(self, ex: str, options: list[str], - flags: dict[str, list[str]]): - if options: - for c in self.commands: - if c.name == options[0]: - c.run(f"{ex} {options[0]}", - options[1:], - flags) - return - all_flags = [i for f in self.flags for i in f.aliases] - for flag in flags: - if flag not in all_flags: - print( - f":: Error: Unknown flag `{flag}`, " - f"try `{ex} --help`" - ) - sys.exit(2) - if "--help" in flags or "-h" in flags: - self.__print_help(ex) - else: - self.fn(ex, options, flags) - - -class RootCommand(Command): - def exec(self): - args = sys.argv - options, flags = parse(args) - self.run(args[0], options, flags) diff --git a/util/pages.py b/util/pages.py index e06f7103..98bccd91 100644 --- a/util/pages.py +++ b/util/pages.py @@ -16,7 +16,6 @@ import json from urllib import request -from util.arguments import not_enough_args, not_found from util.wiki import Wiki """ diff --git a/util/release/__init__.py b/util/release/__init__.py index de8d764e..69b3a166 100644 --- a/util/release/__init__.py +++ b/util/release/__init__.py @@ -1,10 +1,10 @@ import re import sys -from util.arguments import not_enough_args from .changelog import write_changelog from .appimage import write_appimage from .release_py import write_release_py +from ..command import not_enough_args TAG_REGEX = r"^v([0-9]+)\.([0-9]+)\.([0-9]+)(-[0-9A-Za-z-]+)?$" diff --git a/util/wiki.py b/util/wiki.py index edaa9635..521b876d 100755 --- a/util/wiki.py +++ b/util/wiki.py @@ -7,7 +7,7 @@ import release from pokete_classes.effects import effects, effect_list from pokete_data import pokes, attacks, types, items, maps -from util.arguments import not_found, Flag +from util.command import Flag SILENT = False QUIET = False From 585d0c7e21498b9dce02cd671f6e1a978d4d2b82 Mon Sep 17 00:00:00 2001 From: lxgr-linux Date: Sat, 13 Jul 2024 11:08:26 +0200 Subject: [PATCH 21/26] feat(#287): Restructured command structure --- util/command/__init__.py | 2 ++ util/command/command.py | 73 ++++++++++++++++++++++++++++++++++++++++ util/command/helpers.py | 17 ++++++++++ util/command/parse.py | 28 +++++++++++++++ 4 files changed, 120 insertions(+) create mode 100644 util/command/__init__.py create mode 100644 util/command/command.py create mode 100644 util/command/helpers.py create mode 100644 util/command/parse.py diff --git a/util/command/__init__.py b/util/command/__init__.py new file mode 100644 index 00000000..91526918 --- /dev/null +++ b/util/command/__init__.py @@ -0,0 +1,2 @@ +from .command import Command, RootCommand, Flag +from .helpers import not_enough_args, not_found diff --git a/util/command/command.py b/util/command/command.py new file mode 100644 index 00000000..92f55ac3 --- /dev/null +++ b/util/command/command.py @@ -0,0 +1,73 @@ +import sys + +from .parse import parse + + +class Flag: + def __init__(self, aliases: list[str], desc: str): + self.aliases = aliases + self.desc = desc + + def is_flag(self, flag: str): + return flag in self.aliases + + +class Command: + def __init__( + self, + name: str, desc: str, + fn, + flags: list[Flag] | None = None, + commands: list["Command"] | None = None + ): + self.name = name + self.desc = desc + self.fn = fn + self.flags = (flags if flags is not None else []) + [ + Flag(["-h", "--help"], "Shows help for a specific command")] + self.commands = commands if commands is not None else [] + + def __print_help(self, ex: str): + print(f"""{self.name} -- {self.desc} + +Usage: + {ex} [command] [options]... +{f""" +Options: +{"\n".join(f"\t{command.name}\t\t{command.desc}" for command in self.commands)} +""" if self.commands else ""} +{f""" +Flags: +{"\n".join(f"\t{"|".join(flag.aliases)}\t\t{flag.desc}" for flag in self.flags)} +""" if self.flags else ""} + +Copyright (c) lxgr-linux 2024""") + + def run(self, ex: str, options: list[str], + flags: dict[str, list[str]]): + if options: + for c in self.commands: + if c.name == options[0]: + c.run(f"{ex} {options[0]}", + options[1:], + flags) + return + all_flags = [i for f in self.flags for i in f.aliases] + for flag in flags: + if flag not in all_flags: + print( + f":: Error: Unknown flag `{flag}`, " + f"try `{ex} --help`" + ) + sys.exit(2) + if "--help" in flags or "-h" in flags: + self.__print_help(ex) + else: + self.fn(ex, options, flags) + + +class RootCommand(Command): + def exec(self): + args = sys.argv + options, flags = parse(args) + self.run(args[0], options, flags) diff --git a/util/command/helpers.py b/util/command/helpers.py new file mode 100644 index 00000000..7f673cc8 --- /dev/null +++ b/util/command/helpers.py @@ -0,0 +1,17 @@ +import sys + + +def not_found(ex, option): + print( + f":: Error: Command '{option}' not found, " + f"try `{ex} --help`" + ) + sys.exit(2) + + +def not_enough_args(ex): + print( + ":: Error: Not enough arguments, " + f"try `{ex} --help`" + ) + sys.exit(2) diff --git a/util/command/parse.py b/util/command/parse.py new file mode 100644 index 00000000..92eeeb02 --- /dev/null +++ b/util/command/parse.py @@ -0,0 +1,28 @@ +def parse(args) -> tuple[list[str], dict[str, list[str]]]: + if len(args) == 1: + return [], {} + options: list[str] = [] + flags: dict[str, list[str]] = {} + idx = 0 + for arg in args[1:]: + if arg.startswith("--"): + break + idx += 1 + options.append(arg) + __index_flags(0, args[1 + idx:], "", flags) + + return options, flags + + +def __index_flags( + idx: int, arr: list[str], flag: str, + flags: dict[str, list[str]] +): + if idx == len(arr): + return + if arr[idx].startswith("--"): + flag = arr[idx] + flags[flag] = flags.get(flag, []) + else: + flags[flag].append(arr[idx]) + __index_flags(idx + 1, arr, flag, flags) From a083917a1f87b2e4b0a4adf96455ef92d4eb3f0a Mon Sep 17 00:00:00 2001 From: lxgr-linux Date: Sat, 13 Jul 2024 11:17:04 +0200 Subject: [PATCH 22/26] feat(#287): moved liners to utils --- pokete.py | 3 ++- pokete_classes/achievements.py | 2 +- pokete_classes/buy.py | 2 +- pokete_classes/detail.py | 2 +- pokete_classes/dex.py | 2 +- pokete_classes/fightmap/attack.py | 2 +- pokete_classes/hotkeys.py | 2 +- pokete_classes/input.py | 2 +- pokete_classes/learnattack.py | 2 +- pokete_classes/movemap.py | 2 +- pokete_classes/nature.py | 2 +- pokete_classes/notify.py | 2 +- pokete_classes/poke.py | 2 +- pokete_classes/roadmap.py | 2 +- pokete_classes/side_loops.py | 2 +- pokete_general_use_fns.py | 38 ------------------------------- util/__init__.py | 1 + util/liner.py | 36 +++++++++++++++++++++++++++++ 18 files changed, 53 insertions(+), 53 deletions(-) create mode 100644 util/liner.py diff --git a/pokete.py b/pokete.py index c6c8725c..1de122f6 100755 --- a/pokete.py +++ b/pokete.py @@ -55,7 +55,8 @@ from pokete_classes.dex import Dex from pokete_classes.loops import std_loop from pokete_classes.periodic_event_manager import PeriodicEventManager -from pokete_general_use_fns import liner, sort_vers, parse_args +from util import liner +from pokete_general_use_fns import sort_vers, parse_args from release import SPEED_OF_TIME from release import VERSION, CODENAME, SAVEPATH diff --git a/pokete_classes/achievements.py b/pokete_classes/achievements.py index 7a02b9a2..fba893ce 100644 --- a/pokete_classes/achievements.py +++ b/pokete_classes/achievements.py @@ -3,7 +3,7 @@ import datetime import logging import scrap_engine as se -from pokete_general_use_fns import liner +from util import liner from .hotkeys import ACTION_DIRECTIONS, Action, get_action from .loops import std_loop, easy_exit_loop from .ui_elements import BetterChooseBox, LabelBox diff --git a/pokete_classes/buy.py b/pokete_classes/buy.py index 494c0423..630e7508 100644 --- a/pokete_classes/buy.py +++ b/pokete_classes/buy.py @@ -2,7 +2,7 @@ import scrap_engine as se from pokete_classes.hotkeys import ACTION_UP_DOWN, Action, get_action -from pokete_general_use_fns import liner +from util import liner from .loops import std_loop from .ui_elements import Box, ChooseBox from .inv_items import invitems diff --git a/pokete_classes/detail.py b/pokete_classes/detail.py index febd85a5..4389e499 100644 --- a/pokete_classes/detail.py +++ b/pokete_classes/detail.py @@ -2,7 +2,7 @@ import scrap_engine as se import pokete_classes.game_map as gm -from pokete_general_use_fns import liner +from util import liner from .hotkeys import Action, get_action from .pokestats import PokeStatsInfoBox from .loops import std_loop diff --git a/pokete_classes/dex.py b/pokete_classes/dex.py index 0504dd12..9e17e1d7 100644 --- a/pokete_classes/dex.py +++ b/pokete_classes/dex.py @@ -4,7 +4,7 @@ from pokete_classes.hotkeys import Action, ACTION_UP_DOWN, get_action import pokete_data as p_data import pokete_classes.movemap as mvp -from pokete_general_use_fns import liner +from util import liner from .loops import std_loop, easy_exit_loop from .poke import Poke from .color import Color diff --git a/pokete_classes/fightmap/attack.py b/pokete_classes/fightmap/attack.py index 4b533131..255026b3 100644 --- a/pokete_classes/fightmap/attack.py +++ b/pokete_classes/fightmap/attack.py @@ -1,7 +1,7 @@ """Contains stuff related to fight attack choosing""" import scrap_engine as se -from pokete_general_use_fns import liner +from util import liner from ..hotkeys import ACTION_UP_DOWN, Action, get_action from ..ui_elements import ChooseBox, LabelBox from ..loops import std_loop diff --git a/pokete_classes/hotkeys.py b/pokete_classes/hotkeys.py index 60a4acf7..2f4885bc 100644 --- a/pokete_classes/hotkeys.py +++ b/pokete_classes/hotkeys.py @@ -3,7 +3,7 @@ import sys from enum import Enum, auto from collections import defaultdict -from pokete_general_use_fns import liner +from util import liner from .event import _ev diff --git a/pokete_classes/input.py b/pokete_classes/input.py index 67ba3765..6e5c714b 100644 --- a/pokete_classes/input.py +++ b/pokete_classes/input.py @@ -1,7 +1,7 @@ """This file contains input wrappers for ui elements""" from pokete_classes.hotkeys import Action, get_action -from pokete_general_use_fns import hard_liner +from util import hard_liner from .loops import std_loop from .ui_elements import InfoBox, InputBox from .event import _ev diff --git a/pokete_classes/learnattack.py b/pokete_classes/learnattack.py index 138de688..bab1c521 100644 --- a/pokete_classes/learnattack.py +++ b/pokete_classes/learnattack.py @@ -3,7 +3,7 @@ import random import scrap_engine as se import pokete_data as p_data -from pokete_general_use_fns import liner +from util import liner from .hotkeys import Action, get_action from .loops import std_loop, easy_exit_loop from .input import ask_bool, ask_ok diff --git a/pokete_classes/movemap.py b/pokete_classes/movemap.py index 6172e991..0a099140 100644 --- a/pokete_classes/movemap.py +++ b/pokete_classes/movemap.py @@ -2,7 +2,7 @@ import time import scrap_engine as se -from pokete_general_use_fns import liner +from util import liner import pokete_classes.ob_maps as obmp import pokete_classes.game_map as gm from release import SPEED_OF_TIME diff --git a/pokete_classes/nature.py b/pokete_classes/nature.py index 11192526..83438068 100644 --- a/pokete_classes/nature.py +++ b/pokete_classes/nature.py @@ -4,7 +4,7 @@ import random import scrap_engine as se import pokete_data as p_data -from pokete_general_use_fns import liner +from util import liner from .hotkeys import Action from .ui_elements import LabelBox from .color import Color diff --git a/pokete_classes/notify.py b/pokete_classes/notify.py index 805c5b2b..751f67f2 100644 --- a/pokete_classes/notify.py +++ b/pokete_classes/notify.py @@ -1,7 +1,7 @@ """Contains classes for notifications""" import scrap_engine as se -from pokete_general_use_fns import liner +from util import liner from .ui_elements import LabelBox from .color import Color from .util.object_group import get_nested diff --git a/pokete_classes/poke.py b/pokete_classes/poke.py index 78dd3233..a3cc7219 100644 --- a/pokete_classes/poke.py +++ b/pokete_classes/poke.py @@ -7,7 +7,7 @@ from datetime import datetime import scrap_engine as se import pokete_data as p_data -from pokete_general_use_fns import liner +from util import liner from release import SPEED_OF_TIME from .attack_actions import AttackActions from .attack import Attack diff --git a/pokete_classes/roadmap.py b/pokete_classes/roadmap.py index a90cc96a..19f1ff58 100644 --- a/pokete_classes/roadmap.py +++ b/pokete_classes/roadmap.py @@ -3,7 +3,7 @@ import pokete_data as p_data import pokete_classes.ob_maps as obmp -from pokete_general_use_fns import liner +from util import liner from .hotkeys import ACTION_DIRECTIONS, Action, ActionList, get_action from .loops import std_loop, easy_exit_loop from .color import Color diff --git a/pokete_classes/side_loops.py b/pokete_classes/side_loops.py index 7925792e..05fcd829 100644 --- a/pokete_classes/side_loops.py +++ b/pokete_classes/side_loops.py @@ -3,7 +3,7 @@ import os import scrap_engine as se import pokete_classes.game_map as gm -from pokete_general_use_fns import liner +from util import liner from .loops import easy_exit_loop from .ui_elements import InfoBox from . import movemap as mvp diff --git a/pokete_general_use_fns.py b/pokete_general_use_fns.py index b4f084ce..a9909636 100644 --- a/pokete_general_use_fns.py +++ b/pokete_general_use_fns.py @@ -4,44 +4,6 @@ import release -def liner(text, width, pre=""): - """Wraps a string after a certain length and respects word endings - ARGS: - text: The text that should be lined - width: The max width - pre: Prefix that will be added in the next line - RETURNS: - The lined string""" - lens = 0 - out = "" - for name in text.split(" "): - if "\n" in name: - lens = len(pre) - out += name + pre - elif lens+len(name) + 1 <= width: - out += name + " " - lens += len(name) + 1 - else: - lens = len(name) + 1 + len(pre) - out += "\n" + pre + name + " " - return out - - -def hard_liner(l_len, name): - """Wraps a string after a certain length - ARGS: - name: The String - l_len: The max length - RETURNS: - The lined string""" - ret = "" - for i in range(int(len(name) / l_len) + 1): - ret += name[i * l_len:(i + 1) * l_len] + ("\n" - if i != int(len(name) / l_len) - else "") - return ret - - def sort_vers(vers): """Sorts versions ARGS: diff --git a/util/__init__.py b/util/__init__.py index 706700bb..45d99e1d 100644 --- a/util/__init__.py +++ b/util/__init__.py @@ -2,3 +2,4 @@ from .pages import prepare_after, prepare_before from .release import main as make_release from .install import install +from .liner import liner, hard_liner diff --git a/util/liner.py b/util/liner.py new file mode 100644 index 00000000..2934472a --- /dev/null +++ b/util/liner.py @@ -0,0 +1,36 @@ +def liner(text, width, pre=""): + """Wraps a string after a certain length and respects word endings + ARGS: + text: The text that should be lined + width: The max width + pre: Prefix that will be added in the next line + RETURNS: + The lined string""" + lens = 0 + out = "" + for name in text.split(" "): + if "\n" in name: + lens = len(pre) + out += name + pre + elif lens + len(name) + 1 <= width: + out += name + " " + lens += len(name) + 1 + else: + lens = len(name) + 1 + len(pre) + out += "\n" + pre + name + " " + return out + + +def hard_liner(l_len, name): + """Wraps a string after a certain length + ARGS: + name: The String + l_len: The max length + RETURNS: + The lined string""" + ret = "" + for i in range(int(len(name) / l_len) + 1): + ret += name[i * l_len:(i + 1) * l_len] + ("\n" + if i != int(len(name) / l_len) + else "") + return ret From 7cc053853692170b01f766f6cc28b79f0fc825dc Mon Sep 17 00:00:00 2001 From: lxgr-linux Date: Sat, 13 Jul 2024 11:38:03 +0200 Subject: [PATCH 23/26] feat(#287): removed pokete_general_use_fns --- pokete.py | 39 +++++++++++++++++++++-- pokete_general_use_fns.py | 66 --------------------------------------- util/__init__.py | 1 + util/command/command.py | 7 +++-- util/versions.py | 8 +++++ util/wiki.py | 1 - 6 files changed, 50 insertions(+), 72 deletions(-) delete mode 100644 pokete_general_use_fns.py create mode 100644 util/versions.py diff --git a/pokete.py b/pokete.py index 1de122f6..600cc57c 100755 --- a/pokete.py +++ b/pokete.py @@ -19,6 +19,7 @@ from datetime import datetime import scrap_engine as se import pokete_data as p_data +import release from pokete_classes import animations from pokete_classes.pokestats import PokeStats from pokete_classes.poke import Poke, upgrade_by_one_lvl @@ -55,11 +56,11 @@ from pokete_classes.dex import Dex from pokete_classes.loops import std_loop from pokete_classes.periodic_event_manager import PeriodicEventManager -from util import liner -from pokete_general_use_fns import sort_vers, parse_args +from util import liner, sort_vers from release import SPEED_OF_TIME from release import VERSION, CODENAME, SAVEPATH +from util.command import RootCommand, Flag __t = time.time() @@ -1478,7 +1479,39 @@ def map_additions(): # Actual code execution ####################### if __name__ == "__main__": - do_logging, load_mods, audio.use_audio = parse_args(sys.argv) + log_flag = Flag(["--log"], "Enables logging") + mods_flag = Flag(["--no_mods"], "Disables mods") + audio_flag = Flag(["--no_audio"], "Disables audio") + + do_logging = False + load_mods = True + audio.use_audio = True + + + def root_fn(ex: str, options: list[str], + flags: dict[str, list[str]]): + global do_logging, load_mods + for flag in flags: + if log_flag.is_flag(flag): + do_logging = True + elif mods_flag.is_flag(flag): + load_mods = False + elif audio_flag.is_flag(flag): + audio.use_audio = False + + + c = RootCommand( + "Pokete", f"{release.CODENAME} v{release.VERSION}", root_fn, + flags=[log_flag, mods_flag, audio_flag], + additional_info=f"""All save and logfiles are located in ~{release.SAVEPATH}/ +Feel free to contribute. +See README.md for more information. +This software is licensed under the GPLv3, you should have gotten a +copy of it alongside this software.""" + ) + + c.exec() + # deciding on wich input to use if sys.platform == "win32": import msvcrt diff --git a/pokete_general_use_fns.py b/pokete_general_use_fns.py deleted file mode 100644 index a9909636..00000000 --- a/pokete_general_use_fns.py +++ /dev/null @@ -1,66 +0,0 @@ -"""General use functions for Pokete""" - -import sys -import release - - -def sort_vers(vers): - """Sorts versions - ARGS: - vers: List of versions - RETURNS: - Sorted list""" - return [k[-1] for k in - sorted([([int(j) for j in i.split(".")], i) for i in vers])] - - -def print_help(path): - """Shows help message - ARGS: - path: The game's path""" - print(f"""Pokete {release.CODENAME} v{release.VERSION} -Usage: {path} () -Options: - --log : Enables logging - --help : Shows this help - --no_mods : Disables mods - --no_audio : Disables - -Homepage: https://github.com/lxgr-linux/pokete - -All save and logfiles are located in ~{release.SAVEPATH}/ -Feel free to contribute. -See README.md for more information. -This software is licensed under the GPLv3, you should have gotten a -copy of it alongside this software. -Copyright (c) lxgr-linux 2022""") - - -def parse_args(args): - """Parses command line args - ARGS: - args: Arguments given to the game - RETURNS: - Tuple of do_logging, load_mods and use_audio""" - do_logging = False - load_mods = True - use_audio = True - for arg in args[1:]: - if arg == "--log": - do_logging = True - elif arg == "--no_mods": - load_mods = False - elif arg == "--no_audio": - use_audio = False - elif arg == "--help": - print_help(args[0]) - sys.exit(0) - else: - print(f":: Error: '{arg}' is not a valid option! See '--help' for \ -options.") - sys.exit(1) - return do_logging, load_mods, use_audio - - -if __name__ == "__main__": - print("\033[31;1mDo not execute this!\033[0m") diff --git a/util/__init__.py b/util/__init__.py index 45d99e1d..243fde78 100644 --- a/util/__init__.py +++ b/util/__init__.py @@ -3,3 +3,4 @@ from .release import main as make_release from .install import install from .liner import liner, hard_liner +from .versions import sort_vers diff --git a/util/command/command.py b/util/command/command.py index 92f55ac3..b306874d 100644 --- a/util/command/command.py +++ b/util/command/command.py @@ -18,13 +18,15 @@ def __init__( name: str, desc: str, fn, flags: list[Flag] | None = None, - commands: list["Command"] | None = None + commands: list["Command"] | None = None, + additional_info: str = "" ): self.name = name self.desc = desc self.fn = fn self.flags = (flags if flags is not None else []) + [ Flag(["-h", "--help"], "Shows help for a specific command")] + self.additional_info = additional_info self.commands = commands if commands is not None else [] def __print_help(self, ex: str): @@ -40,7 +42,7 @@ def __print_help(self, ex: str): Flags: {"\n".join(f"\t{"|".join(flag.aliases)}\t\t{flag.desc}" for flag in self.flags)} """ if self.flags else ""} - +{f"\n{self.additional_info}\n" if self.additional_info else ""} Copyright (c) lxgr-linux 2024""") def run(self, ex: str, options: list[str], @@ -62,6 +64,7 @@ def run(self, ex: str, options: list[str], sys.exit(2) if "--help" in flags or "-h" in flags: self.__print_help(ex) + sys.exit(0) else: self.fn(ex, options, flags) diff --git a/util/versions.py b/util/versions.py new file mode 100644 index 00000000..9fa7f6bc --- /dev/null +++ b/util/versions.py @@ -0,0 +1,8 @@ +def sort_vers(vers): + """Sorts versions + ARGS: + vers: List of versions + RETURNS: + Sorted list""" + return [k[-1] for k in + sorted([([int(j) for j in i.split(".")], i) for i in vers])] diff --git a/util/wiki.py b/util/wiki.py index 521b876d..60b3e018 100755 --- a/util/wiki.py +++ b/util/wiki.py @@ -627,7 +627,6 @@ def gen(ex: str, options: list[str], gen_pics() else: for flag in flags: - print(flag) if silent_flag.is_flag(flag): SILENT, QUIET, VERBOSE = True, False, False elif quiet_flag.is_flag(flag): From 97e815437b0c0307411a6484b1cca49d8826fd0e Mon Sep 17 00:00:00 2001 From: lxgr-linux Date: Sat, 13 Jul 2024 11:49:27 +0200 Subject: [PATCH 24/26] feat(#287): Added usage to commands --- pokete.py | 3 ++- util.py | 23 ++++++++++++++++------- util/command/command.py | 6 ++++-- util/install.py | 11 ----------- util/wiki.py | 26 -------------------------- 5 files changed, 22 insertions(+), 47 deletions(-) diff --git a/pokete.py b/pokete.py index 600cc57c..fd647203 100755 --- a/pokete.py +++ b/pokete.py @@ -1507,7 +1507,8 @@ def root_fn(ex: str, options: list[str], Feel free to contribute. See README.md for more information. This software is licensed under the GPLv3, you should have gotten a -copy of it alongside this software.""" +copy of it alongside this software.""", + usage="" ) c.exec() diff --git a/util.py b/util.py index afe694df..446bd3ee 100755 --- a/util.py +++ b/util.py @@ -18,7 +18,10 @@ def main(): "Pokete utility", fallback, commands=[ - Command("install", "Install pokete to a given directory", install), + Command( + "install", "Install pokete to a given directory", install, + usage="[dest]" + ), Command( "prepare-pages", "Prepares github pages", fallback, commands=[ @@ -28,12 +31,18 @@ def main(): prepare_after) ] ), - Command("release", "Prepare all relevant files for release", - make_release), - Command("wiki", "Generate a markdown wiki", gen_wiki, flags=[ - wiki.silent_flag, wiki.quiet_flag, wiki.verbose_flag, - wiki.single_flag, wiki.multi_flag, wiki.pics_flag - ]) + Command( + "release", "Prepare all relevant files for release", + make_release, + additional_info="Tags have to follow the `vMAJOR.MINOR.PATCH-RELEASE` semantic.", + usage="[tag]" + ), + Command( + "wiki", "Generate a markdown wiki", gen_wiki, flags=[ + wiki.silent_flag, wiki.quiet_flag, wiki.verbose_flag, + wiki.single_flag, wiki.multi_flag, wiki.pics_flag + ] + ) ] ) diff --git a/util/command/command.py b/util/command/command.py index b306874d..efa6a1f2 100644 --- a/util/command/command.py +++ b/util/command/command.py @@ -19,7 +19,8 @@ def __init__( fn, flags: list[Flag] | None = None, commands: list["Command"] | None = None, - additional_info: str = "" + additional_info: str = "", + usage="[command] [options]..." ): self.name = name self.desc = desc @@ -28,12 +29,13 @@ def __init__( Flag(["-h", "--help"], "Shows help for a specific command")] self.additional_info = additional_info self.commands = commands if commands is not None else [] + self.usage = usage def __print_help(self, ex: str): print(f"""{self.name} -- {self.desc} Usage: - {ex} [command] [options]... + {ex}{f" {self.usage}" if self.usage else ""} {f""" Options: {"\n".join(f"\t{command.name}\t\t{command.desc}" for command in self.commands)} diff --git a/util/install.py b/util/install.py index e54d6614..3755f049 100644 --- a/util/install.py +++ b/util/install.py @@ -2,17 +2,6 @@ import sys -def show_help(ex: str, command: str): - print(f"""{ex} {command} -- Install pokete to a given directory -Usage: - {ex} {command} [dest] - -Flags: - --help\tShows help for a specific command - -Copyright (c) lxgr-linux 2024""") - - def install(ex: str, options: list[str], flags: dict[str, list[str]]): if len(options) == 0: diff --git a/util/wiki.py b/util/wiki.py index 60b3e018..5c867e2b 100755 --- a/util/wiki.py +++ b/util/wiki.py @@ -592,32 +592,6 @@ def gen_pics(): file.write(md_str) -def show_help(ex: str, command: str): - print(f"""{ex} {command} -- Generate a markdown wiki -Usage: - {ex} {command} [options]... - -Options: - silent:\t\tPrints no statements at all - quite:\t\tPrints only some minimal statements - verbose:\tPrints everything that it's doing - single:\t\tGenerated the `wiki.md` as a single file - multi:\t\tGenerates a folder `wiki` with the wiki files - \t\t(Warning: Links are for html pages, not markdown pages!) - pics:\t\tGenerates the `assets/pics.md` file with all sample pictures - -Flags: - --help\t\tShows help for a specific command - -Examples: - - {ex} {command} silent single verbose multi - Creates wiki.md silently and the multi-wiki verbosely - - {ex} {command} quite single multi pics - Creates wiki.md, the multi-page wiki and pics.md quitely - -Copyright (c) lxgr-linux 2024""") - - def gen(ex: str, options: list[str], flags: dict[str, list[str]]): global SILENT, QUIET, VERBOSE From 4fb5a291f7ac289b5452b46e62332554056ade21 Mon Sep 17 00:00:00 2001 From: lxgr-linux Date: Sat, 13 Jul 2024 12:03:20 +0200 Subject: [PATCH 25/26] feat(#287): Added spacing to command help --- util/command/command.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/util/command/command.py b/util/command/command.py index efa6a1f2..825f576a 100644 --- a/util/command/command.py +++ b/util/command/command.py @@ -31,18 +31,34 @@ def __init__( self.commands = commands if commands is not None else [] self.usage = usage + @staticmethod + def __line_setter(lines: list[tuple[str, str]], line_spaces: int): + return "\n".join( + f"\t{line[0]}{" " * (line_spaces - len(line[0]))}{line[1]}" for line + in lines + ) + def __print_help(self, ex: str): + option_lines: list[tuple[str, str]] = [(command.name, command.desc) for + command in self.commands] + flag_lines: list[tuple[str, str]] = [ + ("|".join(flag.aliases), flag.desc) for flag in self.flags] + + line_spaces = sorted([ + len(i[0]) for i in option_lines + flag_lines + ])[-1] + 8 + print(f"""{self.name} -- {self.desc} Usage: {ex}{f" {self.usage}" if self.usage else ""} {f""" Options: -{"\n".join(f"\t{command.name}\t\t{command.desc}" for command in self.commands)} +{self.__line_setter(option_lines, line_spaces)} """ if self.commands else ""} {f""" Flags: -{"\n".join(f"\t{"|".join(flag.aliases)}\t\t{flag.desc}" for flag in self.flags)} +{self.__line_setter(flag_lines, line_spaces)} """ if self.flags else ""} {f"\n{self.additional_info}\n" if self.additional_info else ""} Copyright (c) lxgr-linux 2024""") From f0e82234ad228c1a7cf40b7df778015f18e7f386 Mon Sep 17 00:00:00 2001 From: lxgr-linux Date: Sat, 13 Jul 2024 12:04:08 +0200 Subject: [PATCH 26/26] feat(#287): Removed last help function --- util/release/__init__.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/util/release/__init__.py b/util/release/__init__.py index 69b3a166..9a560ca2 100644 --- a/util/release/__init__.py +++ b/util/release/__init__.py @@ -22,19 +22,6 @@ def __is_tag_valid(tag: str) -> bool: return re.fullmatch(TAG_REGEX, tag) is not None -def show_help(ex: str, command: str): - print(f"""{ex} {command} -- Prepare all relevant files for release -Usage: - {ex} {command} [tag] - -Tags have to follow the `vMAJOR.MINOR.PATCH-RELEASE` semantic. - -Flags: - --help\tShows help for a specific command - -Copyright (c) lxgr-linux 2024""") - - def main( ex: str, options: list[str], flags: dict[str, list[str]]