加入 dragonconf 讀取 /data/dragonpilot.json 設定

This commit is contained in:
Rick Lan
2019-06-27 13:22:38 +10:00
parent 42effa5f4e
commit 65f19b01fa
3 changed files with 34 additions and 0 deletions
View File
@@ -0,0 +1,34 @@
#!/usr/bin/env python2.7
import os
import json
file = '/data/dragonpilot.json'
class dragonconf():
def __init__(self):
self.conf = self.read()
def read(self):
has_new_def = False
config = {}
if not os.path.isfile(file):
self.write(config)
with open(file, 'r') as f:
config = json.load(f)
# add config here
if has_new_def:
self.write(config)
return config
def write(self, config):
with open(file, 'w') as f:
json.dump(config, f, indent=2, sort_keys=True)
os.chmod(file, 0644)
if __name__ == "__main__":
dragonconf = dragonconf()