@@ -464,6 +464,32 @@ def create_environment(args):
464
464
logger.info("You can run it directly with \"morse run %s\" or you "
465
465
"can start editing it." % name)
466
466
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
+
467
493
def delete_environment(args):
468
494
469
495
name = args.env
@@ -717,12 +743,21 @@ if __name__ == '__main__':
717
743
subparsers = parser.add_subparsers(title="modes", description="type 'morse <mode> --help' for details", dest = "mode")
718
744
719
745
# 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.")
721
747
create_parser.add_argument('env', default="", help="the name of the environment to create.")
722
748
create_parser.add_argument('-f', '--force', action='store_true',
723
749
help='forces the creation (possibly overwriting files).')
724
750
create_parser.set_defaults(func=create_environment)
725
751
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
+
726
761
# rm
727
762
rm_parser = subparsers.add_parser('rm', help="deletes an existing simulation environment.")
728
763
rm_parser.add_argument('env', default="", help="the environment to delete.")
@@ -732,7 +767,7 @@ if __name__ == '__main__':
732
767
733
768
734
769
# 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.")
736
771
add_parser.add_argument('type', choices=['robot', 'sensor', 'actuator'],
737
772
help="the type of component you want to add.")
738
773
add_parser.add_argument('name', default="", help="the name of the new component.")
0 commit comments