From 7da128ea808769daaf9bcf7ba934f7a12dffb5f5 Mon Sep 17 00:00:00 2001 From: "Soren I. Bjornstad" Date: Wed, 25 Aug 2021 15:06:42 -0500 Subject: [PATCH] set up config file --- config.py | 21 +++++++++++++++++++++ tzk.py | 21 +++++++++++++++------ 2 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 config.py diff --git a/config.py b/config.py new file mode 100644 index 0000000..7320c00 --- /dev/null +++ b/config.py @@ -0,0 +1,21 @@ +import importlib +import os +from pathlib import Path +import sys + +config_path = Path.cwd() + +for child in sorted(config_path.iterdir()): + if child.is_file() and child.name.endswith('.py'): + mod_name = child.name.rsplit('.', 1)[0] + if mod_name == 'tzk_config': + sys.path.insert(0, str(config_path)) + importlib.import_module(mod_name) + del sys.path[0] + break +else: + print( + f"Your TZK config file could not be found. " + f"Please ensure there is a file called tzk_config.py " + f"in the current directory.", file=sys.stderr) + sys.exit(1) diff --git a/tzk.py b/tzk.py index 79c500f..3982a8d 100644 --- a/tzk.py +++ b/tzk.py @@ -22,18 +22,29 @@ class CommitCommand(CliCommand): @classmethod def setup_arguments(self, parser: argparse.ArgumentParser) -> None: parser.add_argument( - "-m, --message", + "-m", "--message", metavar="MSG", help="Commit message to use.", - default="daily checkpoint") + default="daily checkpoint" + ) + parser.add_argument( + "-l", "--local", + help="Don't push the results to any configured remote repository.", + action="store_true" + ) def execute(self, args: argparse.Namespace) -> None: - os.chdir("zk-wiki") git.exec("add", "-A") git.exec("commit", "-m", args.message) - git.exec("push", "backup") + if not args.local: + git.exec("push", "backup") +import config + +os.chdir("zk-wiki") +# TODO: confirm we're in the right directory + parser = argparse.ArgumentParser() subparsers = parser.add_subparsers() for command in CliCommand.__subclasses__(): @@ -42,6 +53,4 @@ for command in CliCommand.__subclasses__(): command.setup_arguments(subparser) args = parser.parse_args() -print(type(args)) -9/0 args._cls().execute(args)