Example #1
0
def merge_into_workspace(workspace, uris):
    try:
        from wstool.multiproject_cli import prompt_merge
        from wstool.multiproject_cmd import cmd_persist_config, cmd_install_or_update, get_config
    except ImportError:
        sys.stderr.write(
            "Cannot import wstool libraries. Did you source setup.{sh,bash,zsh}?\n"
        )
        sys.exit(os.EX_UNAVAILABLE)

    rosinstall_name = '.rosinstall'
    rosinstall_path = path.join(workspace, 'src')
    if not path.isdir(rosinstall_path):
        sys.stderr.write("%s is not a valid workspace\n" % workspace)
        sys.exit(1)

    if not path.exists(path.join(rosinstall_path, rosinstall_name)):
        with file(path.join(rosinstall_path, rosinstall_name), 'w') as f:
            f.write('\n')

    (newconfig, _) = prompt_merge(rosinstall_path,
                                  additional_uris=uris,
                                  additional_specs=[],
                                  confirmed=True,
                                  config_filename=rosinstall_name)

    if newconfig:
        cmd_persist_config(newconfig, rosinstall_name)
        cmd_install_or_update(newconfig, verbose=True)
    else:
        config = get_config(rosinstall_path, config_filename=rosinstall_name)
        cmd_install_or_update(config, verbose=True)
Example #2
0
    def cmd_update(self, target_path, argv, config=None):
        parser = OptionParser(usage="usage: %s update [localname]*" % self.progname,
                              formatter=IndentedHelpFormatterWithNL(),
                              description=__MULTIPRO_CMD_DICT__["update"] + """

This command calls the SCM provider to pull changes from remote to
your local filesystem. In case the url has changed, the command will
ask whether to delete or backup the folder.

Examples:
$ %(progname)s update -t ~/fuerte
$ %(progname)s update robot_model geometry
""" % {'progname': self.progname},
                              epilog="See: http://www.ros.org/wiki/rosinstall for details\n")
        parser.add_option("--delete-changed-uris", dest="delete_changed",
                          default=False,
                          help="Delete the local copy of a directory before changing uri.",
                          action="store_true")
        parser.add_option("--abort-changed-uris", dest="abort_changed",
                          default=False,
                          help="Abort if changed uri detected",
                          action="store_true")
        parser.add_option("--continue-on-error", dest="robust",
                          default=False,
                          help="Continue despite checkout errors",
                          action="store_true")
        parser.add_option("--backup-changed-uris", dest="backup_changed",
                          default='',
                          help="backup the local copy of a directory before changing uri to this directory.",
                          action="store")
        parser.add_option("-m", "--timeout", dest="timeout",
                          default=None,
                          help="How long to wait for each repo before failing [seconds]",
                          action="store", type=float)
        parser.add_option("-j", "--parallel", dest="jobs",
                          default=1,
                          help="How many parallel threads to use for installing",
                          action="store")
        parser.add_option("-v", "--verbose", dest="verbose",
                          default=False,
                          help="Whether to print out more information",
                          action="store_true")
        # -t option required here for help but used one layer above, see cli_common
        parser.add_option("-t", "--target-workspace", dest="workspace",
                          default=None,
                          help="which workspace to use",
                          action="store")
        (options, args) = parser.parse_args(argv)

        if config is None:
            config = multiproject_cmd.get_config(
                target_path,
                additional_uris=[],
                config_filename=self.config_filename)
        elif config.get_base_path() != target_path:
            raise MultiProjectException("Config path does not match %s %s " % (
                config.get_base_path(),
                target_path))
        success = True
        mode = _get_mode_from_options(parser, options)
        if args == []:
            # None means no filter, [] means filter all
            args = None
        if success:
            install_success = multiproject_cmd.cmd_install_or_update(
                config,
                localnames=args,
                backup_path=options.backup_changed,
                mode=mode,
                robust=options.robust,
                num_threads=int(options.jobs),
                timeout=options.timeout,
                verbose=options.verbose)
            if install_success or options.robust:
                return 0
        return 1
