blob: 156fbaf53f84adc61fa8c8910f26566b97206cde (
plain)
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
|
import os
import json
#Utils
#File Load/Store
def read_file(infile):
with open(infile, 'r') as f:
data = ''.join(f.readlines())
f.close()
return data
def write_file(outfile, data):
with open(outfile, 'w') as f:
f.writelines([data])
f.close()
return
#JSON Load/Store
def load_status(infile):
data = '{}'
if os.access(infile, os.R_OK):
data = read_file(infile)
return json.loads(data)
def store_status(outfile, obj):
write_file(outfile, json.dumps(obj))
return
#test case
if __name__ == '__main__':
obj = load_status('/tmp/test.status')
print(obj)
store_status('/tmp/test.status', obj)
|