allow loading files from json references, handle boolean flags in the configuration files
Hi Enrico,
below are two patches I needed to apply get FASER running with the new daqling version. The first is to allow loading files from json references while the second was needed to handle boolean flags in the configuration files. A more robust implementation of that might be needed.
Cheers, Brian
diff --git a/scripts/Control/daq.py b/scripts/Control/daq.py
index 58b1c1e..9d0a2f1 100644
--- a/scripts/Control/daq.py
+++ b/scripts/Control/daq.py
@@ -17,6 +17,7 @@
import sys
import signal
+import os
from os import environ as env
import json
import jsonref
@@ -27,6 +28,7 @@ import concurrent.futures
import threading
import zmq
from time import sleep
+from pathlib import Path
def spawnJoin(list, func):
futures = []
@@ -109,7 +111,8 @@ for o in sys.argv:
quit()
with open(sys.argv[1]) as f:
- jsonref_obj = jsonref.load(f)
+ base_dir_uri = Path(os.path.realpath(os.getcwd())).as_uri() + '/'+sys.argv[1]
+ jsonref_obj = jsonref.load(f,base_uri=base_dir_uri,loader=jsonref.JsonLoader())
f.close()
if "configuration" in jsonref_obj:
diff --git a/scripts/Control/daqcontrol.py b/scripts/Control/daqcontrol.py
index 87b6f2a..64c333e 100644
--- a/scripts/Control/daqcontrol.py
+++ b/scripts/Control/daqcontrol.py
@@ -164,6 +164,6 @@ class daqcontrol:
def jsonref_to_json(jsonref_obj):
# cast jsonref to str
jsonref_str = str(jsonref_obj)
- # substitute single quote to double quote
- json_str = jsonref_str.replace("\'", "\"")
+ # substitute single quote to double quote and booleans
+ json_str = jsonref_str.replace("\'", "\"").replace("True","true").replace("False","false")
return json.loads(json_str)