Skip to content

Commit ea8d105

Browse files
committed
Add Sphinx documentation.
To get the argparse docs required moving most of the install script to a module, which probably should have been done anyway.
1 parent c83761c commit ea8d105

File tree

9 files changed

+236
-67
lines changed

9 files changed

+236
-67
lines changed

doc/conf.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import sys
4+
import os
5+
6+
#sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'src')))
7+
8+
extensions = [
9+
'sphinx.ext.autodoc',
10+
'sphinx.ext.doctest',
11+
'sphinx.ext.viewcode',
12+
'sphinx.ext.viewcode',
13+
'sphinxarg.ext'
14+
]
15+
16+
# Document constructors (off by default)
17+
autoclass_content = 'both'
18+
19+
templates_path = ['_templates']
20+
21+
source_suffix = '.rst'
22+
23+
master_doc = 'index'
24+
25+
project = u'robot_upstart'
26+
copyright = u'2015, Mike Purvis'
27+
28+
# Get version number from package.xml.
29+
import xml.etree.ElementTree as etree
30+
tree = etree.parse('../package.xml')
31+
version = tree.find("version").text
32+
release = version
33+
34+
pygments_style = 'sphinx'
35+
36+
html_theme = 'nature'
37+
38+
htmlhelp_basename = 'robot_upstartdoc'

doc/index.rst

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
Upstart for ROS Robots
2+
======================
3+
4+
This package aims to assist with creating simple platform-specific jobs
5+
to start your robot's ROS launch files when its PC powers up.
6+
7+
.. toctree::
8+
:hidden:
9+
10+
install
11+
jobs
12+
providers
13+
14+
15+
Usage
16+
-----
17+
18+
The basic or one-off usage is with the ``install`` script, which can be
19+
as simple as:
20+
21+
.. code-block:: bash
22+
23+
$ rosrun robot_upstart install myrobot_bringup/launch/base.launch
24+
25+
This will create a job called ``myrobot`` on your machine, which launches
26+
base.launch. It will start automatically when you next start your machine,
27+
or you can bring it up and down manually:
28+
29+
.. code-block:: bash
30+
31+
$ sudo service myrobot start
32+
$ sudo service myrobot stop
33+
34+
If the job is crashing on startup, or you otherwise want to see what is
35+
being output to the terminal on startup, check the upstart log:
36+
37+
.. code-block:: bash
38+
39+
$ sudo tail /var/log/upstart/myrobot.log -n 30
40+
41+
For more details, please see :doc:`install`.
42+
43+
44+
Python API
45+
----------
46+
47+
More advanced users or platform maintainers will prefer to script the
48+
job creation as part of a larger installation script which may do other
49+
tasks, such as pick and choose which launchers to install based on a
50+
recipe, interactive wizard, or hardware introspection scheme.
51+
52+
These users will want to work with the Python API, which is detailed
53+
in :doc:`jobs`.
54+
55+
56+
Extending
57+
---------
58+
59+
If you're interesting in adding support for other init schemes to
60+
robot_upstart, please see :doc:`providers`.
61+
62+
63+
Indexes
64+
-------
65+
66+
* :ref:`genindex`
67+
* :ref:`modindex`
68+
* :ref:`search`
69+

doc/install.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
The ``install`` script
2+
======================
3+
4+
.. argparse::
5+
:module: robot_upstart.install_script
6+
:func: get_argument_parser
7+
:prog: install

doc/jobs.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Jobs
2+
====
3+
4+
.. autoclass:: robot_upstart.Job
5+
:members:

doc/providers.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Providers
2+
=========
3+
4+
.. automodule:: robot_upstart.providers
5+
:members:

rosdoc.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- builder: sphinx
2+
sphinx_root_dir: doc

scripts/install

