From 9a66835378e4f24a170af688c83099ab0b43dba3 Mon Sep 17 00:00:00 2001 From: Levente Meszaros Date: Tue, 3 Sep 2024 10:55:02 +0200 Subject: [PATCH] python: Removed double \ from regex literal strings. --- python/inet/common/compile.py | 16 ++++++------- python/inet/simulation/build.py | 8 +++---- python/inet/simulation/project.py | 6 ++--- python/inet/test/feature.py | 12 +++++----- python/inet/test/statistical.py | 2 +- python/inet/test/validation.py | 38 +++++++++++++++---------------- 6 files changed, 41 insertions(+), 41 deletions(-) diff --git a/python/inet/common/compile.py b/python/inet/common/compile.py index 4968739c392..69c262dac20 100644 --- a/python/inet/common/compile.py +++ b/python/inet/common/compile.py @@ -68,8 +68,8 @@ def get_parameters_string(self, **kwargs): def get_input_files(self): output_folder = f"out/clang-{self.mode}" - object_path = re.sub(r"\\.msg", "_m.cc", self.file_path) - dependency_file_path = re.sub(r"\\.msg", "_m.h.d", self.file_path) + object_path = re.sub(r"\.msg", "_m.cc", self.file_path) + dependency_file_path = re.sub(r"\.msg", "_m.h.d", self.file_path) full_file_path = self.simulation_project.get_full_path(os.path.join(output_folder, dependency_file_path)) if os.path.exists(full_file_path): dependency = read_dependency_file(full_file_path) @@ -80,14 +80,14 @@ def get_input_files(self): return [self.file_path] def get_output_files(self): - cpp_file_path = re.sub(r"\\.msg", "_m.cc", self.file_path) - header_file_path = re.sub(r"\\.msg", "_m.h", self.file_path) + cpp_file_path = re.sub(r"\.msg", "_m.cc", self.file_path) + header_file_path = re.sub(r"\.msg", "_m.h", self.file_path) return [f"{cpp_file_path}", f"{header_file_path}"] def get_arguments(self): executable = "opp_msgc" output_folder = f"out/clang-{self.mode}" - header_file_path = re.sub(r"\\.msg", "_m.h", self.file_path) + header_file_path = re.sub(r"\.msg", "_m.h", self.file_path) import_paths = list(map(lambda msg_folder: self.simulation_project.get_full_path(msg_folder), self.simulation_project.msg_folders)) return [executable, "--msg6", @@ -118,8 +118,8 @@ def get_parameters_string(self, **kwargs): def get_input_files(self): output_folder = f"out/clang-{self.mode}" - object_path = re.sub(r"\\.cc", ".o", self.file_path) - dependency_file_path = re.sub(r"\\.cc", ".o.d", self.file_path) + object_path = re.sub(r"\.cc", ".o", self.file_path) + dependency_file_path = re.sub(r"\.cc", ".o.d", self.file_path) full_file_path = self.simulation_project.get_full_path(os.path.join(output_folder, dependency_file_path)) if os.path.exists(full_file_path): dependency = read_dependency_file(full_file_path) @@ -130,7 +130,7 @@ def get_input_files(self): def get_output_files(self): output_folder = f"out/clang-{self.mode}" - object_path = re.sub(r"\\.cc", ".o", self.file_path) + object_path = re.sub(r"\.cc", ".o", self.file_path) return [f"{output_folder}/{object_path}"] def get_arguments(self): diff --git a/python/inet/simulation/build.py b/python/inet/simulation/build.py index 0773838daa6..19c878ef074 100644 --- a/python/inet/simulation/build.py +++ b/python/inet/simulation/build.py @@ -117,8 +117,8 @@ def __init__(self, simulation_project=None, name="MSG compile task", mode="relea self.simulation_project = simulation_project self.mode = mode self.input_files = list(map(lambda input_file: self.simulation_project.get_full_path(input_file), self.simulation_project.get_msg_files())) - self.output_files = list(map(lambda output_file: re.sub(r"\\.msg", "_m.cc", output_file), self.input_files)) + \ - list(map(lambda output_file: re.sub(r"\\.msg", "_m.h", output_file), self.input_files)) + self.output_files = list(map(lambda output_file: re.sub(r"\.msg", "_m.cc", output_file), self.input_files)) + \ + list(map(lambda output_file: re.sub(r"\.msg", "_m.h", output_file), self.input_files)) def get_description(self): return self.simulation_project.get_name() + " " + super().get_description() @@ -165,7 +165,7 @@ def get_object_files(self): object_files = [] for cpp_folder in self.simulation_project.cpp_folders: file_paths = glob.glob(self.simulation_project.get_full_path(os.path.join(cpp_folder, "**/*.cc")), recursive=True) - object_files = object_files + list(map(lambda file_path: os.path.join(output_folder, self.simulation_project.get_relative_path(re.sub(r"\\.cc", ".o", file_path))), file_paths)) + object_files = object_files + list(map(lambda file_path: os.path.join(output_folder, self.simulation_project.get_relative_path(re.sub(r"\.cc", ".o", file_path))), file_paths)) return object_files def is_up_to_date(self): @@ -280,7 +280,7 @@ def get_build_tasks(self, **kwargs): os.makedirs(output_folder) msg_compile_tasks = list(map(lambda msg_file: MsgCompileTask(simulation_project=self.simulation_project, file_path=msg_file, mode=self.mode), self.simulation_project.get_msg_files())) multiple_msg_compile_tasks = MultipleMsgCompileTasks(simulation_project=self.simulation_project, mode=self.mode, tasks=msg_compile_tasks, concurrent=self.concurrent_child_tasks) - msg_cpp_compile_tasks = list(map(lambda msg_file: CppCompileTask(simulation_project=self.simulation_project, file_path=re.sub(r"\\.msg", "_m.cc", msg_file), mode=self.mode), self.simulation_project.get_msg_files())) + msg_cpp_compile_tasks = list(map(lambda msg_file: CppCompileTask(simulation_project=self.simulation_project, file_path=re.sub(r"\.msg", "_m.cc", msg_file), mode=self.mode), self.simulation_project.get_msg_files())) cpp_compile_tasks = list(map(lambda cpp_file: CppCompileTask(simulation_project=self.simulation_project, file_path=cpp_file, mode=self.mode), self.simulation_project.get_cpp_files())) all_cpp_compile_tasks = msg_cpp_compile_tasks + cpp_compile_tasks multiple_cpp_compile_tasks = MultipleCppCompileTasks(simulation_project=self.simulation_project, mode=self.mode, tasks=all_cpp_compile_tasks, concurrent=self.concurrent_child_tasks) diff --git a/python/inet/simulation/project.py b/python/inet/simulation/project.py index af3ef1b6e84..7293dc14cf2 100644 --- a/python/inet/simulation/project.py +++ b/python/inet/simulation/project.py @@ -271,14 +271,14 @@ def get_effective_include_folders(self): def get_cpp_files(self): cpp_files = [] for cpp_folder in self.cpp_folders: - file_paths = list(filter(lambda file_path: not re.search(r"_m\\.cc", file_path), glob.glob(self.get_full_path(os.path.join(cpp_folder, "**/*.cc")), recursive=True))) + file_paths = list(filter(lambda file_path: not re.search(r"_m\.cc", file_path), glob.glob(self.get_full_path(os.path.join(cpp_folder, "**/*.cc")), recursive=True))) cpp_files = cpp_files + list(map(lambda file_path: self.get_relative_path(file_path), file_paths)) return cpp_files def get_header_files(self): header_files = [] for cpp_folder in self.cpp_folders: - file_paths = list(filter(lambda file_path: not re.search(r"_m\\.h", file_path), glob.glob(self.get_full_path(os.path.join(cpp_folder, "**/*.h")), recursive=True))) + file_paths = list(filter(lambda file_path: not re.search(r"_m\.h", file_path), glob.glob(self.get_full_path(os.path.join(cpp_folder, "**/*.h")), recursive=True))) header_files = header_files + list(map(lambda file_path: self.get_relative_path(file_path), file_paths)) return header_files @@ -313,7 +313,7 @@ def create_config_dict(config): config_dicts = {"General": create_config_dict("General")} config_dict = {} for line in file: - match = re.match(r"\\[(Config +)?(.*?)\\]", line) + match = re.match(r"\[(Config +)?(.*?)\]", line) if match: config = match.group(2) or match.group(3) config_dict = create_config_dict(config) diff --git a/python/inet/test/feature.py b/python/inet/test/feature.py index 0e57ac71932..801928ba49d 100644 --- a/python/inet/test/feature.py +++ b/python/inet/test/feature.py @@ -109,17 +109,17 @@ def read_xml_file(filename, repair_hint=None): def get_package_folder(package): if re.search(r"inet.examples", package): - return re.sub(r"inet/", "", re.sub(r"\\.", "/", package)) + return re.sub(r"inet/", "", re.sub(r"\.", "/", package)) elif re.search(r"inet.showcases", package): - return re.sub(r"inet/", "", re.sub(r"\\.", "/", package)) + return re.sub(r"inet/", "", re.sub(r"\.", "/", package)) elif re.search(r"inet.tutorials", package): - return re.sub(r"inet/", "", re.sub(r"\\.", "/", package)) + return re.sub(r"inet/", "", re.sub(r"\.", "/", package)) elif re.search(r"inet.tests", package): - return re.sub(r"inet/", "", re.sub(r"\\.", "/", package)) + return re.sub(r"inet/", "", re.sub(r"\.", "/", package)) elif re.search(r"inet.validation", package): - return re.sub(r"inet/", "tests/", re.sub(r"\\.", "/", package)) + return re.sub(r"inet/", "tests/", re.sub(r"\.", "/", package)) else: - return "src/" + re.sub(r"\\.", "/", package) + return "src/" + re.sub(r"\.", "/", package) def get_features(oppfeatures): result = [] diff --git a/python/inet/test/statistical.py b/python/inet/test/statistical.py index 9316f5f18da..ff72bd45bc7 100644 --- a/python/inet/test/statistical.py +++ b/python/inet/test/statistical.py @@ -84,7 +84,7 @@ def check_simulation_task_result(self, simulation_task_result, result_name_filte id = next(iter(df.index), None) reason = df.loc[id].to_string() reason = re.sub(r" +", " = ", reason) - reason = re.sub(r"\\n", ", ", reason) + reason = re.sub(r"\n", ", ", reason) return self.task_result_class(task=self, simulation_task_result=simulation_task_result, result="FAIL", reason=reason) else: return self.task_result_class(task=self, simulation_task_result=simulation_task_result, result="PASS") diff --git a/python/inet/test/validation.py b/python/inet/test/validation.py index baa287fca2d..c0b3e161b1e 100644 --- a/python/inet/test/validation.py +++ b/python/inet/test/validation.py @@ -109,15 +109,15 @@ def compute_asynchronousshaper_icct_endtoend_delay_from_simulation_results(**kwa filter_expression = """type =~ scalar AND name =~ meanBitLifeTimePerPacket:histogram:max""" df = read_result_files(inet_project.get_full_path("tests/validation/tsn/trafficshaping/asynchronousshaper/icct/results/*.sca"), filter_expression=filter_expression, include_fields_as_scalars=True) df = get_scalars(df) - df["name"] = df["name"].map(lambda name: re.sub(r".*(min|max)", "\\1", name)) - df["module"] = df["module"].map(lambda name: re.sub(r".*N6.app\\[[0-4]\\].*", "Flow 4, Class A", name)) - df["module"] = df["module"].map(lambda name: re.sub(r".*N6.app\\[[5-9]\\].*", "Flow 5, Class B", name)) - df["module"] = df["module"].map(lambda name: re.sub(r".*N7.app\\[[0-9]\\].*", "Flow 1, CDT", name)) - df["module"] = df["module"].map(lambda name: re.sub(r".*N7.app\\[1[0-9]\\].*", "Flow 2, Class A", name)) - df["module"] = df["module"].map(lambda name: re.sub(r".*N7.app\\[2[0-9]\\].*", "Flow 3, Class B", name)) - df["module"] = df["module"].map(lambda name: re.sub(r".*N7.app\\[3[0-4]\\].*", "Flow 6, Class A", name)) - df["module"] = df["module"].map(lambda name: re.sub(r".*N7.app\\[3[5-9]\\].*", "Flow 7, Class B", name)) - df["module"] = df["module"].map(lambda name: re.sub(r".*N7.app\\[40\\].*", "Flow 8, Best Effort", name)) + df["name"] = df["name"].map(lambda name: re.sub(r".*(min|max)", "\1", name)) + df["module"] = df["module"].map(lambda name: re.sub(r".*N6.app\[[0-4]\].*", "Flow 4, Class A", name)) + df["module"] = df["module"].map(lambda name: re.sub(r".*N6.app\[[5-9]\].*", "Flow 5, Class B", name)) + df["module"] = df["module"].map(lambda name: re.sub(r".*N7.app\[[0-9]\].*", "Flow 1, CDT", name)) + df["module"] = df["module"].map(lambda name: re.sub(r".*N7.app\[1[0-9]\].*", "Flow 2, Class A", name)) + df["module"] = df["module"].map(lambda name: re.sub(r".*N7.app\[2[0-9]\].*", "Flow 3, Class B", name)) + df["module"] = df["module"].map(lambda name: re.sub(r".*N7.app\[3[0-4]\].*", "Flow 6, Class A", name)) + df["module"] = df["module"].map(lambda name: re.sub(r".*N7.app\[3[5-9]\].*", "Flow 7, Class B", name)) + df["module"] = df["module"].map(lambda name: re.sub(r".*N7.app\[40\].*", "Flow 8, Best Effort", name)) df = pd.pivot_table(df, index="module", columns="name", values="value", aggfunc="max") return df * 1000000 @@ -155,11 +155,11 @@ def compute_asynchronousshaper_core4inet_endtoend_delay_from_simulation_results( filter_expression = """type =~ scalar AND (name =~ meanBitLifeTimePerPacket:histogram:min OR name =~ meanBitLifeTimePerPacket:histogram:max OR name =~ meanBitLifeTimePerPacket:histogram:mean OR name =~ meanBitLifeTimePerPacket:histogram:stddev)""" df = read_result_files(inet_project.get_full_path("tests/validation/tsn/trafficshaping/asynchronousshaper/core4inet/results/*.sca"), filter_expression=filter_expression, include_fields_as_scalars=True) df = get_scalars(df) - df["name"] = df["name"].map(lambda name: re.sub(r".*(min|max|mean|stddev)", "\\1", name)) - df["module"] = df["module"].map(lambda name: re.sub(r".*app\\[0\\].*", "Best effort", name)) - df["module"] = df["module"].map(lambda name: re.sub(r".*app\\[1\\].*", "Medium", name)) - df["module"] = df["module"].map(lambda name: re.sub(r".*app\\[2\\].*", "High", name)) - df["module"] = df["module"].map(lambda name: re.sub(r".*app\\[3\\].*", "Critical", name)) + df["name"] = df["name"].map(lambda name: re.sub(r".*(min|max|mean|stddev)", "\1", name)) + df["module"] = df["module"].map(lambda name: re.sub(r".*app\[0\].*", "Best effort", name)) + df["module"] = df["module"].map(lambda name: re.sub(r".*app\[1\].*", "Medium", name)) + df["module"] = df["module"].map(lambda name: re.sub(r".*app\[2\].*", "High", name)) + df["module"] = df["module"].map(lambda name: re.sub(r".*app\[3\].*", "Critical", name)) df = df.loc[df["module"]!="Best effort"] df = pd.pivot_table(df, index="module", columns="name", values="value") return df * 1000000 @@ -222,11 +222,11 @@ def compute_creditbasedshaper_endtoend_delay_from_simulation_results(**kwargs): filter_expression = """type =~ scalar AND (name =~ meanBitLifeTimePerPacket:histogram:min OR name =~ meanBitLifeTimePerPacket:histogram:max OR name =~ meanBitLifeTimePerPacket:histogram:mean OR name =~ meanBitLifeTimePerPacket:histogram:stddev)""" df = read_result_files(inet_project.get_full_path("tests/validation/tsn/trafficshaping/creditbasedshaper/results/*.sca"), filter_expression=filter_expression, include_fields_as_scalars=True) df = get_scalars(df) - df["name"] = df["name"].map(lambda name: re.sub(r".*(min|max|mean|stddev)", "\\1", name)) - df["module"] = df["module"].map(lambda name: re.sub(r".*app\\[0\\].*", "Best effort", name)) - df["module"] = df["module"].map(lambda name: re.sub(r".*app\\[1\\].*", "Medium", name)) - df["module"] = df["module"].map(lambda name: re.sub(r".*app\\[2\\].*", "High", name)) - df["module"] = df["module"].map(lambda name: re.sub(r".*app\\[3\\].*", "Critical", name)) + df["name"] = df["name"].map(lambda name: re.sub(r".*(min|max|mean|stddev)", "\1", name)) + df["module"] = df["module"].map(lambda name: re.sub(r".*app\[0\].*", "Best effort", name)) + df["module"] = df["module"].map(lambda name: re.sub(r".*app\[1\].*", "Medium", name)) + df["module"] = df["module"].map(lambda name: re.sub(r".*app\[2\].*", "High", name)) + df["module"] = df["module"].map(lambda name: re.sub(r".*app\[3\].*", "Critical", name)) df = df.loc[df["module"]!="Best effort"] df = pd.pivot_table(df, index="module", columns="name", values="value") return df * 1000000