mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-06-23 06:52:07 +08:00
dragonconf 改至 apk
This commit is contained in:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user