13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# Here conf is already an instantiation of the underlying
# Config class.
#
import os
import sys
import pson
import gzip
import platform
#-- create a single instance of config object
|
|
|
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# Here conf is already an instantiation of the underlying
# Config class.
#
import os
import sys
import json
import gzip
import platform
#-- create a single instance of config object
|
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
if gz:
f = gzip.open(file+".gz", "w")
if os.path.exists(file):
os.unlink(file)
else:
f = open(file, "w")
# encode
pson.dump(data, f, indent=(4 if nice else None))
f.close()
# retrieve data from config file
def load(self, name):
name = name + ".json"
file = self.dir + "/" + name
try:
# .gz or normal file
if os.path.exists(file + ".gz"):
f = gzip.open(file + ".gz", "r")
elif os.path.exists(file):
f = open(file, "r")
else:
return # file not found
# decode
r = pson.load(f)
f.close()
return r
except Exception as e:
print("PSON parsing error (in "+name+")", e)
# recursive dict update
|
|
|
|
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
if gz:
f = gzip.open(file+".gz", "w")
if os.path.exists(file):
os.unlink(file)
else:
f = open(file, "w")
# encode
json.dump(data, f, indent=(4 if nice else None))
f.close()
# retrieve data from config file
def load(self, name):
name = name + ".json"
file = self.dir + "/" + name
try:
# .gz or normal file
if os.path.exists(file + ".gz"):
f = gzip.open(file + ".gz", "r")
elif os.path.exists(file):
f = open(file, "r")
else:
return # file not found
# decode
r = json.load(f)
f.close()
return r
except Exception as e:
print("PSON parsing error (in "+name+")", e)
# recursive dict update
|