From 4fb00b110ca79826f69c07856b152fce36682f85 Mon Sep 17 00:00:00 2001 From: GREENRAT-K405 Date: Fri, 20 Feb 2026 03:18:15 +0530 Subject: [PATCH] fix script copying logic in mkconcore.py --- mkconcore.py | 612 ++++++++++++++++++++++++--------------------------- 1 file changed, 291 insertions(+), 321 deletions(-) diff --git a/mkconcore.py b/mkconcore.py index 974c9bb..81e08b9 100644 --- a/mkconcore.py +++ b/mkconcore.py @@ -75,46 +75,46 @@ import shlex # Added for POSIX shell escaping # input validation helper -def safe_name(value, context, allow_path=False): - """ - Validates that the input string does not contain characters dangerous - for filesystem paths or shell command injection. - """ - if not value: - raise ValueError(f"{context} cannot be empty") - # blocks control characters and shell metacharacters - # allow path separators and drive colons for full paths when needed - if allow_path: - pattern = r'[\x00-\x1F\x7F*?"<>|;&`$\'()]' - else: - # blocks path traversal (/, \, :) in addition to shell metacharacters - pattern = r'[\x00-\x1F\x7F\\/:*?"<>|;&`$\'()]' - if re.search(pattern, value): - raise ValueError(f"Unsafe {context}: '{value}' contains illegal characters.") - return value - -def safe_relpath(value, context): - """ - Allow relative subpaths while blocking traversal and absolute/drive paths. - """ - if not value: - raise ValueError(f"{context} cannot be empty") - normalized = value.replace("\\", "/") - safe_name(normalized, context, allow_path=True) - if normalized.startswith("/") or normalized.startswith("~"): - raise ValueError(f"Unsafe {context}: absolute paths are not allowed.") - if re.match(r"^[A-Za-z]:", normalized): - raise ValueError(f"Unsafe {context}: drive paths are not allowed.") - if ":" in normalized: - raise ValueError(f"Unsafe {context}: ':' is not allowed in relative paths.") - if any(part in ("", "..") for part in normalized.split("/")): - raise ValueError(f"Unsafe {context}: invalid path segment.") - return normalized - -MKCONCORE_VER = "22-09-18" - -SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) - +def safe_name(value, context, allow_path=False): + """ + Validates that the input string does not contain characters dangerous + for filesystem paths or shell command injection. + """ + if not value: + raise ValueError(f"{context} cannot be empty") + # blocks control characters and shell metacharacters + # allow path separators and drive colons for full paths when needed + if allow_path: + pattern = r'[\x00-\x1F\x7F*?"<>|;&`$\'()]' + else: + # blocks path traversal (/, \, :) in addition to shell metacharacters + pattern = r'[\x00-\x1F\x7F\\/:*?"<>|;&`$\'()]' + if re.search(pattern, value): + raise ValueError(f"Unsafe {context}: '{value}' contains illegal characters.") + return value + +def safe_relpath(value, context): + """ + Allow relative subpaths while blocking traversal and absolute/drive paths. + """ + if not value: + raise ValueError(f"{context} cannot be empty") + normalized = value.replace("\\", "/") + safe_name(normalized, context, allow_path=True) + if normalized.startswith("/") or normalized.startswith("~"): + raise ValueError(f"Unsafe {context}: absolute paths are not allowed.") + if re.match(r"^[A-Za-z]:", normalized): + raise ValueError(f"Unsafe {context}: drive paths are not allowed.") + if ":" in normalized: + raise ValueError(f"Unsafe {context}: ':' is not allowed in relative paths.") + if any(part in ("", "..") for part in normalized.split("/")): + raise ValueError(f"Unsafe {context}: invalid path segment.") + return normalized + +MKCONCORE_VER = "22-09-18" + +SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) + def _load_tool_config(filepath): tools = {} with open(filepath, "r") as f: @@ -128,24 +128,24 @@ def _load_tool_config(filepath): tools[k] = v return tools -def _resolve_concore_path(): - script_concore = os.path.join(SCRIPT_DIR, "concore.py") - if os.path.exists(script_concore): - return SCRIPT_DIR - cwd_concore = os.path.join(os.getcwd(), "concore.py") - if os.path.exists(cwd_concore): - return os.getcwd() - return SCRIPT_DIR - -if len(sys.argv) < 4: - print("usage: py mkconcore.py file.graphml sourcedir outdir [type]") - print(" type must be posix (macos or ubuntu), windows, or docker") - sys.exit(1) - -ORIGINAL_CWD = os.getcwd() -GRAPHML_FILE = os.path.abspath(sys.argv[1]) -TRIMMED_LOGS = True -CONCOREPATH = _resolve_concore_path() +def _resolve_concore_path(): + script_concore = os.path.join(SCRIPT_DIR, "concore.py") + if os.path.exists(script_concore): + return SCRIPT_DIR + cwd_concore = os.path.join(os.getcwd(), "concore.py") + if os.path.exists(cwd_concore): + return os.getcwd() + return SCRIPT_DIR + +if len(sys.argv) < 4: + print("usage: py mkconcore.py file.graphml sourcedir outdir [type]") + print(" type must be posix (macos or ubuntu), windows, or docker") + sys.exit(1) + +ORIGINAL_CWD = os.getcwd() +GRAPHML_FILE = os.path.abspath(sys.argv[1]) +TRIMMED_LOGS = True +CONCOREPATH = _resolve_concore_path() CPPWIN = os.environ.get("CONCORE_CPPWIN", "g++") #Windows C++ 6/22/21 CPPEXE = os.environ.get("CONCORE_CPPEXE", "g++") #Ubuntu/macOS C++ 6/22/21 VWIN = os.environ.get("CONCORE_VWIN", "iverilog") #Windows verilog 6/25/21 @@ -197,22 +197,22 @@ def _resolve_concore_path(): OCTAVEEXE = _tools.get("OCTAVEEXE", OCTAVEEXE) OCTAVEWIN = _tools.get("OCTAVEWIN", OCTAVEWIN) -prefixedgenode = "" -sourcedir = os.path.abspath(sys.argv[2]) -outdir = os.path.abspath(sys.argv[3]) - -# Validate outdir argument (allow full paths) -safe_name(outdir, "Output directory argument", allow_path=True) +prefixedgenode = "" +sourcedir = os.path.abspath(sys.argv[2]) +outdir = os.path.abspath(sys.argv[3]) + +# Validate outdir argument (allow full paths) +safe_name(outdir, "Output directory argument", allow_path=True) if not os.path.isdir(sourcedir): logging.error(f"{sourcedir} does not exist") quit() -if len(sys.argv) == 4: - # Use only the output directory name in generated prefixes. - prefixedgenode = os.path.basename(os.path.normpath(outdir)) + "_" - concoretype = "docker" -else: +if len(sys.argv) == 4: + # Use only the output directory name in generated prefixes. + prefixedgenode = os.path.basename(os.path.normpath(outdir)) + "_" + concoretype = "docker" +else: concoretype = sys.argv[4] if not (concoretype in ["posix","windows","docker","macos","ubuntu"]): logging.error(" type must be posix (macos or ubuntu), windows, or docker") @@ -229,8 +229,8 @@ def _resolve_concore_path(): logging.error(f"if intended, Remove/Rename {outdir} first") quit() -os.makedirs(outdir) -os.chdir(outdir) +os.makedirs(outdir) +os.chdir(outdir) if concoretype == "windows": fbuild = open("build.bat","w") frun = open("run.bat", "w") @@ -257,8 +257,8 @@ def cleanup_script_files(): fh.close() atexit.register(cleanup_script_files) -os.mkdir("src") -os.chdir(ORIGINAL_CWD) +os.mkdir("src") +os.chdir(ORIGINAL_CWD) logging.info(f"mkconcore {MKCONCORE_VER}") logging.info(f"Concore path: {CONCOREPATH}") @@ -294,15 +294,15 @@ def cleanup_script_files(): node_label = re.sub(r'(\s+|\n)', ' ', node_label) #Validate node labels - if ':' in node_label: - container_part, source_part = node_label.split(':', 1) - safe_name(container_part, f"Node container name '{container_part}'") - source_part = safe_relpath(source_part, f"Node source file '{source_part}'") - node_label = f"{container_part}:{source_part}" - else: - safe_name(node_label, f"Node label '{node_label}'") - # Explicitly reject incorrect format to prevent later crashes and ambiguity - raise ValueError(f"Invalid node label '{node_label}': expected format 'container:source' with a ':' separator.") + if ':' in node_label: + container_part, source_part = node_label.split(':', 1) + safe_name(container_part, f"Node container name '{container_part}'") + source_part = safe_relpath(source_part, f"Node source file '{source_part}'") + node_label = f"{container_part}:{source_part}" + else: + safe_name(node_label, f"Node label '{node_label}'") + # Explicitly reject incorrect format to prevent later crashes and ambiguity + raise ValueError(f"Invalid node label '{node_label}': expected format 'container:source' with a ':' separator.") nodes_dict[node['id']] = node_label node_id_to_label_map[node['id']] = node_label.split(':')[0] @@ -420,69 +420,69 @@ def cleanup_script_files(): logging.warning(f"Error processing edge for parameter aggregation: {e}") # --- Now, run the specialization for each node that has aggregated parameters --- -if node_edge_params: - logging.info("Running script specialization process...") - specialized_scripts_output_dir = os.path.abspath(os.path.join(outdir, "src")) - os.makedirs(specialized_scripts_output_dir, exist_ok=True) - - # Build one specialization plan per source script. This avoids collisions - # when multiple nodes reference the same script and need different ZMQ params. - script_edge_params = {} - script_nodes = {} - for node_id, params_list in node_edge_params.items(): - current_node_full_label = nodes_dict.get(node_id, "") - try: - container_name, original_script = current_node_full_label.split(':', 1) - except ValueError: - continue - - if not original_script or "." not in original_script: - continue - - script_nodes.setdefault(original_script, []).append((node_id, container_name)) - script_edge_params.setdefault(original_script, []) - seen_keys = { - ( - p.get("port"), - p.get("port_name"), - p.get("source_node_label"), - p.get("target_node_label") - ) - for p in script_edge_params[original_script] - } - for edge_param in params_list: - edge_key = ( - edge_param.get("port"), - edge_param.get("port_name"), - edge_param.get("source_node_label"), - edge_param.get("target_node_label") - ) - if edge_key not in seen_keys: - script_edge_params[original_script].append(edge_param) - seen_keys.add(edge_key) - - for original_script, merged_params in script_edge_params.items(): - template_script_full_path = os.path.join(sourcedir, original_script) - if not os.path.exists(template_script_full_path): - logging.error(f"Cannot specialize: Original script '{template_script_full_path}' not found in '{sourcedir}'.") - continue - - new_script_relpath = copy_with_port_portname.run_specialization_script( - template_script_full_path, - specialized_scripts_output_dir, - merged_params, - python_executable, - copy_script_py_path, - output_relpath=original_script - ) - - if not new_script_relpath: - logging.error(f"Failed to generate specialized script for source '{original_script}'.") - continue - - for node_id, container_name in script_nodes.get(original_script, []): - nodes_dict[node_id] = f"{container_name}:{new_script_relpath}" - logging.info(f"Node ID '{node_id}' ('{container_name}') updated to use specialized script '{new_script_relpath}'.") +if node_edge_params: + logging.info("Running script specialization process...") + specialized_scripts_output_dir = os.path.abspath(os.path.join(outdir, "src")) + os.makedirs(specialized_scripts_output_dir, exist_ok=True) + + # Build one specialization plan per source script. This avoids collisions + # when multiple nodes reference the same script and need different ZMQ params. + script_edge_params = {} + script_nodes = {} + for node_id, params_list in node_edge_params.items(): + current_node_full_label = nodes_dict.get(node_id, "") + try: + container_name, original_script = current_node_full_label.split(':', 1) + except ValueError: + continue + + if not original_script or "." not in original_script: + continue + + script_nodes.setdefault(original_script, []).append((node_id, container_name)) + script_edge_params.setdefault(original_script, []) + seen_keys = { + ( + p.get("port"), + p.get("port_name"), + p.get("source_node_label"), + p.get("target_node_label") + ) + for p in script_edge_params[original_script] + } + for edge_param in params_list: + edge_key = ( + edge_param.get("port"), + edge_param.get("port_name"), + edge_param.get("source_node_label"), + edge_param.get("target_node_label") + ) + if edge_key not in seen_keys: + script_edge_params[original_script].append(edge_param) + seen_keys.add(edge_key) + + for original_script, merged_params in script_edge_params.items(): + template_script_full_path = os.path.join(sourcedir, original_script) + if not os.path.exists(template_script_full_path): + logging.error(f"Cannot specialize: Original script '{template_script_full_path}' not found in '{sourcedir}'.") + continue + + new_script_relpath = copy_with_port_portname.run_specialization_script( + template_script_full_path, + specialized_scripts_output_dir, + merged_params, + python_executable, + copy_script_py_path, + output_relpath=original_script + ) + + if not new_script_relpath: + logging.error(f"Failed to generate specialized script for source '{original_script}'.") + continue + + for node_id, container_name in script_nodes.get(original_script, []): + nodes_dict[node_id] = f"{container_name}:{new_script_relpath}" + logging.info(f"Node ID '{node_id}' ('{container_name}') updated to use specialized script '{new_script_relpath}'.") #not right for PM2_1_1 and PM2_1_2 volswr = len(nodes_dict)*[''] @@ -517,15 +517,15 @@ def cleanup_script_files(): if not sourcecode: continue - if "." in sourcecode: - dockername, langext = os.path.splitext(sourcecode) - else: - dockername, langext = sourcecode, "" - - script_target_path = os.path.join(outdir, "src", sourcecode) - script_target_parent = os.path.dirname(script_target_path) - if script_target_parent: - os.makedirs(script_target_parent, exist_ok=True) + if "." in sourcecode: + dockername, langext = os.path.splitext(sourcecode) + else: + dockername, langext = sourcecode, "" + + script_target_path = os.path.join(outdir, "src", sourcecode) + script_target_parent = os.path.dirname(script_target_path) + if script_target_parent: + os.makedirs(script_target_parent, exist_ok=True) # If the script was specialized, it's already in outdir/src. If not, copy from sourcedir. if node_id_key not in node_edge_params: @@ -547,128 +547,98 @@ def cleanup_script_files(): shutil.copytree(os.path.join(sourcedir, dir_for_node), os.path.join(outdir, "src", dir_for_node), dirs_exist_ok=True) -#copy proper concore.py into /src -try: - if concoretype=="docker": - with open(CONCOREPATH+"/concoredocker.py") as fsource: - source_content = fsource.read() - else: - with open(CONCOREPATH+"/concore.py") as fsource: - source_content = fsource.read() -except (FileNotFoundError, IOError) as e: - logging.error(f"{CONCOREPATH} is not correct path to concore: {e}") - quit() -with open(outdir+"/src/concore.py","w") as fcopy: - fcopy.write(source_content) - -#copy proper concore.hpp into /src 6/22/21 -try: - if concoretype=="docker": - with open(CONCOREPATH+"/concoredocker.hpp") as fsource: - source_content = fsource.read() - else: - with open(CONCOREPATH+"/concore.hpp") as fsource: - source_content = fsource.read() -except (FileNotFoundError, IOError) as e: - logging.error(f"{CONCOREPATH} is not correct path to concore: {e}") - quit() -with open(outdir+"/src/concore.hpp","w") as fcopy: - fcopy.write(source_content) - -#copy proper concore.v into /src 6/25/21 -try: - if concoretype=="docker": - with open(CONCOREPATH+"/concoredocker.v") as fsource: - source_content = fsource.read() - else: - with open(CONCOREPATH+"/concore.v") as fsource: - source_content = fsource.read() -except (FileNotFoundError, IOError) as e: - logging.error(f"{CONCOREPATH} is not correct path to concore: {e}") - quit() -with open(outdir+"/src/concore.v","w") as fcopy: - fcopy.write(source_content) - -#copy mkcompile into /src 5/27/21 -try: - with open(CONCOREPATH+"/mkcompile") as fsource: - source_content = fsource.read() -except (FileNotFoundError, IOError) as e: - logging.error(f"{CONCOREPATH} is not correct path to concore: {e}") - quit() -with open(outdir+"/src/mkcompile","w") as fcopy: - fcopy.write(source_content) -os.chmod(outdir+"/src/mkcompile",stat.S_IRWXU) - -#copy concore*.m into /src 4/2/21 -try: #maxtime in matlab 11/22/21 - with open(CONCOREPATH+"/concore_default_maxtime.m") as fsource: - source_content = fsource.read() -except (FileNotFoundError, IOError) as e: - logging.error(f"{CONCOREPATH} is not correct path to concore: {e}") - quit() -with open(outdir+"/src/concore_default_maxtime.m","w") as fcopy: - fcopy.write(source_content) -try: - with open(CONCOREPATH+"/concore_unchanged.m") as fsource: - source_content = fsource.read() -except (FileNotFoundError, IOError) as e: - logging.error(f"{CONCOREPATH} is not correct path to concore: {e}") - quit() -with open(outdir+"/src/concore_unchanged.m","w") as fcopy: - fcopy.write(source_content) -try: - with open(CONCOREPATH+"/concore_read.m") as fsource: - source_content = fsource.read() -except (FileNotFoundError, IOError) as e: - logging.error(f"{CONCOREPATH} is not correct path to concore: {e}") - quit() -with open(outdir+"/src/concore_read.m","w") as fcopy: - fcopy.write(source_content) -try: - with open(CONCOREPATH+"/concore_write.m") as fsource: - source_content = fsource.read() -except (FileNotFoundError, IOError) as e: - logging.error(f"{CONCOREPATH} is not correct path to concore: {e}") - quit() -with open(outdir+"/src/concore_write.m","w") as fcopy: - fcopy.write(source_content) -try: #4/9/21 - with open(CONCOREPATH+"/concore_initval.m") as fsource: - source_content = fsource.read() -except (FileNotFoundError, IOError) as e: - logging.error(f"{CONCOREPATH} is not correct path to concore: {e}") - quit() -with open(outdir+"/src/concore_initval.m","w") as fcopy: - fcopy.write(source_content) -try: #11/19/21 - with open(CONCOREPATH+"/concore_iport.m") as fsource: - source_content = fsource.read() -except (FileNotFoundError, IOError) as e: - logging.error(f"{CONCOREPATH} is not correct path to concore: {e}") - quit() -with open(outdir+"/src/concore_iport.m","w") as fcopy: - fcopy.write(source_content) -try: #11/19/21 - with open(CONCOREPATH+"/concore_oport.m") as fsource: - source_content = fsource.read() -except (FileNotFoundError, IOError) as e: - logging.error(f"{CONCOREPATH} is not correct path to concore: {e}") - quit() -with open(outdir+"/src/concore_oport.m","w") as fcopy: - fcopy.write(source_content) -try: # 4/4/21 - if concoretype=="docker": - with open(CONCOREPATH+"/import_concoredocker.m") as fsource: - source_content = fsource.read() - else: - with open(CONCOREPATH+"/import_concore.m") as fsource: - source_content = fsource.read() -except (FileNotFoundError, IOError) as e: - logging.error(f"{CONCOREPATH} is not correct path to concore: {e}") - quit() -with open(outdir+"/src/import_concore.m","w") as fcopy: - fcopy.write(source_content) +#determine languages used in the graphml +required_langs = set() +for node in nodes_dict: + containername, sourcecode = nodes_dict[node].split(':') + if len(sourcecode) != 0 and "." in sourcecode: + langext = sourcecode.split(".")[-1] + required_langs.add(langext) +logging.info(f"Languages detected in graph: {required_langs}") + +if 'py' in required_langs: + try: + if concoretype=="docker": + fsource = open(CONCOREPATH+"/concoredocker.py") + else: + fsource = open(CONCOREPATH+"/concore.py") + except (FileNotFoundError, IOError): + print(CONCOREPATH+" is not correct path to concore (missing python files)") + quit() + with open(outdir+"/src/concore.py","w") as fcopy: + fcopy.write(fsource.read()) + fsource.close() + +if 'cpp' in required_langs: + try: + if concoretype=="docker": + fsource = open(CONCOREPATH+"/concoredocker.hpp") + else: + fsource = open(CONCOREPATH+"/concore.hpp") + except (FileNotFoundError, IOError): + print(CONCOREPATH+" is not correct path to concore (missing C++ files)") + quit() + with open(outdir+"/src/concore.hpp","w") as fcopy: + fcopy.write(fsource.read()) + fsource.close() + +if 'v' in required_langs: + try: + if concoretype=="docker": + fsource = open(CONCOREPATH+"/concoredocker.v") + else: + fsource = open(CONCOREPATH+"/concore.v") + except (FileNotFoundError, IOError): + print(CONCOREPATH+" is not correct path to concore (missing Verilog files)") + quit() + with open(outdir+"/src/concore.v","w") as fcopy: + fcopy.write(fsource.read()) + fsource.close() + +if 'm' in required_langs: + try: + fsource = open(CONCOREPATH+"/concore_default_maxtime.m") + with open(outdir+"/src/concore_default_maxtime.m","w") as fcopy: fcopy.write(fsource.read()) + fsource.close() + + fsource = open(CONCOREPATH+"/concore_unchanged.m") + with open(outdir+"/src/concore_unchanged.m","w") as fcopy: fcopy.write(fsource.read()) + fsource.close() + + fsource = open(CONCOREPATH+"/concore_read.m") + with open(outdir+"/src/concore_read.m","w") as fcopy: fcopy.write(fsource.read()) + fsource.close() + + fsource = open(CONCOREPATH+"/concore_write.m") + with open(outdir+"/src/concore_write.m","w") as fcopy: fcopy.write(fsource.read()) + fsource.close() + + fsource = open(CONCOREPATH+"/concore_initval.m") + with open(outdir+"/src/concore_initval.m","w") as fcopy: fcopy.write(fsource.read()) + fsource.close() + + fsource = open(CONCOREPATH+"/concore_iport.m") + with open(outdir+"/src/concore_iport.m","w") as fcopy: fcopy.write(fsource.read()) + fsource.close() + + fsource = open(CONCOREPATH+"/concore_oport.m") + with open(outdir+"/src/concore_oport.m","w") as fcopy: fcopy.write(fsource.read()) + fsource.close() + + if concoretype=="docker": + fsource = open(CONCOREPATH+"/import_concoredocker.m") + else: + fsource = open(CONCOREPATH+"/import_concore.m") + with open(outdir+"/src/import_concore.m","w") as fcopy: fcopy.write(fsource.read()) + fsource.close() + + fsource = open(CONCOREPATH+"/mkcompile") + with open(outdir+"/src/mkcompile","w") as fcopy: fcopy.write(fsource.read()) + fsource.close() + os.chmod(outdir+"/src/mkcompile",stat.S_IRWXU) + except Exception as e: + print(CONCOREPATH+" is not correct path to concore (missing MATLAB files):", e) + quit() # --- Generate iport and oport mappings --- logging.info("Generating iport/oport mappings...") @@ -715,33 +685,33 @@ def cleanup_script_files(): # 4. Write final iport/oport files logging.info("Writing .iport and .oport files...") -for node_label, ports in node_port_mappings.items(): +for node_label, ports in node_port_mappings.items(): try: containername, sourcecode = node_label.split(':', 1) - if not sourcecode or "." not in sourcecode: continue - dockername = os.path.splitext(sourcecode)[0] - iport_path = os.path.join(outdir, "src", f"{dockername}.iport") - oport_path = os.path.join(outdir, "src", f"{dockername}.oport") - iport_parent = os.path.dirname(iport_path) - if iport_parent: - os.makedirs(iport_parent, exist_ok=True) - with open(iport_path, "w") as fport: - fport.write(str(ports['iport']).replace("'" + prefixedgenode, "'")) - with open(oport_path, "w") as fport: - fport.write(str(ports['oport']).replace("'" + prefixedgenode, "'")) + if not sourcecode or "." not in sourcecode: continue + dockername = os.path.splitext(sourcecode)[0] + iport_path = os.path.join(outdir, "src", f"{dockername}.iport") + oport_path = os.path.join(outdir, "src", f"{dockername}.oport") + iport_parent = os.path.dirname(iport_path) + if iport_parent: + os.makedirs(iport_parent, exist_ok=True) + with open(iport_path, "w") as fport: + fport.write(str(ports['iport']).replace("'" + prefixedgenode, "'")) + with open(oport_path, "w") as fport: + fport.write(str(ports['oport']).replace("'" + prefixedgenode, "'")) except ValueError: continue #if docker, make docker-dirs, generate build, run, stop, clear scripts and quit -if (concoretype=="docker"): - for node in nodes_dict: - containername,sourcecode = nodes_dict[node].split(':') - if len(sourcecode)!=0 and sourcecode.find(".")!=-1: #3/28/21 - dockername,langext = sourcecode.rsplit(".", 1) - dockerfile_path = os.path.join(outdir, "src", f"Dockerfile.{dockername}") - if not os.path.exists(dockerfile_path): # 3/30/21 - try: +if (concoretype=="docker"): + for node in nodes_dict: + containername,sourcecode = nodes_dict[node].split(':') + if len(sourcecode)!=0 and sourcecode.find(".")!=-1: #3/28/21 + dockername,langext = sourcecode.rsplit(".", 1) + dockerfile_path = os.path.join(outdir, "src", f"Dockerfile.{dockername}") + if not os.path.exists(dockerfile_path): # 3/30/21 + try: if langext=="py": src_path = CONCOREPATH+"/Dockerfile.py" logging.info("assuming .py extension for Dockerfile") @@ -759,14 +729,14 @@ def cleanup_script_files(): logging.info("assuming .m extension for Dockerfile") with open(src_path) as fsource: source_content = fsource.read() - except: - logging.error(f"{CONCOREPATH} is not correct path to concore") - quit() - dockerfile_parent = os.path.dirname(dockerfile_path) - if dockerfile_parent: - os.makedirs(dockerfile_parent, exist_ok=True) - with open(dockerfile_path,"w") as fcopy: - fcopy.write(source_content) + except: + logging.error(f"{CONCOREPATH} is not correct path to concore") + quit() + dockerfile_parent = os.path.dirname(dockerfile_path) + if dockerfile_parent: + os.makedirs(dockerfile_parent, exist_ok=True) + with open(dockerfile_path,"w") as fcopy: + fcopy.write(source_content) if langext=="py": fcopy.write('CMD ["python", "-i", "'+sourcecode+'"]\n') if langext=="m": @@ -1010,22 +980,22 @@ def cleanup_script_files(): if concoretype=="posix": fbuild.write('#!/bin/bash' + "\n") -for node in nodes_dict: - containername,sourcecode = nodes_dict[node].split(':') - if len(sourcecode)!=0: - if sourcecode.find(".")==-1: - logging.error("cannot pull container "+sourcecode+" with control core type "+concoretype) #3/28/21 - quit() - dockername,langext = sourcecode.rsplit(".", 1) - fbuild.write('mkdir '+containername+"\n") - source_subdir = os.path.dirname(sourcecode).replace("\\", "/") - if source_subdir: - if concoretype == "windows": - fbuild.write("mkdir .\\"+containername+"\\"+source_subdir.replace("/", "\\")+"\n") - else: - fbuild.write("mkdir -p ./"+containername+"/"+source_subdir+"\n") - if concoretype == "windows": - fbuild.write("copy .\\src\\"+sourcecode+" .\\"+containername+"\\"+sourcecode+"\n") +for node in nodes_dict: + containername,sourcecode = nodes_dict[node].split(':') + if len(sourcecode)!=0: + if sourcecode.find(".")==-1: + logging.error("cannot pull container "+sourcecode+" with control core type "+concoretype) #3/28/21 + quit() + dockername,langext = sourcecode.rsplit(".", 1) + fbuild.write('mkdir '+containername+"\n") + source_subdir = os.path.dirname(sourcecode).replace("\\", "/") + if source_subdir: + if concoretype == "windows": + fbuild.write("mkdir .\\"+containername+"\\"+source_subdir.replace("/", "\\")+"\n") + else: + fbuild.write("mkdir -p ./"+containername+"/"+source_subdir+"\n") + if concoretype == "windows": + fbuild.write("copy .\\src\\"+sourcecode+" .\\"+containername+"\\"+sourcecode+"\n") if langext == "py": fbuild.write("copy .\\src\\concore.py .\\" + containername + "\\concore.py\n") elif langext == "cpp": @@ -1321,4 +1291,4 @@ def cleanup_script_files(): os.chmod(outdir+"/clear",stat.S_IRWXU) os.chmod(outdir+"/maxtime",stat.S_IRWXU) os.chmod(outdir+"/params",stat.S_IRWXU) - os.chmod(outdir+"/unlock",stat.S_IRWXU) + os.chmod(outdir+"/unlock",stat.S_IRWXU)