Development
This commit is contained in:
parent
60df03e85c
commit
22c18d9edd
4 changed files with 72 additions and 39 deletions
|
|
@ -67,9 +67,9 @@ def _read_pending(done_set):
|
|||
return pending
|
||||
for line in lines:
|
||||
try:
|
||||
parts = line.split(None, 3)
|
||||
if len(parts) == 4:
|
||||
entry_uuid, entry_ts, _dt, rest = parts
|
||||
parts = line.split(None, 2)
|
||||
if len(parts) == 3:
|
||||
entry_uuid, entry_ts, rest = parts
|
||||
cmd_user = rest.rsplit(' (', 1)
|
||||
entry_cmd = cmd_user[0].strip('[]')
|
||||
entry_user = cmd_user[1].rstrip(')') if len(cmd_user) == 2 else ''
|
||||
|
|
@ -128,9 +128,9 @@ def _read_dashboard_pending():
|
|||
continue
|
||||
try:
|
||||
main, _, desc = line.partition(' :: ')
|
||||
parts = main.split(None, 3)
|
||||
if len(parts) == 4:
|
||||
entry_uuid, entry_ts, _dt, rest = parts
|
||||
parts = main.split(None, 2)
|
||||
if len(parts) == 3:
|
||||
entry_uuid, entry_ts, rest = parts
|
||||
cmd_user = rest.rsplit(' (', 1)
|
||||
entry_cmd = cmd_user[0].strip('[]')
|
||||
entry_user = cmd_user[1].rstrip(')') if len(cmd_user) == 2 else ''
|
||||
|
|
@ -154,12 +154,42 @@ def flush_pending_to_queue():
|
|||
with open(DASHBOARD_QUEUE, 'a') as f:
|
||||
for entry_uuid, entry_ts, entry_cmd, entry_user, _desc in items:
|
||||
if entry_uuid not in existing_ids:
|
||||
dt_str = datetime.fromtimestamp(entry_ts).strftime('%Y-%m-%dT%H:%M:%S')
|
||||
f.write(f'{entry_uuid} {entry_ts} {dt_str} [{entry_cmd}] ({entry_user})\n')
|
||||
f.write(f'{entry_uuid} {entry_ts} [{entry_cmd}] ({entry_user})\n')
|
||||
open(DASHBOARD_PENDING, 'w').close()
|
||||
_trim_if_needed()
|
||||
|
||||
|
||||
def _remove_pending_by_uuids(uuid_set):
|
||||
try:
|
||||
lines = open(DASHBOARD_PENDING).read().splitlines()
|
||||
except Exception:
|
||||
return
|
||||
kept = [l for l in lines if l.strip() and l.split(None, 1)[0] not in uuid_set]
|
||||
with open(DASHBOARD_PENDING, 'w') as f:
|
||||
f.write('\n'.join(kept) + ('\n' if kept else ''))
|
||||
|
||||
|
||||
def flush_selected_to_queue(selected_uuids):
|
||||
if not selected_uuids:
|
||||
return
|
||||
selected_set = set(selected_uuids)
|
||||
items = _read_dashboard_pending()
|
||||
done_set = _load_done_set()
|
||||
existing_ids = {uu for uu, *_ in _read_pending(done_set)}
|
||||
with open(DASHBOARD_QUEUE, 'a') as f:
|
||||
for entry_uuid, entry_ts, entry_cmd, entry_user, _desc in items:
|
||||
if entry_uuid in selected_set and entry_uuid not in existing_ids:
|
||||
f.write(f'{entry_uuid} {entry_ts} [{entry_cmd}] ({entry_user})\n')
|
||||
_remove_pending_by_uuids(selected_set)
|
||||
_trim_if_needed()
|
||||
|
||||
|
||||
def delete_pending_by_uuids(selected_uuids):
|
||||
if not selected_uuids:
|
||||
return
|
||||
_remove_pending_by_uuids(set(selected_uuids))
|
||||
|
||||
|
||||
def _queue_pending_command(cmd, description=''):
|
||||
"""Append cmd to .dashboard-pending if not already present for this cmd+user."""
|
||||
existing = _read_dashboard_pending()
|
||||
|
|
@ -170,10 +200,9 @@ def _queue_pending_command(cmd, description=''):
|
|||
entry_uuid = str(uuid.uuid4())
|
||||
now = datetime.now()
|
||||
entry_ts = int(now.timestamp())
|
||||
dt_str = now.strftime('%Y-%m-%dT%H:%M:%S')
|
||||
desc_suffix = f' :: {description}' if description else ''
|
||||
with open(DASHBOARD_PENDING, 'a') as f:
|
||||
f.write(f'{entry_uuid} {entry_ts} {dt_str} [{cmd}] ({current_user}){desc_suffix}\n')
|
||||
f.write(f'{entry_uuid} {entry_ts} [{cmd}] ({current_user}){desc_suffix}\n')
|
||||
return entry_uuid, entry_ts
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue