SMACC2
generate_debs.py
Go to the documentation of this file.
1# Copyright 2021 RobosoftAI Inc.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15# /bin/python
16
17import rospkg
18import subprocess
19import os
20import shutil
21import re
22
23# src/smacc_ci/generate_debs.py -smacc_src_folder src -smacc_viewer_src_folder src
24
25
27 workspace_source_folder, package_name, packagepath, ubuntu_version, ros_distro, already_visited
28):
29 print("-----------------------")
30 print("Working folder: " + str(os.getcwd()))
31 print("Building debian package: " + str(package_name))
32 cmd = (
33 "bloom-generate rosdebian --os-name ubuntu --os-version "
34 + str(ubuntu_version)
35 + " --ros-distro "
36 + str(ros_distro)
37 + " "
38 + str(packagepath)
39 )
40 print(cmd)
41 bloomprocess = subprocess.Popen(cmd, shell=True)
42 bloomprocess.wait()
43
44 develpackagefolder = None
45 for root, dirs, files in os.walk(workspace_source_folder, topdown=False):
46 if "package.xml" in files and package_name == root.split("/")[-1]:
47 print(root)
48 develpackagefolder = root
49 break
50
51 localpackagepath = develpackagefolder
52
53 print("current directory:")
54 print(os.getcwd())
55 print("debian files:")
56 print(os.listdir(""))
57
58 # copy the debian folder generated by bloom inside the package
59 shutil.move("debian", os.path.join(localpackagepath, "debian"))
60
61 os.chdir(localpackagepath)
62 fakerootprocess = subprocess.Popen("fakeroot debian/rules binary", shell=True)
63 fakerootprocess.wait()
64
65 os.chdir(localpackagepath)
66 shutil.rmtree("debian")
67 shutil.rmtree("obj-x86_64-linux-gnu")
68
69 os.chdir(workspace_source_folder)
70
71 # improve this regex
72
73 firstregexstr = ".*ros-" + ros_distro + r"-.*\.deb"
74 regexstr = ".*ros-" + ros_distro + "-" + package_name.replace("_", "-") + r".*\.deb"
75 print("Finding deb package: " + str(regexstr))
76
77 thisfolderfiles = []
78 for root, dirs, files in os.walk(workspace_source_folder, topdown=False):
79 thisfolderfiles = thisfolderfiles + [os.path.join(root, f) for f in files]
80
81 debianfiles = [f for f in thisfolderfiles if re.search(firstregexstr, f)]
82 print("DETECTED DEBIAN FILES:")
83 print(debianfiles)
84 print("VISITED DEBIAN FILES:")
85 print(already_visited)
86
87 debianfilename = [
88 f for f in debianfiles if re.search(regexstr, f) and f not in already_visited
89 ][0]
90
91 print("Debian file found: ")
92 print(debianfilename)
93
94 installdebiantask = subprocess.Popen("sudo dpkg -i " + debianfilename, shell=True)
95 installdebiantask.wait()
96
97 return debianfilename
98
99
101 workspace_source_folder, package_names, identified_install_packages, osversion, rosversion
102):
103 os.chdir(workspace_source_folder)
104 debianfiles = []
105 for pname in package_names:
106 debianfiles.append(
108 workspace_source_folder,
109 pname,
110 identified_install_packages[pname],
111 osversion,
112 rosversion,
113 debianfiles,
114 )
115 )
116 return debianfiles
117
118
119def get_identified_packages(workspace_folder):
120 identified_install_packages = {}
121 exclude_with_words = ["ridgeback", "mecanum", "catkin"]
122 for pname in packagesl:
123 packpath = rospack.get_path(pname)
124 print(pname)
125 if workspace_folder in packpath:
126 if any([True for excludedword in exclude_with_words if excludedword in pname]):
127 continue
128
129 identified_install_packages[pname] = packpath
130 return identified_install_packages
131
132
133def push_debian_files(repo_owner, reponame, osname, osversion, debianfiles):
134 for debf in debianfiles:
135 print("pushing debfile")
136 push_debian_task = subprocess.Popen(
137 "package_cloud push "
138 + repo_owner
139 + "/"
140 + reponame
141 + "/"
142 + osname
143 + "/"
144 + osversion
145 + " "
146 + debf,
147 shell=True,
148 )
149 push_debian_task.wait()
150
151
152def remove_debian_files(repo_owner, reponame, osname, osversion, debianfiles):
153 for debf in debianfiles:
154 shortdebfile = debf.split("/")[-1]
155 print("yanking debfile")
156 push_debian_task = subprocess.Popen(
157 "package_cloud yank "
158 + repo_owner
159 + "/"
160 + reponame
161 + "/"
162 + osname
163 + "/"
164 + osversion
165 + " "
166 + shortdebfile,
167 shell=True,
168 )
169 push_debian_task.wait()
170
171
172# ------------------------ SMACC PACKAGES -----------------------
173
174
175def create_and_push_smacc_debians(osname, osversion, rosversion):
176 workspace_source_folder = os.path.join(workspace_folder, relative_smacc_folder)
177 identified_install_packages = get_identified_packages(workspace_folder)
178
179 smacc_manual_order_packages = [ # 'forward_global_planner',
180 "smacc_msgs",
181 "smacc",
182 "sr_all_events_go",
183 "sr_conditional",
184 "sr_event_countdown",
185 "keyboard_client",
186 "multirole_sensor_client",
187 "ros_publisher_client",
188 "ros_timer_client",
189 "nav2z_client",
190 "forward_global_planner",
191 "forward_local_planner",
192 "backward_global_planner",
193 "undo_path_global_planner",
194 "backward_local_planner",
195 "move_group_interface_client",
196 "sm_atomic",
197 "sm_dance_bot",
198 "sm_dance_bot_strikes_back",
199 "sm_moveit",
200 ]
201
202 smacc_debian_files = iterate_debian_generation(
203 workspace_source_folder,
204 smacc_manual_order_packages,
205 identified_install_packages,
206 osversion,
207 rosversion,
208 )
209
210 create_repo_task = subprocess.Popen("package_cloud repository create smacc", shell=True)
211 create_repo_task.wait()
212
213 # ----- PUSHING TO SMACC --------------
214 remove_debian_files(repo_owner, "smacc", osname, osversion, smacc_debian_files)
215 push_debian_files(repo_owner, "smacc", osname, osversion, smacc_debian_files)
216
217 return smacc_debian_files
218
219
220if __name__ == "__main__":
221 # === requirements for the build machine ==
222 # sudo apt-get install ruby-dev rake
223 # sudo gem update --system
224 # sudo gem install package_cloud
225 # == OR ==
226 # curl -s https://packagecloud.io/install/repositories/fdio/tutorial/script.deb.sh | sudo bash
227
228 import argparse
229 import argcomplete
230
231 # ==== CONFIGURATION PARAMETERS =========
232 repo_owner = "pibgeus"
233
234 # =========================================
235
236 rospack = rospkg.RosPack()
237 packages = rospack.list()
238 packagesl = list(packages)
239
240 parser = argparse.ArgumentParser()
241 parser.add_argument("-smacc_src_folder", help="smacc workspace folder", default="src/SMACC")
242 parser.add_argument(
243 "-smacc_viewer_src_folder", help="relative smacc src folder", default="src/SMACC_Viewer"
244 )
245 parser.add_argument("-repo_owner", help="Repo owner", default="pibgeus")
246 parser.add_argument("-token", help="Repo token", default="")
247 parser.add_argument(
248 "-ros_version", help="The version of ros, ie: kinetic", default="kinetic", type=str
249 )
250 parser.add_argument(
251 "-ubuntu_version", help="The version of ros, ie: xenial", default="xenial", type=str
252 )
253 parser.add_argument("-help", help="Help command")
254
255 argcomplete.autocomplete(parser)
256
257 args = parser.parse_args()
258 # if hasattr(args,'help'):
259 # parser.print_help()
260
261 osname = "ubuntu"
262 osversion = args.ubuntu_version
263 ros_version = args.ros_version
264
265 print("args:" + str(args))
266 print("rosversion: " + ros_version)
267 print("ubuntu: " + osversion)
268
269 relative_smacc_folder = args.smacc_src_folder # "src/SMACC"
270 workspace_folder = os.path.abspath(os.path.join(os.getcwd(), "."))
271
272 repo_owner = args.repo_owner
273
274 print("CREATING TOKEN FILE FOR PACKAGE CLOUD:")
275 homefolder = os.getenv("HOME")
276 packagecloud_token_filepath = os.path.join(homefolder, ".packagecloud")
277
278 outfile = open(packagecloud_token_filepath, "w")
279 outfile.write('{"token":"%s"}' % args.token)
280 outfile.close()
281
282 smacc_debians = create_and_push_smacc_debians(osname, osversion, ros_version)
283
284 print("SMACC DEBIAN'S: " + str(smacc_debians))
def remove_debian_files(repo_owner, reponame, osname, osversion, debianfiles)
def iterate_debian_generation(workspace_source_folder, package_names, identified_install_packages, osversion, rosversion)
def push_debian_files(repo_owner, reponame, osname, osversion, debianfiles)
def build_deb_package(workspace_source_folder, package_name, packagepath, ubuntu_version, ros_distro, already_visited)
def get_identified_packages(workspace_folder)
def create_and_push_smacc_debians(osname, osversion, rosversion)