-
Notifications
You must be signed in to change notification settings - Fork 1
/
add_module.py
54 lines (40 loc) · 1.74 KB
/
add_module.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import logging, yaml, shutil, argparse
from git import Repo
def main():
logging.basicConfig(
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO
)
parser = argparse.ArgumentParser(description='PyTG command line add module utility')
parser.add_argument("--folder")
parser.add_argument("--repo")
parser.add_argument("--subfolder")
parser.add_argument("--source-only", action="store_true")
args = parser.parse_args()
if not args.folder and not args.repo:
logging.error("No source template specified")
return
logging.info("Recognizing template...")
if args.folder:
source_folder = args.folder
elif args.repo:
Repo.clone_from(args.repo, "repo_tmp/")
if args.subfolder:
source_folder = "repo_tmp/{}".format(args.subfolder)
else:
source_folder = "repo_tmp/"
descriptor = yaml.safe_load(open("{}/descriptor.yaml".format(source_folder), "r"))
logging.info("Adding module '{}' from template {}...".format(descriptor['module_name'], args.folder))
src_destination_folder = "modules/{}".format(descriptor["module_name"])
content_destination_folder = "content/{}".format(descriptor["module_name"])
# Copy source
logging.info("Copying source...")
shutil.copytree("{}/src".format(source_folder), src_destination_folder)
if not args.source_only and ("source_only" not in descriptor.keys() or not descriptor["source_only"]):
logging.info("Copying content...")
shutil.copytree("{}/dist_content".format(source_folder), content_destination_folder)
# If repo is used, remove folder
if args.repo:
shutil.rmtree("repo_tmp/")
if __name__ == "__main__":
main()