Example #3
0
    def cmd_init(self, argv):
        if self.config_filename is None:
            print('Error: Bug: config filename required for init')
            return 1
        parser = OptionParser(
            usage="""usage: %s init [TARGET_PATH [SOURCE_PATH]]?""" % self.progname,
            formatter=IndentedHelpFormatterWithNL(),
            description=__MULTIPRO_CMD_DICT__["init"] + """

%(prog)s init does the following:
  1. Reads folder/file/web-uri SOURCE_PATH looking for a rosinstall yaml
  2. Creates new %(cfg_file)s file at TARGET-PATH

SOURCE_PATH can e.g. be a web uri or a rosinstall file with vcs entries only
If PATH is not given, uses current dir.

Examples:
$ %(prog)s init ~/fuerte /opt/ros/fuerte
""" % {'cfg_file': self.config_filename, 'prog': self.progname},
                              epilog="See: http://www.ros.org/wiki/rosinstall for details\n")
        parser.add_option("--continue-on-error", dest="robust", default=False,
                          help="Continue despite checkout errors",
                          action="store_true")
        parser.add_option("-j", "--parallel", dest="jobs", default=1,
                          help="How many parallel threads to use for installing",
                          action="store")
        (options, args) = parser.parse_args(argv)
        if len(args) < 1:
            target_path = '.'
        else:
            target_path = args[0]

        if not os.path.isdir(target_path):
            if not os.path.exists(target_path):
                os.mkdir(target_path)
            else:
                print('Error: Cannot create in target path %s ' % target_path)

        if os.path.exists(os.path.join(target_path, self.config_filename)):
            print('Error: There already is a workspace config file %s at "%s". Use %s install/modify.' %
                  (self.config_filename, target_path, self.progname))
            return 1
        if len(args) > 2:
            parser.error('Too many arguments')

        if len(args) == 2:
            print('Using initial elements from: %s' % args[1])
            config_uris = [args[1]]
        else:
            config_uris = []

        config = multiproject_cmd.get_config(
            basepath=target_path,
            additional_uris=config_uris,
            # catkin workspaces have no resaonable wstool chaining semantics
            # config_filename=self.config_filename
            )
        if config_uris and len(config.get_config_elements()) == 0:
            sys.stderr.write('WARNING: Not using any element from %s\n' % config_uris[0])
        for element in config.get_config_elements():
            if not element.is_vcs_element():
                raise MultiProjectException("wstool does not allow elements without vcs information. %s" % element)

        # includes ROS specific files

        print("Writing %s" % os.path.join(config.get_base_path(), self.config_filename))
        self.config_generator(config, self.config_filename, get_header(self.progname))

        ## install or update each element
        install_success = multiproject_cmd.cmd_install_or_update(
            config,
            robust=False,
            num_threads=int(options.jobs))

        if not install_success:
            print("Warning: installation encountered errors, but --continue-on-error was requested.  Look above for warnings.")
        print("\nupdate complete.")
        return 0
