pull.py
Go to the documentation of this file.
00001 """
00002 The pull command pulls the remote workspace to the local workspace,
00003 making it identical to the workspace on the robot..
00004 
00005 Copyright 2015 Fetch Robotics Inc.
00006 Author: Alex Henning
00007 
00008 """
00009 
00010 import os
00011 import subprocess
00012 import sys
00013 
00014 from ..util import run, add_user, add_robot, add_workspace
00015 
00016 name = "pull"
00017 help_text = "Pull the robots workspace onto the current workspace, losing any differences"
00018 
00019 
00020 def main(args):
00021     print "Pulling %s@%s:%s/src to %s/src " % (
00022         args.user, args.robot, args.remote_workspace, args.workspace,
00023     )
00024 
00025     if not args.no_safety and raw_input("Risk losing local workspace (y/n): ") not in ["y", "yes"]:
00026         print "Giving up, better luck next time."
00027         return
00028 
00029     # Synchronize the workspaces
00030     proc = subprocess.Popen(
00031         ["rsync",
00032          # Following line is a trick to magically create the directory
00033          # if it doesn't exist.
00034          "--rsync-path", "mkdir -p " + args.remote_workspace + " && rsync",
00035          "-phErtz",
00036          "--delete",
00037          args.user + "@" + args.robot + ":" + args.remote_workspace + "/src",
00038          args.workspace + "/"]
00039     )
00040     proc.wait()
00041     if proc.returncode != 0:
00042         print "ERROR: Syncing failed"
00043         sys.exit(-1)
00044 
00045     # Use rosdep to install all dependencies
00046     if args.install_deps:
00047         run("cd "+args.workspace+" && "
00048             "source devel/setup.bash && "
00049             "rosdep update && "
00050             "rosdep install --from-paths src --ignore-src -y")
00051 
00052     # Run the build commands
00053     if args.build is not None:
00054         for build in args.build:
00055             build = build if build is not None else ""
00056             if args.build_type != "default":
00057                 build += " -DCMAKE_BUILD_TYPE="+args.build_type
00058             command = "source /opt/ros/" + os.getenv("ROS_DISTRO") + \
00059                       "/setup.bash && cd " + args.workspace + \
00060                       " && catkin_make " + build
00061             if run(command) != 0:
00062                 print "ERROR: Build failed"
00063                 sys.exit(-1)
00064 
00065 
00066 def add_arguments(parser):
00067     add_user(parser)
00068     add_robot(parser)
00069     add_workspace(parser)
00070     parser.add_argument("--install-deps", action="store_true",
00071                         help="Install dependencies using rosdep")
00072     parser.add_argument("--build", nargs="?", action="append",
00073                         help="Build after syncing")
00074     parser.add_argument("--build-type", action="store", default="default",
00075                         choices=["Debug", "Release", "RelWithDebInfo", "MinSizeRel", "default"],
00076                         help="Type of build to use `default`, `Debug`, `Release`, and `RelWithDebInfo`")
00077     parser.add_argument("--no-safety", action="store_true",
00078                         help="Don't prompt about overwriting the local workspace")


fetch_tools
Author(s): Alex Henning
autogenerated on Thu Jun 6 2019 21:10:20