Lines changed: 1 addition & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -26,73 +26,7 @@
2626
The is the main CLI interface to the robot_upstart package.
2727
"""
2828

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-
29+
from robot_upstart.install_script import main
9630

9731
if __name__ == "__main__":
9832
exit(main())

src/robot_upstart/install_script.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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+
import argparse
27+
import os
28+
29+
import robot_upstart
30+
from catkin.find_in_workspaces import find_in_workspaces
31+
32+
33+
def get_argument_parser():
34+
p = argparse.ArgumentParser(description=
35+
"""Use this tool to quickly and easily create system startup jobs
36+
which run one or more ROS launch files as a daemonized background
37+
process on your computer. More advanced users will prefer to access
38+
the Python API from their own setup scripts, but this exists as a
39+
simple helper, an example, and a compatibility shim for previous
40+
versions of robot_upstart which were bash-based.""")
41+
42+
p.add_argument("pkgpath", type=str, nargs=1, metavar=("pkg/path",),
43+
help="Package and path to install job launch files from.")
44+
p.add_argument("--job", type=str,
45+
help="Specify job name. If unspecified, will be constructed from package name.")
46+
p.add_argument("--interface", type=str, metavar="ethN",
47+
help="Specify network interface name to associate job with.")
48+
p.add_argument("--user", type=str, metavar="NAME",
49+
help="Specify user to launch job as.")
50+
p.add_argument("--setup", type=str, metavar="path/to/setup.bash",
51+
help="Specify workspace setup file for the job launch context.")
52+
p.add_argument("--rosdistro", type=str, metavar="DISTRO",
53+
help="Specify ROS distro this is for.")
54+
p.add_argument("--master", type=str, metavar="http://MASTER:11311",
55+
help="Specify an alternative ROS_MASTER_URI for the job launch context.")
56+
p.add_argument("--logdir", type=str, metavar="path/to/logs",
57+
help="Specify an a value for ROS_LOG_DIR in the job launch context.")
58+
p.add_argument("--augment",
59+
help="Bypass creating the job, and only copy user files. Assumes the job was previously created.")
60+
return p
61+
62+
63+
def main():
64+
args = get_argument_parser().parse_args()
65+
66+
pkg, pkgpath = args.pkgpath[0].split('/', 1)
67+
job_name = args.job or pkg.split('_', 1)[0]
68+
69+
# Any unspecified arguments are on the args object as None. These are filled
70+
# in by the Job constructor when passed as Nones.
71+
j = robot_upstart.Job(name=job_name, interface=args.interface, user=args.user,
72+
workspace_setup=args.setup, rosdistro=args.rosdistro,
73+
master_uri=args.master, log_path=args.logdir)
74+
75+
found_path = find_in_workspaces(project=pkg, path=pkgpath, first_match_only=True)
76+
if not found_path:
77+
print "Unable to located path %s in package %s. Installation aborted." % (pkgpath, pkg)
78+
79+
if os.path.isfile(found_path[0]):
80+
# Single file, install just that.
81+
j.add(package=pkg, filename=pkgpath)
82+
else:
83+
# Directory found, install everything within.
84+
j.add(package=pkg, glob=os.path.join(pkgpath, "*"))
85+
86+
if args.augment:
87+
j.generate_system_files = False
88+
89+
j.install()
90+
91+
return 0;

src/robot_upstart/providers.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,30 @@
3636

3737

3838
class Generic(object):
39+
""" Provides only a common constructor for the moment, but as further
40+
providers are implemented, may provide a place to store configuration
41+
common to them. """
42+
3943
def __init__(self, root, job):
44+
""" Construct a new Provider.
45+
46+
:param root: The filesystem location to prefix all file-install
47+
commands with.
48+
:type root: str
49+
:param job: The job definition to transform to a set of system files.
50+
:type job: :py:class:robot_upstart.Job
51+
"""
4052
self.root = root
4153
self.job = job
4254

4355

4456
class Upstart(Generic):
57+
""" The Upstart implementation places the user-specified files in ``/etc/ros/DISTRO/NAME.d``,
58+
and creates an upstart job configuration in ``/etc/init/NAME.d``. Two additional
59+
helper scripts are created for starting and stopping the job, places in
60+
``/usr/sbin``.
61+
"""
62+
4563
def generate(self):
4664
self.job.job_path = os.path.join(self.root, "etc/ros",
4765
self.job.rosdistro, self.job.name + ".d")

0 commit comments

Comments
 (0)