Example #4
0
def rosinstall_main(argv):
    if len(argv) < 2:
        usage()
    args = argv[1:]
    parser = OptionParser(
        usage=
        "usage: rosinstall [OPTIONS] INSTALL_PATH [ROSINSTALL FILES OR DIRECTORIES]\n\n\
rosinstall does the following:\n\
  1. Merges all URIs into new or existing .rosinstall file at PATH\n\
  2. Checks out or updates all version controlled URIs\n\
  3. If ros stack is installed from source, calls rosmake after checkout or updates.\n\
  4. Generates/overwrites updated setup files\n\n\
If running with --catkin mode:\
  1. Merges all URIs into new or existing .rosinstall file at PATH\n\
  2. Checks out or updates all version controlled URIs\n\
  4. Generates/overwrites updated setup files and creates CMakeLists.txt at the root.\n\n\
URIs can be web urls to remote .rosinstall files, local .rosinstall files,\n\
git, svn, bzr, hg URIs, or other (local directories)\n\
Later URIs will shadow packages of earlier URIs.\n",
        epilog="See: http://www.ros.org/wiki/rosinstall for details\n")
    parser.add_option("-c",
                      "--catkin",
                      dest="catkin",
                      default=False,
                      help="Declare this is a catkin build.",
                      action="store_true")
    parser.add_option(
        "--cmake-prefix-path",
        dest="catkinpp",
        default=None,
        help="Where to set the CMAKE_PREFIX_PATH, implies --catkin",
        action="store")
    parser.add_option("--version",
                      dest="version",
                      default=False,
                      help="display version information",
                      action="store_true")
    parser.add_option("--verbose",
                      dest="verbose",
                      default=False,
                      help="display more information",
                      action="store_true")
    parser.add_option("-n",
                      "--nobuild",
                      dest="nobuild",
                      default=False,
                      help="skip the build step for the ROS stack",
                      action="store_true")
    parser.add_option("--rosdep-yes",
                      dest="rosdep_yes",
                      default=False,
                      help="Pass through --rosdep-yes to rosmake",
                      action="store_true")
    parser.add_option("--continue-on-error",
                      dest="robust",
                      default=False,
                      help="Continue despite checkout errors",
                      action="store_true")
    parser.add_option(
        "--delete-changed-uris",
        dest="delete_changed",
        default=False,
        help="Delete the local copy of a directory before changing uri.",
        action="store_true")
    parser.add_option("--abort-changed-uris",
                      dest="abort_changed",
                      default=False,
                      help="Abort if changed uri detected",
                      action="store_true")
    parser.add_option(
        "--backup-changed-uris",
        dest="backup_changed",
        default='',
        help=
        "backup the local copy of a directory before changing uri to this directory.",
        action="store")
    parser.add_option("--diff",
                      dest="vcs_diff",
                      default=False,
                      help="shows a combined diff over all SCM entries",
                      action="store_true")
    parser.add_option(
        "--status",
        dest="vcs_status",
        default=False,
        help="shows a combined status command over all SCM entries",
        action="store_true")
    parser.add_option(
        "--status-untracked",
        dest="vcs_status_untracked",
        default=False,
        help=
        "shows a combined status command over all SCM entries, also showing untracked files",
        action="store_true")
    parser.add_option("-j",
                      "--parallel",
                      dest="jobs",
                      default=1,
                      help="How many parallel threads to use for installing",
                      action="store")
    parser.add_option("--generate-versioned-rosinstall",
                      dest="generate_versioned",
                      default=None,
                      help="generate a versioned rosinstall file",
                      action="store")
    (options, args) = parser.parse_args(args)

    if options.version:
        print("rosinstall %s\n%s" %
              (rosinstall.__version__.version, multiproject_cmd.cmd_version()))
        sys.exit(0)

    if len(args) < 1:
        parser.error("rosinstall requires at least 1 argument")

    mode = 'prompt'
    if options.delete_changed:
        mode = 'delete'
    if options.abort_changed:
        if mode == 'delete':
            parser.error(
                "delete-changed-uris is mutually exclusive with abort-changed-uris"
            )
        mode = 'abort'
    if options.backup_changed != '':
        if mode == 'delete':
            parser.error(
                "delete-changed-uris is mutually exclusive with backup-changed-uris"
            )
        if mode == 'abort':
            parser.error(
                "abort-changed-uris is mutually exclusive with backup-changed-uris"
            )
        mode = 'backup'

    # Catkin must be enabled if catkinpp is set
    if options.catkinpp:
        options.catkin = True

    # Get the path to the rosinstall
    options.path = os.path.abspath(args[0])

    config_uris = args[1:]

    config = multiproject_cmd.get_config(basepath=options.path,
                                         additional_uris=config_uris,
                                         config_filename=ROSINSTALL_FILENAME)

    if options.generate_versioned:
        filename = os.path.abspath(options.generate_versioned)
        source_aggregate = multiproject_cmd.cmd_snapshot(config)
        with open(filename, 'w') as fhand:
            fhand.write(yaml.safe_dump(source_aggregate))
        print("Saved versioned rosinstall of current directory %s to %s" %
              (options.path, filename))
        return True

    if options.vcs_diff:
        difflist = multiproject_cmd.cmd_diff(config)
        alldiff = []
        for entrydiff in difflist:
            if entrydiff['diff'] is not None and entrydiff['diff'] != '':
                alldiff.append(entrydiff['diff'])
        print('\n'.join(alldiff))
        return True

    if options.vcs_status or options.vcs_status_untracked:
        statuslist = multiproject_cmd.cmd_status(
            config, untracked=options.vcs_status_untracked)
        allstatus = ""
        for entrystatus in statuslist:
            if entrystatus['status'] is not None:
                allstatus += entrystatus['status']
        print(allstatus, end='')
        return True

    print("rosinstall operating on", options.path,
          "from specifications in rosinstall files ", ", ".join(config_uris))

    # includes ROS specific files
    print("(Over-)Writing %s" %
          os.path.join(options.path, ROSINSTALL_FILENAME))
    if (os.path.isfile(os.path.join(options.path, ROSINSTALL_FILENAME))):
        shutil.move(os.path.join(options.path, ROSINSTALL_FILENAME),
                    "%s.bak" % os.path.join(options.path, ROSINSTALL_FILENAME))
    rosinstall_cmd.cmd_persist_config(config)

    ## install or update each element
    install_success = multiproject_cmd.cmd_install_or_update(
        config,
        backup_path=options.backup_changed,
        mode=mode,
        robust=options.robust,
        num_threads=int(options.jobs),
        verbose=options.verbose)

    rosinstall_cmd.cmd_generate_ros_files(config, options.path,
                                          options.nobuild, options.rosdep_yes,
                                          options.catkin, options.catkinpp)

    if not install_success:
        print(
            "Warning: installation encountered errors, but --continue-on-error was requested.    Look above for warnings."
        )

    print("\nrosinstall update complete.")
    if (options.catkin is False and options.catkinpp is None):

        print(
            "\n\nNow, type 'source %s/setup.bash' to set up your environment.\nAdd that to the bottom of your ~/.bashrc to set it up every time.\n\nIf you are not using bash please see http://www.ros.org/wiki/rosinstall/NonBashShells "
            % os.path.abspath(options.path))
    return True
