Skip to content

Commit

Permalink
Implement sample project autocreation
Browse files Browse the repository at this point in the history
- Use `hworker --sample --command run` to test
  • Loading branch information
George V. Kouryachy (Fr. Br. George) committed Aug 28, 2023
1 parent 0834b01 commit 4288103
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@


### Workflow files
data.db
logs/
sample/

# Configs
hworker*.toml
Expand Down
21 changes: 20 additions & 1 deletion hworker/control/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import shlex
import sys
import os
import shutil
from pathlib import Path
from pprint import pprint

Expand Down Expand Up @@ -180,17 +181,35 @@ def emptyline(self):
pass


def copy_sample(path: Path) -> Path:
"""Copy sample project from inside package
:param path: Destination path
:return: Sample project config file name"""

from .. import __path__ as module_path

P = Path(path)
shutil.copytree(Path(module_path[0]) / "example", P, dirs_exist_ok=True)
return str(P / "example.toml")


def shell():
parser = argparse.ArgumentParser(description="Homework checker")
parser.add_argument("-c", "--command", action="append", help="Run a command")
parser.add_argument(
"-e",
"--external",
action="store_true",
help="Treat config file as external one and use current directory as project path",
)
parser.add_argument("-c", "--command", action="append", help="Run a COMMAND")
parser.add_argument(
"-s", "--sample", nargs="?", metavar="PATH", const="sample", help="Copy a sample project into PATH"
)
parser.add_argument("config", nargs="*", help="Configuration file to parse")
args = parser.parse_args()
if args.sample:
args.config.insert(0, copy_sample(args.sample))
if args.config:
finalconf = config.process_configs(*args.config)
if not args.external:
Expand Down

0 comments on commit 4288103

Please sign in to comment.