improved startup a lot
This commit is contained in:
1 parent
9397fcd8b8
commit
e138ec8c2e
12 files changed
+221
-107
No files matched your search
@@ -0,0 +1,36 @@
|
||||
config_path = '/gs/config/'
|
||||
|
||||
def is_config_existing():
|
||||
return is_file_existing(config_path + 'device_config.json')
|
||||
|
||||
def is_initial_config_existing():
|
||||
return is_file_existing(config_path + 'initial_config.py')
|
||||
|
||||
def is_file_existing(filepath):
|
||||
try:
|
||||
f = open(filepath, "r")
|
||||
f.close()
|
||||
# continue with the file.
|
||||
return True
|
||||
except OSError: # open failed
|
||||
# handle the file open cas
|
||||
return False
|
||||
|
||||
def replace_value(filepath, prop, newvalue):
|
||||
with open(filepath, 'r') as file:
|
||||
config_lines = file.readlines()
|
||||
file.close()
|
||||
|
||||
# Parse the config data into a dictionary
|
||||
config_dict = {}
|
||||
for line in config_lines:
|
||||
if '=' in line:
|
||||
key, value = line.strip().split('=')
|
||||
config_dict[key.strip()] = value.strip()
|
||||
# Add or Update the value of the property
|
||||
config_dict[prop] = newvalue
|
||||
|
||||
# Write the modified data back to the file
|
||||
with open(filepath, 'w') as file:
|
||||
for key, value in config_dict.items():
|
||||
file.write(f"{key} = {value}\n")
|
||||
@@ -0,0 +1,9 @@
|
||||
import helper.file_helper as fh
|
||||
|
||||
app_config_path = '/gs/config/app.py'
|
||||
|
||||
def write_token(token):
|
||||
print("Write new token: " + token)
|
||||
fh.replace_value(app_config_path, 'token', '"' + token + '"')
|
||||
#with open(app_config_path, "a") as app_config:
|
||||
# app_config.write(token)
|
||||
Reference in new issue
Block a user