Development
This commit is contained in:
parent
d0cfffac52
commit
adcfe55c7c
24 changed files with 405 additions and 359 deletions
|
|
@ -5,7 +5,7 @@ from flask import session
|
|||
CONFIGS_DIR = '/routlin_location'
|
||||
DATA_DIR = '/data'
|
||||
ACCOUNTS_FILE = f'{DATA_DIR}/authorized_accounts.json'
|
||||
CORE_FILE = f'{CONFIGS_DIR}/core.json'
|
||||
CONFIG_FILE = f'{CONFIGS_DIR}/config.json'
|
||||
DASHBOARD_QUEUE = f'{CONFIGS_DIR}/.dashboard-queue'
|
||||
DASHBOARD_DONE = f'{CONFIGS_DIR}/.dashboard-done'
|
||||
DASHBOARD_LAST_RUN = f'{CONFIGS_DIR}/.dashboard-last-run'
|
||||
|
|
@ -21,31 +21,31 @@ DASHB_INTERVAL_SECS = 60
|
|||
QUEUE_MAX_LINES = 50
|
||||
|
||||
|
||||
def load_core():
|
||||
def load_config():
|
||||
try:
|
||||
with open(CORE_FILE) as f:
|
||||
with open(CONFIG_FILE) as f:
|
||||
return json.load(f)
|
||||
except Exception:
|
||||
return {}
|
||||
|
||||
|
||||
def save_core(data):
|
||||
with open(CORE_FILE, 'w') as f:
|
||||
def save_config(data):
|
||||
with open(CONFIG_FILE, 'w') as f:
|
||||
json.dump(data, f, indent=2)
|
||||
|
||||
|
||||
def core_hash():
|
||||
def config_hash():
|
||||
try:
|
||||
with open(CORE_FILE, 'rb') as f:
|
||||
with open(CONFIG_FILE, 'rb') as f:
|
||||
return hashlib.md5(f.read()).hexdigest()
|
||||
except Exception:
|
||||
return ''
|
||||
|
||||
|
||||
def verify_core_hash(submitted):
|
||||
def verify_config_hash(submitted):
|
||||
if not submitted:
|
||||
return True
|
||||
return submitted == core_hash()
|
||||
return submitted == config_hash()
|
||||
|
||||
|
||||
def _load_done_set():
|
||||
|
|
@ -358,7 +358,7 @@ def _items_match(item, ref):
|
|||
|
||||
|
||||
def revert_snapshot_to_core(entry_uuid):
|
||||
"""Apply the inverse of a snapshot to core.json and queue a new pending change.
|
||||
"""Apply the inverse of a snapshot to config.json and queue a new pending change.
|
||||
|
||||
Returns (flash_message, success_bool).
|
||||
"""
|
||||
|
|
@ -375,7 +375,7 @@ def revert_snapshot_to_core(entry_uuid):
|
|||
if operation == 'revert':
|
||||
return 'This change is already a revert; cannot revert again.', False
|
||||
|
||||
core = load_core()
|
||||
core = load_config()
|
||||
|
||||
if key == 'global':
|
||||
if before is None:
|
||||
|
|
@ -396,7 +396,7 @@ def revert_snapshot_to_core(entry_uuid):
|
|||
items[i] = before
|
||||
break
|
||||
|
||||
msg = save_core_with_snapshot(
|
||||
msg = save_config_with_snapshot(
|
||||
core, path=path, key=key, operation='revert',
|
||||
before=after, after=before,
|
||||
description=f"Reverted: {snap.get('description', '')}",
|
||||
|
|
@ -417,7 +417,7 @@ def load_snapshot_for_uuid(entry_uuid):
|
|||
return None
|
||||
|
||||
|
||||
def save_core_with_snapshot(new_core, path, key, operation, before, after,
|
||||
def save_config_with_snapshot(new_core, path, key, operation, before, after,
|
||||
description='', cmd='core apply', queue=True):
|
||||
"""
|
||||
Write a .snapshots/{ts}-{uuid}.json file, save new_core to disk, and
|
||||
|
|
@ -447,7 +447,7 @@ def save_core_with_snapshot(new_core, path, key, operation, before, after,
|
|||
with open(os.path.join(SNAPSHOTS_DIR, f'{entry_ts}-{entry_uuid}.json'), 'w') as f:
|
||||
json.dump(snapshot, f, indent=2)
|
||||
|
||||
save_core(new_core)
|
||||
save_config(new_core)
|
||||
|
||||
if not queue:
|
||||
return None
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue