This repository was archived by the owner on Apr 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetting.py
More file actions
41 lines (35 loc) · 1.34 KB
/
setting.py
File metadata and controls
41 lines (35 loc) · 1.34 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
from json_tool import JsonTool
class Setting:
"""certain values, which can be read out of a file, which change how the program behaves are in this
class"""
def __init__(self):
self.filename = None
self.file = None
self.processes_to_track = []
self.time_delay = 2
self.file_content_object = None
self.excluded_processes = []
self.log_filename = "log.json"
def load_from_file(self, filename):
self.filename = filename
self.read_json()
def to_json(self):
settings = {
"processes_to_track": self.processes_to_track,
"time_delay": self.time_delay,
"excluded_processes": self.excluded_processes,
"log_filename": self.log_filename
}
return settings
def parse(self):
try:
self.processes_to_track = self.file_content_object["processes_to_track"]
self.time_delay = self.file_content_object["time_delay"]
self.excluded_processes = self.file_content_object["excluded_processes"]
self.log_filename = self.file_content_object["log_filename"]
except KeyError as e:
print(e)
def read_json(self):
json_reader = JsonTool(filename=self.filename)
self.file_content_object = json_reader.get_json()
self.parse()