-
Notifications
You must be signed in to change notification settings - Fork 2
/
DatabaseClass.py
executable file
·65 lines (50 loc) · 1.91 KB
/
DatabaseClass.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
# Author: PlanckBit
# MIT License
# Copyright (c) 2019 PlanckBit
import random
import tempfile
class DatabaseClass:
# Keep track of total instances.
instanceCount = 0
# Used for creating a unique instance ID
instanceSeedID=99
# tempfile director location
tempfile.tempdir = tempfile.mkdtemp()
def __init__(self, description: str):
DatabaseClass.instanceCount += 1
DatabaseClass.instanceSeedID = random.randint(DatabaseClass.instanceSeedID+1,
DatabaseClass.instanceSeedID+100)
self.description = description
def createTempFile(self):
try:
self.tempFile = tempfile.NamedTemporaryFile()
except:
print("Exception in tempFile creation")
def closeTempFile(self):
try:
self.tempFile.close()
except:
print("Exception closing tempFile")
def getTempFileName(self):
return self.tempFile.name
def writeTempFileName(self, inputBytes: b''):
self.tempFile.write(inputBytes)
def readTempFileName(self):
self.tempFile.seek(0)
return self.tempFile.read()
def getDataBaseName(self):
return self.dataBaseName
def setDataBaseName(self, dataBaseName: str):
self.dataBaseName = dataBaseName
def getDescription(self):
return self.description
def setDescription(self, description: str):
self.description = description
def getInstanceCount(self):
return DatabaseClass.instanceCount
def __del__(self, description: str = "None", instanceID: int = None):
print("Deleted - "+description+" InstanceID="+str(instanceID))
DatabaseClass.instanceCount -= 1
# static method for logging purpose.
def printClassFunctionName(className: str, functionName: str):
print("==============================>" + className + "." + functionName)