Example #5
0
 def cmd_add_stack(self, target_path, argv):
     parser = OptionParser(
         usage="usage: rosws add-stack [PATH] localname",
         epilog="See: http://wiki.ros.org/rosinstall for details\n")
     parser.add_option(
         "-N",
         "--non-recursive",
         dest="norecurse",
         default=False,
         help="don't change configuration for dependent stacks",
         action="store_true")
     parser.add_option(
         "--released",
         dest="released",
         default=False,
         help="Pull stack from release tag instead of development branch",
         action="store_true")
     parser.add_option("--continue-on-error",
                       dest="robust",
                       default=False,
                       help="Continue despite checkout errors",
                       action="store_true")
     parser.add_option(
         "--delete-changed-uris",
         dest="delete_changed",
         default=False,
         help="Delete the local copy of a directory before changing uri.",
         action="store_true")
     parser.add_option("--abort-changed-uris",
                       dest="abort_changed",
                       default=False,
                       help="Abort if changed uri detected",
                       action="store_true")
     parser.add_option(
         "--backup-changed-uris",
         dest="backup_changed",
         default='',
         help=
         "backup the local copy of a directory before changing uri to this directory.",
         action="store")
     (options, args) = parser.parse_args(argv)
     mode = 'prompt'
     if options.delete_changed:
         mode = 'delete'
     if options.abort_changed:
         if mode == 'delete':
             parser.error(
                 "delete-changed-uris is mutually exclusive with abort-changed-uris"
             )
         mode = 'abort'
     if options.backup_changed != '':
         if mode == 'delete':
             parser.error(
                 "delete-changed-uris is mutually exclusive with backup-changed-uris"
             )
         if mode == 'abort':
             parser.error(
                 "abort-changed-uris is mutually exclusive with backup-changed-uris"
             )
         mode = 'backup'
     if len(args) < 1:
         print("Error: Too few arguments.")
         print(parser.usage)
         return -1
     if len(args) > 1:
         print("Error: Too many arguments.")
         print(parser.usage)
         return -1
     stack = args[0]
     config = get_config(target_path, [],
                         config_filename=self.config_filename)
     if cmd_add_stack(config,
                      stack,
                      released=options.released,
                      recurse=(not options.norecurse)) is True:
         cmd_persist_config(config, self.config_filename)
         # install or update each element
         install_success = cmd_install_or_update(
             config,
             backup_path=options.backup_changed,
             mode=mode,
             robust=options.robust)
         if install_success:
             return 0
     return 1
Example #6
0
 def cmd_add_stack(self, target_path, argv):
     parser = OptionParser(usage="usage: rosws add-stack [PATH] localname",
                           epilog="See: http://wiki.ros.org/rosinstall for details\n")
     parser.add_option("-N", "--non-recursive", dest="norecurse",
                       default=False,
                       help="don't change configuration for dependent stacks",
                       action="store_true")
     parser.add_option("--released", dest="released",
                       default=False,
                       help="Pull stack from release tag instead of development branch",
                       action="store_true")
     parser.add_option("--continue-on-error", dest="robust",
                       default=False,
                       help="Continue despite checkout errors",
                       action="store_true")
     parser.add_option("--delete-changed-uris", dest="delete_changed",
                       default=False,
                       help="Delete the local copy of a directory before changing uri.",
                       action="store_true")
     parser.add_option("--abort-changed-uris", dest="abort_changed",
                       default=False,
                       help="Abort if changed uri detected",
                       action="store_true")
     parser.add_option("--backup-changed-uris", dest="backup_changed",
                       default='',
                       help="backup the local copy of a directory before changing uri to this directory.",
                       action="store")
     (options, args) = parser.parse_args(argv)
     mode = 'prompt'
     if options.delete_changed:
         mode = 'delete'
     if options.abort_changed:
         if mode == 'delete':
             parser.error(
                 "delete-changed-uris is mutually exclusive with abort-changed-uris")
         mode = 'abort'
     if options.backup_changed != '':
         if mode == 'delete':
             parser.error(
                 "delete-changed-uris is mutually exclusive with backup-changed-uris")
         if mode == 'abort':
             parser.error(
                 "abort-changed-uris is mutually exclusive with backup-changed-uris")
         mode = 'backup'
     if len(args) < 1:
         print("Error: Too few arguments.")
         print(parser.usage)
         return -1
     if len(args) > 1:
         print("Error: Too many arguments.")
         print(parser.usage)
         return -1
     stack = args[0]
     config = get_config(
         target_path, [], config_filename=self.config_filename)
     if cmd_add_stack(config,
                      stack,
                      released=options.released,
                      recurse=(not options.norecurse)) is True:
         cmd_persist_config(config, self.config_filename)
         # install or update each element
         install_success = cmd_install_or_update(
             config,
             backup_path=options.backup_changed,
             mode=mode,
             robust=options.robust)
         if install_success:
             return 0
     return 1
