From 6f208d6c649733a360b055bb86b1760b2f3bf8df Mon Sep 17 00:00:00 2001
From: Karim Ahmed <karim.ahmed@xfel.eu>
Date: Mon, 14 Oct 2019 17:40:30 +0200
Subject: [PATCH] enable turning a true bool to false

---
 webservice/update_config.py | 16 +++++++++++++---
 webservice/webservice.py    | 15 ++++++++++++---
 2 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/webservice/update_config.py b/webservice/update_config.py
index 77f6ffe25..33fdc1347 100644
--- a/webservice/update_config.py
+++ b/webservice/update_config.py
@@ -10,7 +10,8 @@ available_options = {
               "blc-noise": bool,
               "dont-zero-nans": bool,
               "dont-zero-orange": bool,
-              "max-pulses": int},
+              "max-pulses": str,
+              "calfile": str},
 }
 
 parser = argparse.ArgumentParser(
@@ -25,7 +26,6 @@ required_args.add_argument('--instrument', type=str,
                              "DETLAB"], help='The instrument')  # noqa
 required_args.add_argument('--cycle', type=str, help='The facility cycle')
 parser.add_argument('--apply', action='store_true')
-
 # remove help calls as they will cause the argument parser to exit
 add_help = False
 if "-h" in sys.argv:
@@ -35,6 +35,14 @@ if "--help" in sys.argv:
     sys.argv.remove("--help")
     add_help = True
 
+for det, val in available_options.items():
+    bool_keys = []
+    for k, v in val.items():
+        if v == bool:
+            bool_keys.append(k)
+    for b in bool_keys:
+        available_options[det]['no-{}'.format(b)] = bool
+
 known, remaining = parser.parse_known_args()
 args = vars(known)
 detector = args["detector"]
@@ -61,6 +69,8 @@ new_conf = {task: {instrument: {detector: {}}}}
 for key, value in args.items():
     key = key.replace("_", "-")
     if key in available_options[detector] and value is not None:
+        if 'no-' in  key and isinstance(value, bool):
+            new_conf[task][instrument][detector][key.replace('no-','')] = False
         new_conf[task][instrument][detector][key] = value
 
 pyaml = yaml.dump(new_conf, default_flow_style=False)
@@ -76,7 +86,7 @@ print(f"Sending the following update: \n {pyaml}")
 print("-" * 80)
 con = zmq.Context()
 socket = con.socket(zmq.REQ)
-con = socket.connect("tcp://max-exfl016:5555")
+con = socket.connect("tcp://max-exfl001:5555")
 msg = "','".join(["update_conf", "SASEX", args["instrument"], args["cycle"],
                   args["proposal"], json.dumps(new_conf), str(args["apply"])])
 socket.send("['{}']".format(msg).encode())
diff --git a/webservice/webservice.py b/webservice/webservice.py
index 51e60a32a..76597931f 100644
--- a/webservice/webservice.py
+++ b/webservice/webservice.py
@@ -633,7 +633,11 @@ async def server_runner(config, mode):
 
                     for key, value in dconfig.items():
                         if not isinstance(value, bool):
-                            cmd += ["--{}".format(key), str(value)]
+                            if " " in str(value):
+                                cmd += ["--{}".format(key)]
+                                cmd += [str(v) for v in value.split(" ")]
+                            else:
+                                cmd += ["--{}".format(key), str(value)]
                         else:
                             cmd += ["--{}".format(key)]
                     ret = await run_correction(job_db, cmd, mode, proposal,
@@ -683,9 +687,14 @@ async def server_runner(config, mode):
                            detector, "CORRECT"]
                     for key, value in dconfig.items():
                         if not isinstance(value, bool):
-                            cmd += ["--{}".format(key), str(value)]
+                            if " " in str(value):
+                                cmd += ["--{}".format(key)]
+                                cmd += [str(v) for v in value.split(" ")]
+                            else:
+                                cmd += ["--{}".format(key), str(value)]
                         else:
-                            cmd += ["--{}".format(key)]
+                            if value:
+                                cmd += ["--{}".format(key)]
                     if priority:
                         cmd += ["--priority", str(priority)]
                     ret = await run_correction(job_db, cmd, mode, proposal,
-- 
GitLab