added a clean up for filename / output directory
This commit is contained in:
@@ -12,7 +12,7 @@ from slic.utils import xrange, tqdm_mod, tqdm_sleep
|
||||
from slic.utils import json_validate
|
||||
from slic.utils.printing import printable_dict
|
||||
|
||||
from .broker_tools import get_current_pulseid, get_endstation
|
||||
from .broker_tools import get_current_pulseid, get_endstation, clean_output_dir
|
||||
|
||||
|
||||
class BrokerClient:
|
||||
@@ -306,7 +306,12 @@ class BrokerConfig:
|
||||
self.kwargs_init = kwargs # unknown arguments will be forwarded verbatim to the broker
|
||||
self.set(None) #TODO: sensible defaults?
|
||||
|
||||
|
||||
def set(self, output_dir, detectors=None, channels=None, pvs=None, scan_info=None, **kwargs):
|
||||
# output dir needs to be cleaned if used as part of the folder name
|
||||
if self.append_user_tag_to_data_dir:
|
||||
output_dir = clean_output_dir(output_dir)
|
||||
|
||||
self.output_dir = output_dir
|
||||
self.detectors = detectors
|
||||
self.channels = channels
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
from datetime import datetime
|
||||
import socket
|
||||
import string
|
||||
import epics
|
||||
from logzero import logger as log
|
||||
|
||||
from slic.utils import singleton
|
||||
from slic.utils import cprint
|
||||
|
||||
|
||||
#TODO: these should probably move to different IOCs
|
||||
@@ -29,6 +31,10 @@ IP_TO_ENDSTATION = {
|
||||
REFERENCE_DATETIME = datetime(2020, 5, 8, 8, 29, 52)
|
||||
REFERENCE_PID = 11718051371
|
||||
|
||||
#TODO: remove the same from gui code
|
||||
ALLOWED_CHARS = set(
|
||||
string.ascii_letters + string.digits + "_-"
|
||||
)
|
||||
|
||||
|
||||
def decide_get_current_pulseid():
|
||||
@@ -100,3 +106,17 @@ class get_current_pulseid():
|
||||
|
||||
|
||||
|
||||
def clean_output_dir(s, default="_", allowed=ALLOWED_CHARS):
|
||||
if s is None:
|
||||
return None
|
||||
res = "".join(i if i in allowed else default for i in s)
|
||||
if res != s:
|
||||
warn_output_dir(s, res)
|
||||
return res
|
||||
|
||||
def warn_output_dir(old, new):
|
||||
msg = f'output dir contains forbidden characters. will adjust:\n"{old}"\n==>\n"{new}"'
|
||||
cprint(msg, color="cyan")
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user