Example #7
0
    def cmd_init(self, argv):
        if self.config_filename is None:
            print('Error: Bug: config filename required for init')
            return 1
        parser = OptionParser(
            usage="""usage: %s init [TARGET_PATH [SOURCE_PATH]]?""" %
            self.progname,
            formatter=IndentedHelpFormatterWithNL(),
            description=__MULTIPRO_CMD_DICT__["init"] + """

%(prog)s init does the following:
  1. Reads folder/file/web-uri SOURCE_PATH looking for a rosinstall yaml
  2. Creates new %(cfg_file)s file at TARGET-PATH
  3. Generates ROS setup files

SOURCE_PATH can e.g. be a folder like /opt/ros/electric
If PATH is not given, uses current dir.

Examples:
$ %(prog)s init ~/fuerte /opt/ros/fuerte
""" % {
                'cfg_file': self.config_filename,
                'prog': self.progname
            },
            epilog="See: http://wiki.ros.org/rosinstall for details\n")
        parser.add_option("-c",
                          "--catkin",
                          dest="catkin",
                          default=False,
                          help="Declare this is a catkin build.",
                          action="store_true")
        parser.add_option("--cmake-prefix-path",
                          dest="catkinpp",
                          default=None,
                          help="Where to set the CMAKE_PREFIX_PATH",
                          action="store")
        parser.add_option("--continue-on-error",
                          dest="robust",
                          default=False,
                          help="Continue despite checkout errors",
                          action="store_true")
        parser.add_option(
            "-j",
            "--parallel",
            dest="jobs",
            default=1,
            help="How many parallel threads to use for installing",
            action="store")
        (options, args) = parser.parse_args(argv)
        if len(args) < 1:
            target_path = '.'
        else:
            target_path = args[0]

        if not os.path.isdir(target_path):
            if not os.path.exists(target_path):
                os.mkdir(target_path)
            else:
                print('Error: Cannot create in target path %s ' % target_path)

        if os.path.exists(os.path.join(target_path, self.config_filename)):
            print(
                'Error: There already is a workspace config file %s at "%s". Use %s install/modify.'
                % (self.config_filename, target_path, self.progname))
            return 1
        if len(args) > 2:
            parser.error('Too many arguments')
        config_uris = []
        if len(args) == 2:
            config_uris.append(args[1])
        if len(config_uris) > 0:
            print('Using ROS_ROOT: %s' % config_uris[0])

        config = get_config(basepath=target_path,
                            additional_uris=config_uris,
                            config_filename=self.config_filename)

        # includes ROS specific files

        print("Writing %s" %
              os.path.join(config.get_base_path(), self.config_filename))
        rosinstall_cmd.cmd_persist_config(config)

        ## install or update each element
        install_success = cmd_install_or_update(config,
                                                robust=False,
                                                num_threads=int(options.jobs))

        rosinstall_cmd.cmd_generate_ros_files(config,
                                              target_path,
                                              nobuild=True,
                                              rosdep_yes=False,
                                              catkin=options.catkin,
                                              catkinpp=options.catkinpp,
                                              no_ros_allowed=True)

        if not install_success:
            print(
                "Warning: installation encountered errors, but --continue-on-error was requested.  Look above for warnings."
            )
        print("\nrosinstall update complete.")
        if (options.catkin is False and options.catkinpp is None):
            print(
                "\nType 'source %s/setup.bash' to change into this environment. Add that source command to the bottom of your ~/.bashrc to set it up every time you log in.\n\nIf you are not using bash please see http://wiki.ros.org/rosinstall/NonBashShells "
                % os.path.abspath(target_path))
        return 0
Example #8
0
    def cmd_init(self, argv):
        if self.config_filename is None:
            print('Error: Bug: config filename required for init')
            return 1
        parser = OptionParser(
            usage="""usage: %s init [TARGET_PATH [SOURCE_PATH]]?""" % self.progname,
            formatter=IndentedHelpFormatterWithNL(),
            description=__MULTIPRO_CMD_DICT__["init"] + """

%(prog)s init does the following:
  1. Reads folder/file/web-uri SOURCE_PATH looking for a rosinstall yaml
  2. Creates new %(cfg_file)s file at TARGET-PATH
  3. Generates ROS setup files

SOURCE_PATH can e.g. be a folder like /opt/ros/electric
If PATH is not given, uses current dir.

Examples:
$ %(prog)s init ~/fuerte /opt/ros/fuerte
""" % {'cfg_file': self.config_filename, 'prog': self.progname},
            epilog="See: http://wiki.ros.org/rosinstall for details\n")
        parser.add_option("-c", "--catkin", dest="catkin", default=False,
                          help="Declare this is a catkin build.",
                          action="store_true")
        parser.add_option("--cmake-prefix-path", dest="catkinpp", default=None,
                          help="Where to set the CMAKE_PREFIX_PATH",
                          action="store")
        parser.add_option("--continue-on-error", dest="robust", default=False,
                          help="Continue despite checkout errors",
                          action="store_true")
        parser.add_option("-j", "--parallel", dest="jobs", default=1,
                          help="How many parallel threads to use for installing",
                          action="store")
        (options, args) = parser.parse_args(argv)
        if len(args) < 1:
            target_path = '.'
        else:
            target_path = args[0]

        if not os.path.isdir(target_path):
            if not os.path.exists(target_path):
                os.mkdir(target_path)
            else:
                print('Error: Cannot create in target path %s ' % target_path)

        if os.path.exists(os.path.join(target_path, self.config_filename)):
            print('Error: There already is a workspace config file %s at "%s". Use %s install/modify.' %
                  (self.config_filename, target_path, self.progname))
            return 1
        if len(args) > 2:
            parser.error('Too many arguments')
        config_uris = []
        if len(args) == 2:
            config_uris.append(args[1])
        if len(config_uris) > 0:
            print('Using ROS_ROOT: %s' % config_uris[0])

        config = get_config(basepath=target_path,
                            additional_uris=config_uris,
                            config_filename=self.config_filename)

        # includes ROS specific files

        print("Writing %s" % os.path.join(config.get_base_path(),
              self.config_filename))
        rosinstall_cmd.cmd_persist_config(config)

        ## install or update each element
        install_success = cmd_install_or_update(
            config,
            robust=False,
            num_threads=int(options.jobs))

        rosinstall_cmd.cmd_generate_ros_files(config,
                                              target_path,
                                              nobuild=True,
                                              rosdep_yes=False,
                                              catkin=options.catkin,
                                              catkinpp=options.catkinpp,
                                              no_ros_allowed=True)

        if not install_success:
            print("Warning: installation encountered errors, but --continue-on-error was requested.  Look above for warnings.")
        print("\nrosinstall update complete.")
        if (options.catkin is False
            and options.catkinpp is None):
            print("\nType 'source %s/setup.bash' to change into this environment. Add that source command to the bottom of your ~/.bashrc to set it up every time you log in.\n\nIf you are not using bash please see http://wiki.ros.org/rosinstall/NonBashShells " % os.path.abspath(target_path))
        return 0
