mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-06-24 07:22:04 +08:00
加入 dragonconf 讀取 /data/dragonpilot.json 設定
This commit is contained in:
@@ -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()
|
||||
Reference in New Issue
Block a user