|
| 1 | +#!/usr/bin/env python |
| 2 | +# Software License Agreement (BSD) |
| 3 | +# |
| 4 | +# @author Mike Purvis <[email protected]> |
| 5 | +# @copyright (c) 2015, Clearpath Robotics, Inc., All rights reserved. |
| 6 | +# |
| 7 | +# Redistribution and use in source and binary forms, with or without modification, are permitted provided that |
| 8 | +# the following conditions are met: |
| 9 | +# * Redistributions of source code must retain the above copyright notice, this list of conditions and the |
| 10 | +# following disclaimer. |
| 11 | +# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the |
| 12 | +# following disclaimer in the documentation and/or other materials provided with the distribution. |
| 13 | +# * Neither the name of Clearpath Robotics nor the names of its contributors may be used to endorse or |
| 14 | +# promote products derived from this software without specific prior written permission. |
| 15 | +# |
| 16 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED |
| 17 | +# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
| 18 | +# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
| 19 | +# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED |
| 20 | +# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 21 | +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 22 | +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 23 | +# POSSIBILITY OF SUCH DAMAGE. |
| 24 | + |
| 25 | +""" |
| 26 | +The is the main CLI interface to the robot_upstart package. |
| 27 | +""" |
| 28 | + |
| 29 | +import argparse |
| 30 | +import os |
| 31 | + |
| 32 | +import robot_upstart |
| 33 | +from catkin.find_in_workspaces import find_in_workspaces |
| 34 | + |
| 35 | + |
| 36 | +def get_argument_parser(): |
| 37 | + p = argparse.ArgumentParser(description= |
| 38 | + """Use this tool to quickly and easily create system startup jobs |
| 39 | + which run one or more ROS launch files as a daemonized background |
| 40 | + process on your computer. More advanced users will prefer to access |
| 41 | + the Python API from their own setup scripts, but this exists as a |
| 42 | + simple helper, an example, and a compatibility shim for previous |
| 43 | + versions of robot_upstart which were bash-based.""") |
| 44 | + |
| 45 | + p.add_argument("pkgpath", type=str, nargs=1, metavar=("pkg/path",), |
| 46 | + help="Package and path to install job launch files from.") |
| 47 | + p.add_argument("--job", type=str, |
| 48 | + help="Specify job name. If unspecified, will be constructed from package name.") |
| 49 | + p.add_argument("--interface", type=str, metavar="ethN", |
| 50 | + help="Specify network interface name to associate job with.") |
| 51 | + p.add_argument("--user", type=str, metavar="NAME", |
| 52 | + help="Specify user to launch job as.") |
| 53 | + p.add_argument("--setup", type=str, metavar="path/to/setup.bash", |
| 54 | + help="Specify workspace setup file for the job launch context.") |
| 55 | + p.add_argument("--rosdistro", type=str, metavar="DISTRO", |
| 56 | + help="Specify ROS distro this is for.") |
| 57 | + p.add_argument("--master", type=str, metavar="http://MASTER:11311", |
| 58 | + help="Specify an alternative ROS_MASTER_URI for the job launch context.") |
| 59 | + p.add_argument("--logdir", type=str, metavar="path/to/logs", |
| 60 | + help="Specify an a value for ROS_LOG_DIR in the job launch context.") |
| 61 | + p.add_argument("--augment", |
| 62 | + help="Bypass creating the job, and only copy user files. Assumes the job was previously created.") |
| 63 | + return p |
| 64 | + |
| 65 | + |
| 66 | +def main(): |
| 67 | + args = get_argument_parser().parse_args() |
| 68 | + |
| 69 | + pkg, pkgpath = args.pkgpath[0].split('/', 1) |
| 70 | + job_name = args.job or pkg.split('_', 1)[0] |
| 71 | + |
| 72 | + # Any unspecified arguments are on the args object as None. These are filled |
| 73 | + # in by the Job constructor when passed as Nones. |
| 74 | + j = robot_upstart.Job(name=job_name, interface=args.interface, user=args.user, |
| 75 | + workspace_setup=args.setup, rosdistro=args.rosdistro, |
| 76 | + master_uri=args.master, log_path=args.logdir) |
| 77 | + |
| 78 | + found_path = find_in_workspaces(project=pkg, path=pkgpath, first_match_only=True) |
| 79 | + if not found_path: |
| 80 | + print "Unable to located path %s in package %s. Installation aborted." % (pkgpath, pkg) |
| 81 | + |
| 82 | + if os.path.isfile(found_path[0]): |
| 83 | + # Single file, install just that. |
| 84 | + j.add(package=pkg, filename=pkgpath) |
| 85 | + else: |
| 86 | + # Directory found, install everything within. |
| 87 | + j.add(package=pkg, glob=os.path.join(pkgpath, "*")) |
| 88 | + |
| 89 | + if args.augment: |
| 90 | + j.generate_system_files = False |
| 91 | + |
| 92 | + j.install() |
| 93 | + |
| 94 | + return 0; |
| 95 | + |
| 96 | + |
| 97 | +if __name__ == "__main__": |
| 98 | + exit(main()) |
0 commit comments