-
Notifications
You must be signed in to change notification settings - Fork 0
/
scaffold.py
executable file
·37 lines (28 loc) · 1022 Bytes
/
scaffold.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
#!/usr/bin/env python3
"""Create a new directory with the structure typically used for a day"""
import argparse
import os
import shutil
def main():
"""Entry point for script"""
args = get_arguments()
folder_name = "day" + str(args.DayOfMonth)
scaffold_folder(folder_name)
def get_arguments() -> argparse.Namespace:
"""Gets the cli arguments"""
parser = argparse.ArgumentParser(
description="Scaffold a new day from template"
)
parser.add_argument("DayOfMonth", type=int)
return parser.parse_args()
def scaffold_folder(name: str):
"""Create a new folder from the template if the folder doesn't exist"""
parent_dir = os.path.dirname(__file__)
template_dir = os.path.join(parent_dir, "template")
dst_dir = os.path.join(parent_dir, name)
shutil.copytree(template_dir, dst_dir, dirs_exist_ok=False)
src = os.path.join(dst_dir, "template.py")
dst = os.path.join(dst_dir, name + ".py")
os.rename(src, dst)
if __name__ == "__main__":
main()