-
Notifications
You must be signed in to change notification settings - Fork 2
/
utils.py
25 lines (22 loc) · 953 Bytes
/
utils.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
import os
class Config:
def __init__(self, config_path=".config/workoutPlan.conf"):
self.config_path = os.environ.get("HOME") + "/" + config_path
if os.path.exists(self.config_path):
print("Config file found at " + self.config_path)
self.log_path = open(self.config_path).readline()
print(self)
else:
if self.config_path[-5:] != ".conf":
raise ValueError("Config file must be a path ending in .conf")
print("Creating new config file " + self.config_path)
self.log_path = input("Enter location of log folder: ")
self.log_path = "LOGPATH=" + self.log_path + "\n"
self.save()
def __str__(self):
return self.log_path
def save(self):
stream = open(self.config_path, "wt")
stream.write(self.log_path)
stream.close()
print("Config file created at " + self.config_path)