1+ import os , sys
2+ import json
3+ import xml .etree .ElementTree as xml_parser
4+
5+ from .utils import run_cmd
6+
7+ class Package :
8+ def __init__ (self , name , path ):
9+ self .name = name
10+ self .path = path
11+ self .ignored = False
12+
13+ def ignore (self ):
14+ self .ignored = True
15+ ignore_path = self .path + '/COLCON_IGNORE'
16+ with open (ignore_path , 'a' ):
17+ os .utime (ignore_path , None )
18+
19+ class Repository :
20+ def __init__ (self , name , url , distribution , branch = None ):
21+ self .name = name
22+ self .url = url
23+ self .distribution = distribution
24+ self .branch = distribution if branch is None else branch
25+ self .path = None
26+
27+ def clone (self , folder ):
28+ self .path = folder + "/" + self .name
29+ # TODO(pablogs) ensure that git is installed
30+ command = "git clone -b {} {} {}" .format (self .branch , self .url , self .path )
31+ result = run_cmd (command )
32+
33+ if 0 != result .returncode :
34+ print ("{} clone failed: \n {}" .format (self .name , result .stderr .decode ("utf-8" )))
35+ sys .exit (1 )
36+
37+ def get_packages (self ):
38+ packages = []
39+ if os .path .exists (self .path + '/package.xml' ):
40+ packages .append (Package (self .name , self .path ))
41+ else :
42+ for root , dirs , files in os .walk (self .path ):
43+ path = root .split (os .sep )
44+ if 'package.xml' in files :
45+ package_name = Repository .get_package_name_from_package_xml (os .path .join (root , 'package.xml' ))
46+ package_path = os .path .join (os .getcwd (), root )
47+ packages .append (Package (package_name , package_path ))
48+ elif 'colcon.pkg' in files :
49+ package_name = Repository .get_package_name_from_colcon_pkg (os .path .join (root , 'colcon.pkg' ))
50+ package_path = os .path .join (os .getcwd (), root )
51+ packages .append (Package (package_name , package_path ))
52+ return packages
53+
54+ def get_package_name_from_package_xml (xml_file ):
55+ root_node = xml_parser .parse (xml_file ).getroot ()
56+ name_node = root_node .find ('name' )
57+ if name_node is not None :
58+ return name_node .text
59+ return None
60+
61+ def get_package_name_from_colcon_pkg (colcon_pkg ):
62+ with open (colcon_pkg , 'r' ) as f :
63+ content = json .load (f )
64+ if content ['name' ]:
65+ return content ['name' ]
66+ return None
67+
68+ class Sources :
69+ dev_environments = {
70+ 'galactic' : [
71+ Repository ("ament_cmake" , "https://github.com/ament/ament_cmake" , "galactic" ),
72+ Repository ("ament_lint" , "https://github.com/ament/ament_lint" , "galactic" ),
73+ Repository ("ament_package" , "https://github.com/ament/ament_package" , "galactic" ),
74+ Repository ("googletest" , "https://github.com/ament/googletest" , "galactic" ),
75+ Repository ("ament_cmake_ros" , "https://github.com/ros2/ament_cmake_ros" , "galactic" ),
76+ Repository ("ament_index" , "https://github.com/ament/ament_index" , "galactic" )
77+ ],
78+ 'rolling' : [
79+ Repository ("ament_cmake" , "https://github.com/ament/ament_cmake" , "rolling" , "master" ),
80+ Repository ("ament_lint" , "https://github.com/ament/ament_lint" , "rolling" , "master" ),
81+ Repository ("ament_package" , "https://github.com/ament/ament_package" , "rolling" , "master" ),
82+ Repository ("googletest" , "https://github.com/ament/googletest" , "rolling" , "ros2" ),
83+ Repository ("ament_cmake_ros" , "https://github.com/ros2/ament_cmake_ros" , "rolling" , "master" ),
84+ Repository ("ament_index" , "https://github.com/ament/ament_index" , "rolling" , "master" )
85+ ]
86+ }
87+
88+ mcu_environments = {
89+ 'galactic' : [
90+ Repository ("micro-CDR" , "https://github.com/eProsima/micro-CDR" , "galactic" , "ros2" ),
91+ Repository ("Micro-XRCE-DDS-Client" , "https://github.com/eProsima/Micro-XRCE-DDS-Client" , "galactic" , "ros2" ),
92+ Repository ("rcl" , "https://github.com/micro-ROS/rcl" , "galactic" ),
93+ Repository ("rclc" , "https://github.com/ros2/rclc" , "galactic" ),
94+ Repository ("micro_ros_utilities" , "https://github.com/micro-ROS/micro_ros_utilities" , "galactic" ),
95+ Repository ("rcutils" , "https://github.com/micro-ROS/rcutils" , "galactic" ),
96+ Repository ("micro_ros_msgs" , "https://github.com/micro-ROS/micro_ros_msgs" , "galactic" ),
97+ Repository ("rmw-microxrcedds" , "https://github.com/micro-ROS/rmw-microxrcedds" , "galactic" ),
98+ Repository ("rosidl_typesupport" , "https://github.com/micro-ROS/rosidl_typesupport" , "galactic" ),
99+ Repository ("rosidl_typesupport_microxrcedds" , "https://github.com/micro-ROS/rosidl_typesupport_microxrcedds" , "galactic" ),
100+ Repository ("rosidl" , "https://github.com/ros2/rosidl" , "galactic" ),
101+ Repository ("rmw" , "https://github.com/ros2/rmw" , "galactic" ),
102+ Repository ("rcl_interfaces" , "https://github.com/ros2/rcl_interfaces" , "galactic" ),
103+ Repository ("rosidl_defaults" , "https://github.com/ros2/rosidl_defaults" , "galactic" ),
104+ Repository ("unique_identifier_msgs" , "https://github.com/ros2/unique_identifier_msgs" , "galactic" ),
105+ Repository ("common_interfaces" , "https://github.com/ros2/common_interfaces" , "galactic" ),
106+ Repository ("test_interface_files" , "https://github.com/ros2/test_interface_files" , "galactic" ),
107+ Repository ("rmw_implementation" , "https://github.com/ros2/rmw_implementation" , "galactic" ),
108+ Repository ("rcl_logging" , "https://github.com/ros2/rcl_logging" , "galactic" ),
109+ Repository ("ros2_tracing" , "https://gitlab.com/micro-ROS/ros_tracing/ros2_tracing" , "galactic" ),
110+ ],
111+ 'rolling' : [
112+ Repository ("micro-CDR" , "https://github.com/eProsima/micro-CDR" , "rolling" , "ros2" ),
113+ Repository ("Micro-XRCE-DDS-Client" , "https://github.com/eProsima/Micro-XRCE-DDS-Client" , "rolling" , "ros2" ),
114+ Repository ("rcl" , "https://github.com/micro-ROS/rcl" , "rolling" , "master" ),
115+ Repository ("rclc" , "https://github.com/ros2/rclc" , "rolling" , "master" ),
116+ Repository ("micro_ros_utilities" , "https://github.com/micro-ROS/micro_ros_utilities" , "rolling" , "main" ),
117+ Repository ("rcutils" , "https://github.com/micro-ROS/rcutils" , "rolling" , "master" ),
118+ Repository ("micro_ros_msgs" , "https://github.com/micro-ROS/micro_ros_msgs" , "rolling" , "main" ),
119+ Repository ("rmw-microxrcedds" , "https://github.com/micro-ROS/rmw-microxrcedds" , "rolling" , "main" ),
120+ Repository ("rosidl_typesupport" , "https://github.com/micro-ROS/rosidl_typesupport" , "rolling" , "master" ),
121+ Repository ("rosidl_typesupport_microxrcedds" , "https://github.com/micro-ROS/rosidl_typesupport_microxrcedds" , "rolling" , "main" ),
122+ Repository ("rosidl" , "https://github.com/ros2/rosidl" , "rolling" , "master" ),
123+ Repository ("rmw" , "https://github.com/ros2/rmw" , "rolling" , "master" ),
124+ Repository ("rcl_interfaces" , "https://github.com/ros2/rcl_interfaces" , "rolling" , "master" ),
125+ Repository ("rosidl_defaults" , "https://github.com/ros2/rosidl_defaults" , "rolling" , "master" ),
126+ Repository ("unique_identifier_msgs" , "https://github.com/ros2/unique_identifier_msgs" , "rolling" , "master" ),
127+ Repository ("common_interfaces" , "https://github.com/ros2/common_interfaces" , "rolling" , "master" ),
128+ Repository ("test_interface_files" , "https://github.com/ros2/test_interface_files" , "rolling" , "master" ),
129+ Repository ("rmw_implementation" , "https://github.com/ros2/rmw_implementation" , "rolling" , "master" ),
130+ Repository ("rcl_logging" , "https://github.com/ros2/rcl_logging" , "rolling" , "master" ),
131+ Repository ("ros2_tracing" , "https://gitlab.com/micro-ROS/ros_tracing/ros2_tracing" , "rolling" , "master" ),
132+ ]
133+ }
134+
135+ ignore_packages = {
136+ 'galactic' : ['rcl_logging_log4cxx' , 'rcl_logging_spdlog' , 'rcl_yaml_param_parser' , 'rclc_examples' ],
137+ 'rolling' : ['rcl_logging_log4cxx' , 'rcl_logging_spdlog' , 'rcl_yaml_param_parser' , 'rclc_examples' ]
138+ }
0 commit comments