Example #9
0
def rosinstall_main(argv):
    if len(argv) < 2:
        usage()
    args = argv[1:]
    parser = OptionParser(
        usage="usage: rosinstall [OPTIONS] INSTALL_PATH [ROSINSTALL FILES OR DIRECTORIES]\n\n\
rosinstall does the following:\n\
  1. Merges all URIs into new or existing .rosinstall file at PATH\n\
  2. Checks out or updates all version controlled URIs\n\
  3. If ros stack is installed from source, calls rosmake after checkout or updates.\n\
  4. Generates/overwrites updated setup files\n\n\
If running with --catkin mode:\
  1. Merges all URIs into new or existing .rosinstall file at PATH\n\
  2. Checks out or updates all version controlled URIs\n\
  4. Generates/overwrites updated setup files and creates CMakeLists.txt at the root.\n\n\
URIs can be web urls to remote .rosinstall files, local .rosinstall files,\n\
git, svn, bzr, hg URIs, or other (local directories)\n\
Later URIs will shadow packages of earlier URIs.\n",
        epilog="See: http://www.ros.org/wiki/rosinstall for details\n",
    )
    parser.add_option(
        "-c", "--catkin", dest="catkin", default=False, help="Declare this is a catkin build.", action="store_true"
    )
    parser.add_option(
        "--cmake-prefix-path",
        dest="catkinpp",
        default=None,
        help="Where to set the CMAKE_PREFIX_PATH, implies --catkin",
        action="store",
    )
    parser.add_option(
        "--version", dest="version", default=False, help="display version information", action="store_true"
    )
    parser.add_option("--verbose", dest="verbose", default=False, help="display more information", action="store_true")
    parser.add_option(
        "-n",
        "--nobuild",
        dest="nobuild",
        default=False,
        help="skip the build step for the ROS stack",
        action="store_true",
    )
    parser.add_option(
        "--rosdep-yes",
        dest="rosdep_yes",
        default=False,
        help="Pass through --rosdep-yes to rosmake",
        action="store_true",
    )
    parser.add_option(
        "--continue-on-error",
        dest="robust",
        default=False,
        help="Continue despite checkout errors",
        action="store_true",
    )
    parser.add_option(
        "--delete-changed-uris",
        dest="delete_changed",
        default=False,
        help="Delete the local copy of a directory before changing uri.",
        action="store_true",
    )
    parser.add_option(
        "--abort-changed-uris",
        dest="abort_changed",
        default=False,
        help="Abort if changed uri detected",
        action="store_true",
    )
    parser.add_option(
        "--backup-changed-uris",
        dest="backup_changed",
        default="",
        help="backup the local copy of a directory before changing uri to this directory.",
        action="store",
    )
    parser.add_option(
        "--diff", dest="vcs_diff", default=False, help="shows a combined diff over all SCM entries", action="store_true"
    )
    parser.add_option(
        "--status",
        dest="vcs_status",
        default=False,
        help="shows a combined status command over all SCM entries",
        action="store_true",
    )
    parser.add_option(
        "--status-untracked",
        dest="vcs_status_untracked",
        default=False,
        help="shows a combined status command over all SCM entries, also showing untracked files",
        action="store_true",
    )
    parser.add_option(
        "-j",
        "--parallel",
        dest="jobs",
        default=1,
        help="How many parallel threads to use for installing",
        action="store",
    )
    parser.add_option(
        "--generate-versioned-rosinstall",
        dest="generate_versioned",
        default=None,
        help="generate a versioned rosinstall file",
        action="store",
    )
    (options, args) = parser.parse_args(args)

    if options.version:
        print("rosinstall %s\n%s" % (rosinstall.__version__.version, multiproject_cmd.cmd_version()))
        sys.exit(0)

    if len(args) < 1:
        parser.error("rosinstall requires at least 1 argument")

    mode = "prompt"
    if options.delete_changed:
        mode = "delete"
    if options.abort_changed:
        if mode == "delete":
            parser.error("delete-changed-uris is mutually exclusive with abort-changed-uris")
        mode = "abort"
    if options.backup_changed != "":
        if mode == "delete":
            parser.error("delete-changed-uris is mutually exclusive with backup-changed-uris")
        if mode == "abort":
            parser.error("abort-changed-uris is mutually exclusive with backup-changed-uris")
        mode = "backup"

    # Catkin must be enabled if catkinpp is set
    if options.catkinpp:
        options.catkin = True

    # Get the path to the rosinstall
    options.path = os.path.abspath(args[0])

    config_uris = args[1:]

    config = multiproject_cmd.get_config(
        basepath=options.path, additional_uris=config_uris, config_filename=ROSINSTALL_FILENAME
    )

    if options.generate_versioned:
        filename = os.path.abspath(options.generate_versioned)
        source_aggregate = multiproject_cmd.cmd_snapshot(config)
        with open(filename, "w") as fhand:
            fhand.write(yaml.safe_dump(source_aggregate))
        print("Saved versioned rosinstall of current directory %s to %s" % (options.path, filename))
        return True

    if options.vcs_diff:
        difflist = multiproject_cmd.cmd_diff(config)
        alldiff = []
        for entrydiff in difflist:
            if entrydiff["diff"] is not None and entrydiff["diff"] != "":
                alldiff.append(entrydiff["diff"])
        print("\n".join(alldiff))
        return True

    if options.vcs_status or options.vcs_status_untracked:
        statuslist = multiproject_cmd.cmd_status(config, untracked=options.vcs_status_untracked)
        allstatus = ""
        for entrystatus in statuslist:
            if entrystatus["status"] is not None:
                allstatus += entrystatus["status"]
        print(allstatus, end="")
        return True

    print("rosinstall operating on", options.path, "from specifications in rosinstall files ", ", ".join(config_uris))

    # includes ROS specific files
    print("(Over-)Writing %s" % os.path.join(options.path, ROSINSTALL_FILENAME))
    if os.path.isfile(os.path.join(options.path, ROSINSTALL_FILENAME)):
        shutil.move(
            os.path.join(options.path, ROSINSTALL_FILENAME), "%s.bak" % os.path.join(options.path, ROSINSTALL_FILENAME)
        )
    rosinstall_cmd.cmd_persist_config(config)

    ## install or update each element
    install_success = multiproject_cmd.cmd_install_or_update(
        config,
        backup_path=options.backup_changed,
        mode=mode,
        robust=options.robust,
        num_threads=int(options.jobs),
        verbose=options.verbose,
    )

    rosinstall_cmd.cmd_generate_ros_files(
        config, options.path, options.nobuild, options.rosdep_yes, options.catkin, options.catkinpp
    )

    if not install_success:
        print(
            "Warning: installation encountered errors, but --continue-on-error was requested.    Look above for warnings."
        )

    print("\nrosinstall update complete.")
    if options.catkin is False and options.catkinpp is None:

        print(
            "\n\nNow, type 'source %s/setup.bash' to set up your environment.\nAdd that to the bottom of your ~/.bashrc to set it up every time.\n\nIf you are not using bash please see http://www.ros.org/wiki/rosinstall/NonBashShells "
            % os.path.abspath(options.path)
        )
    return True