diff --git a/concore.py b/concore.py index 6d71f0f..e9fa88a 100644 --- a/concore.py +++ b/concore.py @@ -125,13 +125,15 @@ def safe_literal_eval(filename, defaultValue): inpath = "./in" #must be rel path for local outpath = "./out" simtime = 0 +concore_params_file = os.path.join(inpath, "1", "concore.params") +concore_maxtime_file = os.path.join(inpath, "1", "concore.maxtime") #9/21/22 # =================================================================== # Parameter Parsing # =================================================================== try: - sparams_path = os.path.join(inpath + "1", "concore.params") + sparams_path = concore_params_file if os.path.exists(sparams_path): with open(sparams_path, "r") as f: sparams = f.read() @@ -171,8 +173,7 @@ def tryparam(n, i): def default_maxtime(default): """Read maximum simulation time from file or use default.""" global maxtime - maxtime_path = os.path.join(inpath + "1", "concore.maxtime") - maxtime = safe_literal_eval(maxtime_path, default) + maxtime = safe_literal_eval(concore_maxtime_file, default) default_maxtime(100) @@ -220,7 +221,7 @@ def read(port_identifier, name, initstr_val): return default_return_val time.sleep(delay) - file_path = os.path.join(inpath+str(file_port_num), name) + file_path = os.path.join(inpath, str(file_port_num), name) ins = "" try: @@ -283,14 +284,12 @@ def write(port_identifier, name, val, delta=0): print(f"ZMQ write error on port {port_identifier} (name: {name}): {e}") except Exception as e: print(f"Unexpected error during ZMQ write on port {port_identifier} (name: {name}): {e}") + return # Case 2: File-based port try: - if isinstance(port_identifier, str) and port_identifier in zmq_ports: - file_path = os.path.join("../"+port_identifier, name) - else: - file_port_num = int(port_identifier) - file_path = os.path.join(outpath+str(file_port_num), name) + file_port_num = int(port_identifier) + file_path = os.path.join(outpath, str(file_port_num), name) except ValueError: print(f"Error: Invalid port identifier '{port_identifier}' for file operation. Must be integer or ZMQ name.") return diff --git a/concoredocker.py b/concoredocker.py index 5c5689d..161ad1b 100644 --- a/concoredocker.py +++ b/concoredocker.py @@ -21,10 +21,12 @@ def safe_literal_eval(filename, defaultValue): inpath = os.path.abspath("/in") outpath = os.path.abspath("/out") simtime = 0 +concore_params_file = os.path.join(inpath, "1", "concore.params") +concore_maxtime_file = os.path.join(inpath, "1", "concore.maxtime") #9/21/22 try: - sparams = open(inpath+"1/concore.params").read() + sparams = open(concore_params_file).read() if sparams[0] == '"': #windows keeps "" need to remove sparams = sparams[1:] sparams = sparams[0:sparams.find('"')] @@ -46,7 +48,7 @@ def tryparam(n, i): #9/12/21 def default_maxtime(default): global maxtime - maxtime = safe_literal_eval(os.path.join(inpath, "1", "concore.maxtime"), default) + maxtime = safe_literal_eval(concore_maxtime_file, default) default_maxtime(100) @@ -62,7 +64,7 @@ def read(port, name, initstr): global s, simtime, retrycount max_retries=5 time.sleep(delay) - file_path = os.path.join(inpath+str(port), name) + file_path = os.path.join(inpath, str(port), name) try: with open(file_path, "r") as infile: @@ -101,7 +103,7 @@ def read(port, name, initstr): def write(port, name, val, delta=0): global simtime - file_path = os.path.join(outpath+str(port), name) + file_path = os.path.join(outpath, str(port), name) if isinstance(val, str): time.sleep(2 * delay)