dragonconf 改至 apk

This commit is contained in:
Rick Lan
2019-07-02 16:19:22 +10:00
parent a2b00731cb
commit c345bb1d8f
+33 -33
View File
@@ -1,8 +1,8 @@
#!/usr/bin/env python2.7
import os
import json
# import os
# import json
file = '/data/dragonpilot.json'
# file = '/data/dragonpilot.json'
default_conf = {
@@ -12,39 +12,39 @@ default_conf = {
'DragonTempDisableSteerOnSignal': '0',
}
def write_json_config(config):
with open(file, 'w') as f:
json.dump(config, f, indent=2, sort_keys=True)
os.chmod(file, 0644)
# def write_json_config(config):
# with open(file, 'w') as f:
# json.dump(config, f, indent=2, sort_keys=True)
# os.chmod(file, 0644)
def dragonpilot_set_params(params):
# create new json file
if not os.path.isfile(file):
write_json_config(default_conf)
config = default_conf
else:
# load from json
with open(file, 'r') as f:
config = json.load(f)
json_update_needed = False
# add new keys
for key, val in default_conf.items():
if key not in config:
json_update_needed = True
config[key] = val
# remove invalid keys
for key, val in config.items():
if key not in default_conf:
json_update_needed = True
config.pop(key, None)
# write to json if update needed
if json_update_needed:
write_json_config(config)
# # create new json file
# if not os.path.isfile(file):
# write_json_config(default_conf)
# config = default_conf
# else:
# # load from json
# with open(file, 'r') as f:
# config = json.load(f)
#
# json_update_needed = False
# # add new keys
# for key, val in default_conf.items():
# if key not in config:
# json_update_needed = True
# config[key] = val
#
# # remove invalid keys
# for key, val in config.items():
# if key not in default_conf:
# json_update_needed = True
# config.pop(key, None)
#
# # write to json if update needed
# if json_update_needed:
# write_json_config(config)
# set params
for key, val in config.items():
for key, val in default_conf.items():
if params.get(key) is None:
params.put(key, str(val))