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


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