-
Notifications
You must be signed in to change notification settings - Fork 0
/
engine.py
129 lines (104 loc) · 3.65 KB
/
engine.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# -*- coding: utf-8 -*-
#-----------------------------------------------------------------------------
# project: chinook
# authors: 1966bc
# mailto: [[email protected]]
# modify: hiems MMXXI
#-----------------------------------------------------------------------------
import os
import sys
import inspect
import datetime
import subprocess
from dbms import DBMS
from clock import Clock
from tools import Tools
class Engine(DBMS, Clock, Tools):
def __init__(self,):
super().__init__()
self.no_selected = "Attention!\nNo record selected!"
self.ask_to_delete = "Delete data?"
self.ask_to_save = "Save data?"
self.abort = "Operation aborted!"
def __str__(self):
return "class: {0}\nMRO:{1}".format(self.__class__.__name__,
[x.__name__ for x in Engine.__mro__])
def get_clock(self,):
"""Instance the clock."""
return Clock()
def get_python_version(self,):
return "Python version:\n{0}".format(".".join(map(str, sys.version_info[:3])))
def get_file(self, file):
"""# return full path of the directory where program resides."""
return os.path.join(os.path.dirname(__file__), file)
def open_file(self, path):
"""open file on linux and windows"""
if os.path.exists(path):
if os.name == 'posix':
subprocess.call(["xdg-open", path])
else:
os.startfile(path)
def on_log(self, container, function, exc_value, exc_type, module):
now = datetime.datetime.now()
log_text = "{0}\n{1}\n{2}\n{3}\n{4}\n\n".format(now, function, exc_value, exc_type, module)
log_file = open("log.txt", "a")
log_file.write(log_text)
log_file.close()
def get_dimensions(self):
try:
d = {}
with open("dimensions", "r") as filestream:
for line in filestream:
currentline = line.split(",")
d[currentline[0]] = currentline[1]
return d
except FileNotFoundError:
self.on_log(self,
inspect.stack()[0][3],
sys.exc_info()[1],
sys.exc_info()[0],
sys.modules[__name__])
def get_license(self):
"""get license"""
try:
path = self.get_file("LICENSE")
f = open(path, "r")
v = f.read()
f.close()
return v
except FileNotFoundError:
self.on_log(inspect.stack()[0][3],
sys.exc_info()[1],
sys.exc_info()[0],
sys.modules[__name__])
def get_icon(self, which):
try:
path = self.get_file(which)
f = open(path, "r")
v = f.readline()
f.close()
return v
except FileNotFoundError:
self.on_log(self,
inspect.stack()[0][3],
sys.exc_info()[1],
sys.exc_info()[0],
sys.modules[__name__])
def get_log_file(self):
try:
path = self.get_file("log.txt")
self.open_file(path)
except FileNotFoundError:
self.on_log(self,
inspect.stack()[0][3],
sys.exc_info()[1],
sys.exc_info()[0],
sys.modules[__name__])
def main():
#testing some stuff
foo = Engine()
print(foo)
print(foo.set_connection())
input('end')
if __name__ == "__main__":
main()