-
Notifications
You must be signed in to change notification settings - Fork 0
/
class_settings.py
49 lines (41 loc) · 1.27 KB
/
class_settings.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
import json
import tempfile
import uuid
"""
Файл настроек имеет следующий вид:
{
"server": "mssqlserver",
"database": "dbname",
"login": "login",
"password": "password",
"ofd_login": "name",
"ofd_password": "password",
"ofd_token": "hex_array"
}
"""
class Settings:
def __init__(self, filename="ofd_request.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