push.py
Go to the documentation of this file.
1 """
2 The push command pushes the local workspace to the
3 remote workspace, making it identical to the current workspace.
4 
5 Copyright 2015 Fetch Robotics Inc.
6 Author: Alex Henning
7 """
8 
9 import os
10 import subprocess
11 import sys
12 
13 from ..util import ssh, add_user, add_robot, add_workspace
14 
15 name = "push"
16 help_text = "Push the workspace to the robot"
17 
18 
19 def main(args):
20  print "Pushing %s/src to %s@%s:%s/src" % (
21  args.workspace, args.user, args.robot, args.remote_workspace
22  )
23 
24  # Synchronize the workspaces
25  proc = subprocess.Popen(
26  ["rsync",
27  # Following line is a trick to magically create the directory
28  # if it doesn't exist.
29  "--rsync-path", "mkdir -p " + args.remote_workspace + " && rsync",
30  "-phErtz",
31  "--delete",
32  args.workspace + "/src",
33  args.user + "@" + args.robot + ":" + args.remote_workspace + "/"]
34  )
35  proc.wait()
36  if proc.returncode != 0:
37  print "ERROR: Syncing failed"
38  sys.exit(-1)
39 
40  # Use rosdep to install all dependencies
41  if args.install_deps:
42  ssh(args.user, args.robot,
43  "cd "+args.remote_workspace+" && "
44  "source devel/setup.bash && "
45  "rosdep update && "
46  "rosdep install --from-paths src --ignore-src -y")
47 
48  # Run the build commands
49  if args.build is not None:
50  for build in args.build:
51  build = build if build is not None else ""
52  if args.build_type != "default":
53  build += " -DCMAKE_BUILD_TYPE="+args.build_type
54  command = "source /opt/ros/" + os.getenv("ROS_DISTRO") + \
55  "/setup.bash && cd " + args.remote_workspace + \
56  " && catkin_make " + build
57  if ssh(args.user, args.robot, command) != 0:
58  print "ERROR: Build failed"
59  sys.exit(-1)
60 
61 
62 def add_arguments(parser):
63  add_user(parser)
64  add_robot(parser)
65  add_workspace(parser)
66  parser.add_argument("--install-deps", action="store_true",
67  help="Install dependencies using rosdep")
68  parser.add_argument("--build", nargs="?", action="append",
69  help="Build after syncing")
70  parser.add_argument("--build-type", action="store", default="default",
71  choices=["Debug", "Release", "RelWithDebInfo", "MinSizeRel", "default"],
72  help="Type of build to use `default`, `Debug`, `Release`, and `RelWithDebInfo`")
def add_workspace(parser)
Definition: util.py:64
def add_arguments(parser)
Definition: push.py:62
def ssh(user, host, command, password=None, fname=None)
Definition: util.py:12
def add_robot(parser)
Definition: util.py:59
def add_user(parser)
Definition: util.py:53


fetch_tools
Author(s): Alex Henning
autogenerated on Mon Feb 28 2022 22:19:10