Skip to content

Commit

Permalink
Add load_req_file util function
Browse files Browse the repository at this point in the history
  • Loading branch information
jsouter committed Jul 4, 2024
1 parent 8c9c5af commit 9ee7549
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions softioc/autosave.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from datetime import datetime
from pathlib import Path

from softioc.device_core import LookupRecordList
from softioc.device_core import LookupRecord, LookupRecordList

SAV_SUFFIX = "softsav"
SAVB_SUFFIX = "softsavB"
Expand Down Expand Up @@ -34,6 +34,17 @@ def set_autosave(pv, value=True):
else:
Autosave.remove_pv(pv)

def load_req_file(file, override=False):
with open(file, "r") as f:
pv_names = [name.strip() for name in f.readlines()]
if not override:
for pv_name in pv_names:
pv = LookupRecord(pv_name)
set_autosave(pv, True)
else: # explicitly set autosave for False if pv not in file
for pv_name, pv in LookupRecordList():
set_autosave(pv, pv_name in pv_names)


class Autosave:
_instance = None
Expand Down Expand Up @@ -88,12 +99,12 @@ def backup_sav_file(self):
@classmethod
def add_pv(cls, pv):
pv.set_autosave(True)
cls._pvs[pv.name] = pv
cls._pvs[pv._name] = pv

@classmethod
def remove_pv(cls, pv):
pv.set_autosave(False)
cls._pvs.pop(pv.name, None)
cls._pvs.pop(pv._name, None)

def _get_timestamped_backup_sav_path(self):
sav_path = self._get_current_sav_path()
Expand Down

0 comments on commit 9ee7549

Please sign in to comment.