-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass_settings.py
More file actions
36 lines (29 loc) · 1005 Bytes
/
class_settings.py
File metadata and controls
36 lines (29 loc) · 1005 Bytes
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
import json
import tempfile
import uuid
class Settings:
def __init__(self, filename="settings.json"):
try:
with open(filename, "r") as file:
self.__settings = json.loads(file.read())
self.__errors = False
except Exception as E:
self.__errors = True
print(f"Исключительная ситуация: {E}")
def param(self, param_name):
return self.__settings.get(param_name, None)
@property
def errors(self):
return self.__errors
@property
def new_id(self):
return str(uuid.uuid4())
@classmethod
def random_file_name(cls, ext="tmp"):
if tempfile.gettempdir()[:-1] == "\\":
return tempfile.gettempdir() + str(uuid.uuid4()) + "." + ext
else:
return tempfile.gettempdir() + "\\" + str(uuid.uuid4()) + "." + ext
@classmethod
def random_file_name_local(cls, ext="dump"):
return str(uuid.uuid4()) + "." + ext