-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass_configfile.py
More file actions
40 lines (34 loc) · 1.1 KB
/
class_configfile.py
File metadata and controls
40 lines (34 loc) · 1.1 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
#class_configfile.py
###############################################################
# File utilities
#
# Author: Adam A. Koch (aakoch)
# Date: 2018-04-03
# Copyright (c) 2018 Adam A. Koch
# This work is licensed under the MIT license.
###############################################################
import uio, uos
class ConfigFile():
def _file_exists(self, filename):
for file in uos.ilistdir():
if (file[0] == filename):
return True
return False
def set_property(self, key, value):
file = uio.open(key + ".config", "wt")
file.write(str(value))
file.close()
def get_property(self, key):
filename = key + ".config"
if (self._file_exists(filename)):
file = uio.open(filename, "rt")
value = file.read()
file.close()
else:
print("Could not find property with name " + key)
return None
return value
def delete_property(self, key):
filename = key + ".config"
if (self._file_exists(filename)):
file = uos.remove(filename)