set up config file

This commit is contained in:
Soren I. Bjornstad 2021-08-25 15:06:42 -05:00
parent af147196e2
commit 7da128ea80
2 changed files with 36 additions and 6 deletions

21
config.py Normal file
View File

@ -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)

21
tzk.py
View File

@ -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)