Skip to content

Commit 0a780f4

Browse files
author
Séverin Lemaignan
committed
Add support for 'morse import <path>'
This allows to import pre-existing simulations in MORSE for later run them with 'morse run' (or 'morse edit'). 'path' must be a local path. Partially fix morse-simulator#396
1 parent 43d8cf5 commit 0a780f4

File tree

5 files changed

+75
-3
lines changed

5 files changed

+75
-3
lines changed

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ ELSE()
256256
INSTALL(FILES ${SPHINX_MAN_OUTPUT}/morse.1.gz
257257
${SPHINX_MAN_OUTPUT}/morse-run.1.gz
258258
${SPHINX_MAN_OUTPUT}/morse-create.1.gz
259+
${SPHINX_MAN_OUTPUT}/morse-import.1.gz
259260
${SPHINX_MAN_OUTPUT}/morse-edit.1.gz
260261
${SPHINX_MAN_OUTPUT}/morse-check.1.gz
261262
${SPHINX_MAN_OUTPUT}/morse-add.1.gz

bin/morse.in

+37-2
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,32 @@ def create_environment(args):
464464
logger.info("You can run it directly with \"morse run %s\" or you "
465465
"can start editing it." % name)
466466

467+
def import_environment(args):
468+
469+
470+
path = os.path.abspath(args.path)
471+
name = args.name
472+
if not name:
473+
name = os.path.basename(path)
474+
475+
force = args.force
476+
477+
site = get_site(name)
478+
if not force and site:
479+
logger.error("You already have a simulation environment "
480+
"called \"%s\" (pointing to <%s>)!" % (name, site))
481+
logger.error("Use 'morse import -f <path>' to overwrite it.")
482+
sys.exit()
483+
484+
485+
add_site(name, path)
486+
487+
logger.info("The simulation environment <%s> has been successfully "
488+
"imported." % name)
489+
logger.info("You can run it directly with \"morse run %s\" or you "
490+
"can start editing it." % name)
491+
492+
467493
def delete_environment(args):
468494

469495
name = args.env
@@ -717,12 +743,21 @@ if __name__ == '__main__':
717743
subparsers = parser.add_subparsers(title="modes", description="type 'morse <mode> --help' for details", dest = "mode")
718744

719745
# create
720-
create_parser = subparsers.add_parser('create', help="create a new simulation environment in the current directory.")
746+
create_parser = subparsers.add_parser('create', help="creates a new simulation environment in the current directory.")
721747
create_parser.add_argument('env', default="", help="the name of the environment to create.")
722748
create_parser.add_argument('-f', '--force', action='store_true',
723749
help='forces the creation (possibly overwriting files).')
724750
create_parser.set_defaults(func=create_environment)
725751

752+
# import
753+
import_parser = subparsers.add_parser('import', help="imports a pre-existing simulation environment.")
754+
import_parser.add_argument('path', default="", help="the relative or absolute path to the environment. For instance './lab_sim_checkout'.")
755+
import_parser.add_argument('name', default="", nargs='?', help="the name of the environment (extracted from path if not specified).")
756+
import_parser.add_argument('-f', '--force', action='store_true',
757+
help='forces the import (possibly overwriting existing environment).')
758+
import_parser.set_defaults(func=import_environment)
759+
760+
726761
# rm
727762
rm_parser = subparsers.add_parser('rm', help="deletes an existing simulation environment.")
728763
rm_parser.add_argument('env', default="", help="the environment to delete.")
@@ -732,7 +767,7 @@ if __name__ == '__main__':
732767

733768

734769
# add
735-
add_parser = subparsers.add_parser('add', help="add a template for a component to an environment.")
770+
add_parser = subparsers.add_parser('add', help="adds a template for a component to an environment.")
736771
add_parser.add_argument('type', choices=['robot', 'sensor', 'actuator'],
737772
help="the type of component you want to add.")
738773
add_parser.add_argument('name', default="", help="the name of the new component.")

doc/conf.py.in

+1
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ man_pages = [("morse_man_page", "morse", "A robotics simulator based upon the Bl
211211
("morse-run_man_page", "morse-run", "Runs a MORSE simulation", "", 1),
212212
("morse-edit_man_page", "morse-edit", "Loads a MORSE simulation for further edition", "", 1),
213213
("morse-create_man_page", "morse-create", "Creates a MORSE simulation environment", "", 1),
214+
("morse-import_man_page", "morse-import", "Imports a MORSE simulation environment", "", 1),
214215
("morse-check_man_page", "morse-check", "Checks the MORSE configuration", "", 1),
215216
("morse-add_man_page", "morse-add", "Adds a component to a MORSE simulation environment", "", 1),
216217
("morse-rm_man_page", "morse-rm", "Removes a MORSE simulation environment", "", 1),

doc/man/morse-import_man_page.rst

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
:orphan:
2+
3+
morse import manual page
4+
========================
5+
6+
Synopsis
7+
--------
8+
9+
**morse import** [-h] [-f] path [name]
10+
11+
Description
12+
-----------
13+
14+
Imports a directory as a simulation environment, ie, adds an entry to MORSE's
15+
"sites" section of the configuration file (typically, $HOME/.morse/config) that
16+
refers to this directory.
17+
18+
Options
19+
-------
20+
21+
:path: a relative or absolute path to the simulation
22+
environment to import.
23+
:name: the name given to the imported environment.
24+
If not specified, default to the name of the
25+
containing directory (path's basename).
26+
27+
:-h, --help: show this help message and exit
28+
:-f, --force: forces the import (possibly overwriting existing entry).
29+
30+
Refer to :manpage:`morse(1)` for global MORSE options.
31+
32+
See Also
33+
--------
34+
:manpage:`morse(1)`

doc/man/morse_man_page.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ See "man morse-<command>" for a documentation of each commands.
5050
to an existing simulation environment.
5151
:check:
5252
Checks the environment is correctly setup to run morse.
53-
5453
:create:
5554
Creates a new simulation environment in the current directory.
5655
A template simulation scene is also created.
@@ -59,6 +58,8 @@ See "man morse-<command>" for a documentation of each commands.
5958
Open the given Blender scene or Python script in the Blender
6059
interface for edition. The simulation can be started by
6160
pressing P.
61+
:import:
62+
Imports a pre-existing simulation as a new simulation environment.
6263
:rm:
6364
Deletes an existing simulation environment.
6465
:run:

0 commit comments

Comments
 (0)