-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
executable file
·62 lines (48 loc) · 1.39 KB
/
setup.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
55
56
57
58
59
60
61
62
#! /usr/bin/python
import shutil
import sys
import os
import datetime
from enum import Enum
from typing import List
class Action(Enum):
CREATE_DIRECTORY = 0
CREATE_EMPTY_FILE = 1
COPY_CODE_FROM_TEMPLATE = 2
def create(path: str, action: Action) -> None:
if os.path.exists(path):
print('exists:', path)
else:
if action == Action.CREATE_DIRECTORY:
os.makedirs(path)
elif action == Action.CREATE_EMPTY_FILE:
open(path, 'w')
elif action == Action.COPY_CODE_FROM_TEMPLATE:
shutil.copyfile('template.py', path)
else:
raise ValueError('Unsupported action: ' + action.name)
print('created:', path)
def main(args: List[str]) -> int:
if len(args) == 1:
print('Usage: setup.py [year=current] <day>')
return 1
elif len(args) == 2:
year = str(datetime.datetime.now().year)
day = args[1]
elif len(args) == 3:
year = args[1]
day = args[2]
else:
raise ValueError(f'Too many arguments provided. Expected 1-2 but received {len(args) - 1}')
create(year, Action.CREATE_DIRECTORY)
problem_directory = f'{year}/day{day.zfill(2)}/'
create(problem_directory, Action.CREATE_DIRECTORY)
for file in 'part1', 'part2':
file_path = problem_directory + file + '.py'
create(file_path, Action.COPY_CODE_FROM_TEMPLATE)
for file in 'example', 'input':
file_path = problem_directory + file + '.txt'
create(file_path, Action.CREATE_EMPTY_FILE)
print('done!')
return 0
exit(main(sys.argv))