forked from eProsima/Micro-XRCE-DDS-Agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
combine_default_profiles.py
executable file
·66 lines (54 loc) · 2.1 KB
/
combine_default_profiles.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/python3
import sys, os, re
import shutil
agent_refs_path=""
if len(sys.argv) > 1:
agent_refs_path=sys.argv[1]
dds_security_part_file = os.path.join(agent_refs_path, "dds_security_part.xml")
default_profiles_file = os.path.join(agent_refs_path, "default_profiles.xml")
agent_refs_tmp_file = os.path.join(agent_refs_path, "agent.refs.tmp")
agent_refs_file = os.path.join(agent_refs_path, "agent.refs")
def cleanup_temporary_files():
# cleanup
if os.path.exists(agent_refs_tmp_file):
os.remove(agent_refs_tmp_file)
if os.path.exists(default_profiles_file):
os.remove(default_profiles_file)
if os.path.exists(dds_security_part_file):
os.remove(dds_security_part_file)
sec_part_data = ""
add_sec_part = False
if os.path.exists(dds_security_part_file):
add_sec_part = True
with open(dds_security_part_file, "r") as f:
sec_part_data = f.read()
else:
print("No ROS2 security additions found for default profiles")
### Combine original profiles data to agent.refs
keep_config = True
with open(default_profiles_file, "r") as in_f:
with open(agent_refs_tmp_file, "w") as out_f:
for line in in_f:
line_str = line.strip()
# Replace participant profile name
if line_str.startswith("<participant") and "profile_name=" in line_str:
line = re.sub(
'profile_name="\S+"',
'profile_name="default_xrce_participant"',
line)
# Remove data_reader and data_writer configs
# as they conflicts with xrce client side configs
if line_str.startswith("<data_writer") or line_str.startswith("<data_reader"):
keep_config = False
if keep_config:
out_f.write(line)
if add_sec_part and line_str.startswith("<rtps>"):
out_f.write(sec_part_data)
if line_str.startswith("</data_writer") or line_str.startswith("</data_reader"):
keep_config = True
# Replace original agent.refs with generated one
if os.path.exists(agent_refs_tmp_file):
if os.path.exists(agent_refs_file):
os.remove(agent_refs_file)
shutil.copyfile(agent_refs_tmp_file, agent_refs_file)
cleanup_temporary_files()