-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_config.py
More file actions
53 lines (40 loc) · 1.19 KB
/
generate_config.py
File metadata and controls
53 lines (40 loc) · 1.19 KB
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
import os
import sys
import json
import pathlib
from contextlib import contextmanager
@contextmanager
def suppress_stdout():
with open(os.devnull, 'w') as devnull:
valid_stdout = sys.stdout
sys.stdout = devnull
try:
yield
finally:
sys.stdout = valid_stdout
with suppress_stdout():
import pyart
import bugtracker.config
def generate_config():
"""
Create a config file that is rooted in some user-specified
directory.
"""
print("Specify a directory for Bugtracker application data:")
bugtracker_root = input(">")
# Check if parent directory exists
root_path = pathlib.Path(bugtracker_root)
parent = root_path.parent
if not os.path.isdir(parent):
raise FileNotFoundError(f"Path parent does not exist: {parent}")
if not os.path.isdir(bugtracker_root):
os.mkdir(bugtracker_root)
output_json = os.path.join("apps", "bugtracker.json")
template = bugtracker.config.ConfigTemplate()
template.populate(bugtracker_root)
print("template data:")
print(template.data)
template.write(output_json)
template.make_folders()
if __name__ == "__main__":
generate_config()