forked from XilefTech/CharlieOSX
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprofileHelper.py
More file actions
Latest commit
101 lines (90 loc) · 3.5 KB
/
Copy pathprofileHelper.py
File metadata and controls
101 lines (90 loc) · 3.5 KB
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
importos
fromcopyimportdeepcopy
classProfileHelper():
'''
ProfileHelper is a helper class to load and save the profiles to a file and load them from that file.
Args:
logger (Logger): initialized Logger class used for logging
config (dict): The path to the config file.
'''
def__init__(self, logger, config):
logger.info(self, 'Initialisating ProfileHelper...')
self.logger=logger
self.__config=config
self.foldername=self.__config['profileFolderName']
self._data= {}
self.logger.info(self, 'Done initialisating ProfileHelper...')
self.loadProfiles()
def__repr__(self):
return'TODO'
def__str__(self):
return'ProfileHelper'
defloadProfiles(self):
'''
Loads the data from all the Profiles stored on the brick.
'''
self.logger.info(self, 'Loading profiles...')
try:
ifnotself.foldernameinos.listdir():
os.mkdir(self.foldername)
os.chdir(self.foldername)
forkinself.__config['profileNames']:
ifnot'%s.dat'%kinos.listdir():
open('%s.dat'%k, 'a').close()
self._data[k] = []
withopen('%s.dat'%k, 'r') asdat:
forlineindat:
l=line.split(', ')
intList= [float(s) forsinl]
self._data[k].append(intList)
self.logger.info(self, 'Loaded profiles sucessfully')
exceptExceptionasexception:
self.logger.error(self, 'Failed to load Profiles', exception)
os.chdir('..')
def_saveProfiles(self):
'''
Saves the data of all the Profiles to the brick.
'''
self.logger.info(self, 'Saving profiles....')
try:
ifnotself.foldernameinos.listdir():
os.mkdir(self.foldername)
os.chdir(self.foldername)
forkinself.__config['profileNames']:
ifnot'%s.dat'%kinos.listdir():
open('%s.dat'%k, 'a').close()
ffile=open('%s.dat'%k, 'w')
strArr=''
forlinself._data[k]:
foriinl:
strArr+=str(i) +', '
strArr=strArr[:-2]
ffile.write(strArr+'\n')
strArr=''
ffile.close()
exceptExceptionasexception:
self.logger.error(self, 'Failed to save Profiles', exception)
os.chdir('..')
defgetProfileData(self, profile):
'''
Function to get the data of a given profile. WIP
Args:
profile (str): The name of the profile
Returns:
array: The array of number code arrays frome the given profile
'''
try:
x=deepcopy(self._data[profile])
returnx
exceptKeyErrorasexception:
self.logger.warn(self, 'Couldn\'t get profile data for %s: No such profile in data'%str(exception))
defsetProfileData(self, profile, data):
'''
Function to set the data of a given profile. WIP
Args:
profile (str): The name of the profile
data (array): The array with the data
'''
self.logger.debug(self, 'Setting Profile data for profile "%s"'%profile)
self._data[profile] =deepcopy(data)
self._saveProfiles()