Skip to content

Commit

Permalink
python: Removed double \ from regex literal strings.
Browse files Browse the repository at this point in the history
  • Loading branch information
levy committed Sep 3, 2024
1 parent 17f4915 commit 9a66835
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 41 deletions.
16 changes: 8 additions & 8 deletions python/inet/common/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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",
Expand Down Expand Up @@ -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)
Expand All @@ -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):
Expand Down
8 changes: 4 additions & 4 deletions python/inet/simulation/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions python/inet/simulation/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions python/inet/test/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
2 changes: 1 addition & 1 deletion python/inet/test/statistical.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
38 changes: 19 additions & 19 deletions python/inet/test/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9a66835

Please sign in to comment.