예제 #1
0
def cmd_diff(config, localnames=None):
    """
    calls SCM diff for all SCM entries in config, relative to path

    :returns: List of dict {element: ConfigElement, diff: diffstring}
    :raises MultiProjectException: on plenty of errors
    """
    class DiffRetriever():

        def __init__(self, element, path):
            self.element = element
            self.path = path

        def do_work(self):
            return {'diff': self.element.get_diff(self.path)}

    path = config.get_base_path()
    elements = config.get_config_elements()
    work = DistributedWork(len(elements))
    elements = select_elements(config, localnames)
    for element in elements:
        if element.is_vcs_element():
            work.add_thread(DiffRetriever(element, path))
    outputs = work.run()
    return outputs
예제 #2
0
def cmd_snapshot(config, localnames=None):
    elements = select_elements(config, localnames)
    source_aggregate = []
    for element in elements:
        source = element.get_versioned_path_spec().get_legacy_yaml()
        source_aggregate.append(source)
    return source_aggregate
예제 #3
0
def cmd_snapshot(config, localnames=None):
    elements = select_elements(config, localnames)
    source_aggregate = []
    for element in elements:
        source = element.get_versioned_path_spec().get_legacy_yaml()
        source_aggregate.append(source)
    return source_aggregate
 def test_select_elements(self):
     self.assertEqual([], select_elements(None, None))
     mock1 = MockElement('foo', '/test/path1')
     mock2 = MockElement('bar', '/test/path2')
     mock3 = MockElement('baz', '/test/path3')
     class FakeConfig():
         def get_config_elements(self):
             return [mock1, mock2, mock3]
         def get_base_path(self):
             return '/foo/bar'
     self.assertEqual([mock1, mock2, mock3],
                      select_elements(FakeConfig(), None))
     self.assertEqual([mock2],
                      select_elements(FakeConfig(), ['bar']))
     self.assertEqual([mock1, mock2, mock3],
                      select_elements(FakeConfig(), ['/foo/bar']))
     self.assertRaises(MultiProjectException, select_elements, FakeConfig(), ['bum'])
     self.assertRaises(MultiProjectException, select_elements, FakeConfig(), ['foo', 'bum', 'bar'])
     self.assertRaises(MultiProjectException, select_elements, FakeConfig(), ['bu*'])
예제 #5
0
    def test_select_elements(self):
        self.assertEqual([], select_elements(None, None))
        mock1 = MockElement('foo', '/test/path1')
        mock2 = MockElement('bar', '/test/path2')
        mock3 = MockElement('baz', '/test/path3')

        class FakeConfig():
            def get_config_elements(self):
                return [mock1, mock2, mock3]

            def get_base_path(self):
                return '/foo/bar'
        self.assertEqual([mock1, mock2, mock3],
                         select_elements(FakeConfig(), None))
        self.assertEqual([mock2],
                         select_elements(FakeConfig(), ['bar']))
        self.assertEqual([mock1, mock2, mock3],
                         select_elements(FakeConfig(), ['/foo/bar']))
        self.assertRaises(MultiProjectException, select_elements, FakeConfig(), ['bum'])
        self.assertRaises(MultiProjectException, select_elements, FakeConfig(), ['foo', 'bum', 'bar'])
        self.assertRaises(MultiProjectException, select_elements, FakeConfig(), ['bu*'])
예제 #6
0
def cmd_status(config, localnames=None, untracked=False):
    """
    calls SCM status for all SCM entries in config, relative to path

    :returns: List of dict {element: ConfigElement, diff: diffstring}
    :param untracked: also show files not added to the SCM
    :raises MultiProjectException: on plenty of errors
    """
    class StatusRetriever():

        def __init__(self, element, path, untracked):
            self.element = element
            self.path = path
            self.untracked = untracked

        def do_work(self):
            path_spec = self.element.get_path_spec()
            scmtype = path_spec.get_scmtype()
            status = self.element.get_status(self.path, self.untracked)
            # align other scm output to svn
            columns = -1
            if scmtype == "git":
                columns = 3
            elif scmtype == "hg":
                columns = 2
            elif scmtype == "bzr":
                columns = 4
            if columns > -1 and status is not None:
                status_aligned = ''
                for line in status.splitlines():
                    status_aligned = "%s%s%s\n" % (status_aligned,
                                                 line[:columns].ljust(8),
                                                 line[columns:])
                status = status_aligned
            return {'status': status}

    path = config.get_base_path()
    # call SCM info in separate threads
    elements = config.get_config_elements()
    work = DistributedWork(len(elements))
    elements = select_elements(config, localnames)
    for element in elements:
        if element.is_vcs_element():
            work.add_thread(StatusRetriever(element, path, untracked))
    outputs = work.run()
    return outputs
예제 #7
0
def cmd_status(config, localnames=None, untracked=False):
    """
    calls SCM status for all SCM entries in config, relative to path

    :returns: List of dict {element: ConfigElement, diff: diffstring}
    :param untracked: also show files not added to the SCM
    :raises MultiProjectException: on plenty of errors
    """
    class StatusRetriever():
        def __init__(self, element, path, untracked):
            self.element = element
            self.path = path
            self.untracked = untracked

        def do_work(self):
            path_spec = self.element.get_path_spec()
            scmtype = path_spec.get_scmtype()
            status = self.element.get_status(self.path, self.untracked)
            # align other scm output to svn
            columns = -1
            if scmtype == "git":
                columns = 3
            elif scmtype == "hg":
                columns = 2
            elif scmtype == "bzr":
                columns = 4
            if columns > -1 and status is not None:
                status_aligned = ''
                for line in status.splitlines():
                    status_aligned = "%s%s%s\n" % (status_aligned,
                                                   line[:columns].ljust(8),
                                                   line[columns:])
                status = status_aligned
            return {'status': status}

    path = config.get_base_path()
    # call SCM info in separate threads
    elements = config.get_config_elements()
    work = DistributedWork(len(elements))
    elements = select_elements(config, localnames)
    for element in elements:
        if element.is_vcs_element():
            work.add_thread(StatusRetriever(element, path, untracked))
    outputs = work.run()
    return outputs
예제 #8
0
def get_info_table_raw_csv(config, properties, localnames):
    """
    returns raw data without decorations in comma-separated value format.
    allows to select properties.
    Given a config, collects all elements, and prints a line of each,
    with selected properties in the output

    :param properties: list of property ids to display
    :param localnames: which config elements to show
    .return: list of str, each a csv line
    """
    lookup_required = False
    for attr in properties:
        if not attr in ONLY_OPTION_VALID_ATTRS:
            parser.error("Invalid --only option '%s', valids are %s" %
                         (attr, ONLY_OPTION_VALID_ATTRS))
        if attr in ['cur_revision', 'cur_uri', 'revision']:
            lookup_required = True
    elements = select_elements(config, localnames)
    result=[]
    for element in elements:
        if lookup_required and element.is_vcs_element():
            spec = element.get_versioned_path_spec()
        else:
            spec = element.get_path_spec()
        output = []
        for attr in properties:
            if 'localname' == attr:
                output.append(spec.get_local_name() or '')
            if 'path' == attr:
                output.append(spec.get_path() or '')
            if 'scmtype' == attr:
                output.append(spec.get_scmtype() or '')
            if 'uri' == attr:
                output.append(spec.get_uri() or '')
            if 'version' == attr:
                output.append(spec.get_version() or '')
            if 'revision' == attr:
                output.append(spec.get_revision() or '')
            if 'cur_uri' == attr:
                output.append(spec.get_curr_uri() or '')
            if 'cur_revision' == attr:
                output.append(spec.get_current_revision() or '')
        result.append(','.join(output))
    return result
예제 #9
0
def get_info_table_raw_csv(config, properties, localnames):
    """
    returns raw data without decorations in comma-separated value format.
    allows to select properties.
    Given a config, collects all elements, and prints a line of each,
    with selected properties in the output

    :param properties: list of property ids to display
    :param localnames: which config elements to show
    .return: list of str, each a csv line
    """
    lookup_required = False
    for attr in properties:
        if not attr in ONLY_OPTION_VALID_ATTRS:
            parser.error("Invalid --only option '%s', valids are %s" %
                         (attr, ONLY_OPTION_VALID_ATTRS))
        if attr in ['cur_revision', 'cur_uri', 'revision']:
            lookup_required = True
    elements = select_elements(config, localnames)
    result = []
    for element in elements:
        if lookup_required and element.is_vcs_element():
            spec = element.get_versioned_path_spec()
        else:
            spec = element.get_path_spec()
        output = []
        for attr in properties:
            if 'localname' == attr:
                output.append(spec.get_local_name() or '')
            if 'path' == attr:
                output.append(spec.get_path() or '')
            if 'scmtype' == attr:
                output.append(spec.get_scmtype() or '')
            if 'uri' == attr:
                output.append(spec.get_uri() or '')
            if 'version' == attr:
                output.append(spec.get_version() or '')
            if 'revision' == attr:
                output.append(spec.get_revision() or '')
            if 'cur_uri' == attr:
                output.append(spec.get_curr_uri() or '')
            if 'cur_revision' == attr:
                output.append(spec.get_current_revision() or '')
        result.append(','.join(output))
    return result
예제 #10
0
    def cmd_remove(self, target_path, argv, config=None):
        parser = OptionParser(
            usage="usage: %s remove [localname]*" % self.progname,
            formatter=IndentedHelpFormatterWithNL(),
            description=__MULTIPRO_CMD_DICT__["remove"] + """
The command removes entries from your configuration file, it does not affect your filesystem.
""",
            epilog="See: http://www.ros.org/wiki/rosinstall for details\n")
        (_, args) = parser.parse_args(argv)
        if len(args) < 1:
            print("Error: Too few arguments.")
            print(parser.usage)
            return -1

        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
        elements = select_elements(config, args)
        for element in elements:
            if not config.remove_element(element.get_local_name()):
                success = False
                print(
                    "Bug: No such element %s in config, aborting without changes"
                    % (element.get_local_name()))
                break
        if success:
            print("Overwriting %s" %
                  os.path.join(config.get_base_path(), self.config_filename))
            shutil.move(
                os.path.join(config.get_base_path(),
                             self.config_filename), "%s.bak" %
                os.path.join(config.get_base_path(), self.config_filename))
            self.config_generator(config, self.config_filename)
            print("Removed entries %s" % args)

        return 0
예제 #11
0
    def cmd_remove(self, target_path, argv, config=None):
        parser = OptionParser(usage="usage: %s remove [localname]*" % self.progname,
                              formatter=IndentedHelpFormatterWithNL(),
                              description=__MULTIPRO_CMD_DICT__["remove"] + """
The command removes entries from your configuration file, it does not affect your filesystem.
""",
                              epilog="See: http://www.ros.org/wiki/rosinstall for details\n")
        (_, args) = parser.parse_args(argv)
        if len(args) < 1:
            print("Error: Too few arguments.")
            print(parser.usage)
            return -1

        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
        elements = select_elements(config, args)
        for element in elements:
            if not config.remove_element(element.get_local_name()):
                success = False
                print("Bug: No such element %s in config, aborting without changes" %
                      (element.get_local_name()))
                break
        if success:
            print("Overwriting %s" % os.path.join(config.get_base_path(),
                                                  self.config_filename))
            shutil.move(os.path.join(config.get_base_path(),
                                     self.config_filename),
                        "%s.bak" % os.path.join(config.get_base_path(),
                                                self.config_filename))
            self.config_generator(config, self.config_filename)
            print("Removed entries %s" % args)

        return 0
예제 #12
0
def cmd_snapshot(config, localnames=None):
    elements = select_elements(config, localnames)
    source_aggregate = []
    for element in elements:
        if element.is_vcs_element():
            spec = element.get_versioned_path_spec()
            export_spec = PathSpec(
                local_name=spec.get_local_name(),
                scmtype=spec.get_scmtype(),
                uri=spec.get_uri() or spec.get_curr_uri(),
                version=(spec.get_current_revision() or
                         spec.get_revision() or
                         spec.get_version()),
                path=spec.get_path())
            if not export_spec.get_version():
                sys.stderr.write('Warning, discarding non-vcs element %s\n' % element.get_local_name())
            source = export_spec.get_legacy_yaml()
            source_aggregate.append(source)
        else:
            sys.stderr.write('Warning, discarding non-vcs element %s\n' % element.get_local_name())
    return source_aggregate
예제 #13
0
def cmd_snapshot(config, localnames=None):
    elements = select_elements(config, localnames)
    source_aggregate = []
    for element in elements:
        if element.is_vcs_element():
            spec = element.get_versioned_path_spec()
            export_spec = PathSpec(local_name=spec.get_local_name(),
                                   scmtype=spec.get_scmtype(),
                                   uri=spec.get_uri() or spec.get_curr_uri(),
                                   version=(spec.get_current_revision()
                                            or spec.get_revision()
                                            or spec.get_version()),
                                   path=spec.get_path())
            if not export_spec.get_version():
                sys.stderr.write('Warning, discarding non-vcs element %s\n' %
                                 element.get_local_name())
            source = export_spec.get_legacy_yaml()
            source_aggregate.append(source)
        else:
            sys.stderr.write('Warning, discarding non-vcs element %s\n' %
                             element.get_local_name())
    return source_aggregate
예제 #14
0
def cmd_diff(config, localnames=None):
    """
    calls SCM diff for all SCM entries in config, relative to path

    :returns: List of dict {element: ConfigElement, diff: diffstring}
    :raises MultiProjectException: on plenty of errors
    """
    class DiffRetriever():
        def __init__(self, element, path):
            self.element = element
            self.path = path

        def do_work(self):
            return {'diff': self.element.get_diff(self.path)}

    path = config.get_base_path()
    elements = config.get_config_elements()
    work = DistributedWork(len(elements))
    elements = select_elements(config, localnames)
    for element in elements:
        if element.is_vcs_element():
            work.add_thread(DiffRetriever(element, path))
    outputs = work.run()
    return outputs
예제 #15
0
def cmd_info(config, localnames=None):
    """This function compares what should be (config_file) with what is
    (directories) and returns a list of dictionary giving each local
    path and all the state information about it available.
    """
    class InfoRetriever():
        def __init__(self, element, path):
            self.element = element
            self.path = path

        def do_work(self):
            localname = ""
            scm = None
            uri = ""
            curr_uri = None
            exists = False
            version = ""  # what is given in config file
            modified = ""
            actualversion = ""  # revision number of version
            specversion = ""  # actual revision number
            localname = self.element.get_local_name()
            path = self.element.get_path() or localname

            if localname is None or localname == "":
                raise MultiProjectException(
                    "Missing local-name in element: %s" % self.element)
            abs_path = normabspath(path, self.path)
            if (os.path.exists(abs_path)):
                exists = True
            if self.element.is_vcs_element():
                if not exists:
                    path_spec = self.element.get_path_spec()
                    version = path_spec.get_version()
                else:
                    path_spec = self.element.get_versioned_path_spec()
                    version = path_spec.get_version()
                    curr_uri = path_spec.get_curr_uri()
                    status = self.element.get_status(self.path)
                    if (status is not None and status.strip() != ''):
                        modified = True
                    specversion = path_spec.get_revision()
                    if (version is not None and version.strip() != '' and
                        (specversion is None or specversion.strip() == '')):

                        specversion = '"%s"' % version
                    actualversion = path_spec.get_current_revision()
                scm = path_spec.get_scmtype()
                uri = path_spec.get_uri()
            return {
                'scm': scm,
                'exists': exists,
                'localname': localname,
                'path': path,
                'uri': uri,
                'curr_uri': curr_uri,
                'version': version,
                'specversion': specversion,
                'actualversion': actualversion,
                'modified': modified,
                'properties': self.element.get_properties()
            }

    path = config.get_base_path()
    # call SCM info in separate threads
    elements = config.get_config_elements()
    work = DistributedWork(len(elements))
    elements = select_elements(config, localnames)
    for element in elements:
        if element.get_properties(
        ) is None or not 'setup-file' in element.get_properties():
            work.add_thread(InfoRetriever(element, path))
    outputs = work.run()
    return outputs
예제 #16
0
def cmd_install_or_update(config,
                          backup_path=None,
                          mode='abort',
                          robust=False,
                          localnames=None,
                          num_threads=1,
                          verbose=False):
    """
    performs many things, generally attempting to make
    the local filesystem look like what the config specifies,
    pulling from remote sources the most recent changes.

    The command may have stdin user interaction (TODO abstract)

    :param backup_path: if and where to backup trees before deleting them
    :param robust: proceed to next element even when one element fails
    :returns: True on Success
    :raises MultiProjectException: on plenty of errors
    """
    success = True
    if not os.path.exists(config.get_base_path()):
        os.mkdir(config.get_base_path())
    # Prepare install operation check filesystem and ask user
    preparation_reports = []
    elements = select_elements(config, localnames)
    for tree_el in elements:
        abs_backup_path = None
        if backup_path is not None:
            abs_backup_path = os.path.join(config.get_base_path(), backup_path)
        try:
            preparation_report = tree_el.prepare_install(
                backup_path=abs_backup_path, arg_mode=mode, robust=robust)
            if preparation_report is not None:
                if preparation_report.abort:
                    raise MultiProjectException(
                        "Aborting install because of %s" %
                        preparation_report.error)
                if not preparation_report.skip:
                    preparation_reports.append(preparation_report)
                else:
                    if preparation_report.error is not None:
                        print("Skipping install of %s because: %s" % (
                            preparation_report.config_element.get_local_name(),
                            preparation_report.error))
        except MultiProjectException as exc:
            fail_str = "Failed to install tree '%s'\n %s" % (
                tree_el.get_path(), exc)
            if robust:
                success = False
                print("Continuing despite %s" % fail_str)
            else:
                raise MultiProjectException(fail_str)

    class Installer():
        def __init__(self, report):
            self.element = report.config_element
            self.report = report

        def do_work(self):
            self.element.install(checkout=self.report.checkout,
                                 backup=self.report.backup,
                                 backup_path=self.report.backup_path,
                                 verbose=self.report.verbose)
            return {}

    work = DistributedWork(len(preparation_reports), num_threads, silent=False)
    for report in preparation_reports:
        report.verbose = verbose
        thread = Installer(report)
        work.add_thread(thread)

    try:
        work.run()
    except MultiProjectException as exc:
        print("Exception caught during install: %s" % exc)
        success = False
        if not robust:
            raise exc
    return success
예제 #17
0
    def cmd_info(self, target_path, argv, reverse=True, config=None):
        only_option_valid_attrs = [
            'path', 'localname', 'version', 'revision', 'cur_revision', 'uri',
            'cur_uri', 'scmtype'
        ]
        parser = OptionParser(
            usage="usage: %s info [localname]* [OPTIONS]" % _PROGNAME,
            formatter=IndentedHelpFormatterWithNL(),
            description=__MULTIPRO_CMD_DICT__["info"] + """

The Status (S) column shows
 x  for missing
 L  for uncommited (local) changes
 V  for difference in version and/or remote URI

The 'Version-Spec' column shows what tag, branch or revision was given
in the .rosinstall file. The 'UID' column shows the unique ID of the
current (and specified) version. The 'URI' column shows the configured
URL of the repo.

If status is V, the difference between what was specified and what is
real is shown in the respective column. For SVN entries, the url is
split up according to standard layout (trunk/tags/branches).  The
ROS_PACKAGE_PATH follows the order of the table, earlier entries
overlay later entries.

When given one localname, just show the data of one element in list form.
This also has the generic properties element which is usually empty.

The --only option accepts keywords: %(opts)s

Examples:
$ %(prog)s info -t ~/ros/fuerte
$ %(prog)s info robot_model
$ %(prog)s info --yaml
$ %(prog)s info --only=path,cur_uri,cur_revision robot_model geometry
""" % {
                'prog': _PROGNAME,
                'opts': only_option_valid_attrs
            },
            epilog="See: http://www.ros.org/wiki/rosinstall for details\n")
        parser.add_option("--data-only",
                          dest="data_only",
                          default=False,
                          help="Does not provide explanations",
                          action="store_true")
        parser.add_option("--no-pkg-path",
                          dest="no_pkg_path",
                          default=False,
                          help="Suppress ROS_PACKAGE_PATH.",
                          action="store_true")
        parser.add_option(
            "--pkg-path-only",
            dest="pkg_path_only",
            default=False,
            help=
            "Shows only ROS_PACKAGE_PATH separated by ':'. Supercedes all other options.",
            action="store_true")
        parser.add_option(
            "--only",
            dest="only",
            default=False,
            help=
            "Shows comma-separated lists of only given comma-separated attribute(s).",
            action="store")
        parser.add_option(
            "--yaml",
            dest="yaml",
            default=False,
            help="Shows only version of single entry. Intended for scripting.",
            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 = 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))
        if args == []:
            args = None
        # relevant for code completion, so these should yield quick response:
        if options.pkg_path_only:
            print(":".join(get_ros_package_path(config)))
            return 0
        elif options.only:
            only_options = options.only.split(",")
            if only_options == '':
                parser.error('No valid options given')

            lookup_required = False
            for attr in only_options:
                if not attr in only_option_valid_attrs:
                    parser.error("Invalid --only option '%s', valids are %s" %
                                 (attr, only_option_valid_attrs))
                if attr in ['cur_revision', 'cur_uri', 'revision']:
                    lookup_required = True
            elements = select_elements(config, args)
            for element in elements:
                if lookup_required and element.is_vcs_element():
                    spec = element.get_versioned_path_spec()
                else:
                    spec = element.get_path_spec()
                output = []
                for attr in only_options:
                    if 'localname' == attr:
                        output.append(spec.get_local_name() or '')
                    if 'path' == attr:
                        output.append(spec.get_path() or '')
                    if 'scmtype' == attr:
                        output.append(spec.get_scmtype() or '')
                    if 'uri' == attr:
                        output.append(spec.get_uri() or '')
                    if 'version' == attr:
                        output.append(spec.get_version() or '')
                    if 'revision' == attr:
                        output.append(spec.get_revision() or '')
                    if 'cur_uri' == attr:
                        output.append(spec.get_curr_uri() or '')
                    if 'cur_revision' == attr:
                        output.append(spec.get_current_revision() or '')
                print(','.join(output))
            return 0
        if options.yaml:
            source_aggregate = cmd_snapshot(config, localnames=args)
            print(yaml.safe_dump(source_aggregate))
            return 0

        # this call takes long, as it invokes scms.
        outputs = cmd_info(config, localnames=args)
        if args is not None and len(outputs) == 1:
            print(
                get_info_list(config.get_base_path(), outputs[0],
                              options.data_only))
            return 0

        header = 'workspace: %s\nROS_ROOT: %s' % (target_path,
                                                  get_ros_stack_path(config))
        print(header)
        if not options.no_pkg_path:
            table = get_info_table(config.get_base_path(),
                                   outputs,
                                   options.data_only,
                                   reverse=reverse)
            if table is not None and table != '':
                print("\n%s" % table)

        return 0
예제 #18
0
def cmd_install_or_update(
    config,
    backup_path=None,
    mode='abort',
    robust=False,
    localnames=None,
    num_threads=1,
    verbose=False):
    """
    performs many things, generally attempting to make
    the local filesystem look like what the config specifies,
    pulling from remote sources the most recent changes.

    The command may have stdin user interaction (TODO abstract)

    :param backup_path: if and where to backup trees before deleting them
    :param robust: proceed to next element even when one element fails
    :returns: True on Success
    :raises MultiProjectException: on plenty of errors
    """
    success = True
    if not os.path.exists(config.get_base_path()):
        os.mkdir(config.get_base_path())
    # Prepare install operation check filesystem and ask user
    preparation_reports = []
    elements = select_elements(config, localnames)
    for tree_el in elements:
        abs_backup_path = None
        if backup_path is not None:
            abs_backup_path = os.path.join(config.get_base_path(), backup_path)
        try:
            preparation_report = tree_el.prepare_install(backup_path=abs_backup_path,
                                                   arg_mode=mode,
                                                   robust=robust)
            if preparation_report is not None:
                if preparation_report.abort:
                    raise MultiProjectException("Aborting install because of %s" % preparation_report.error)
                if not preparation_report.skip:
                    preparation_reports.append(preparation_report)
                else:
                    if preparation_report.error is not None:
                        print("Skipping install of %s because: %s" % (preparation_report.config_element.get_local_name(),
                                                                    preparation_report.error))
        except MultiProjectException as exc:
            fail_str = "Failed to install tree '%s'\n %s" % (tree_el.get_path(), exc)
            if robust:
                success = False
                print("Continuing despite %s" % fail_str)
            else:
                raise MultiProjectException(fail_str)

    class Installer():

        def __init__(self, report):
            self.element = report.config_element
            self.report = report

        def do_work(self):
            self.element.install(checkout=self.report.checkout,
                                 backup=self.report.backup,
                                 backup_path=self.report.backup_path,
                                 inplace=self.report.inplace,
                                 verbose=self.report.verbose)
            return {}

    work = DistributedWork(len(preparation_reports), num_threads, silent=False)
    for report in preparation_reports:
        report.verbose = verbose
        thread = Installer(report)
        work.add_thread(thread)

    try:
        work.run()
    except MultiProjectException as exc:
        print ("Exception caught during install: %s" % exc)
        success = False
        if not robust:
            raise
    return success
예제 #19
0
    def cmd_info(self, target_path, argv, reverse=True, config=None):
        only_option_valid_attrs = ['path', 'localname', 'version', 'revision', 'cur_revision', 'uri', 'cur_uri', 'scmtype']
        parser = OptionParser(usage="usage: %s info [localname]* [OPTIONS]" % self.progname,
                              formatter=IndentedHelpFormatterWithNL(),
                              description=__MULTIPRO_CMD_DICT__["info"] + """

The Status (S) column shows
 x  for missing
 L  for uncommited (local) changes
 V  for difference in version and/or remote URI

The 'Version-Spec' column shows what tag, branch or revision was given
in the .rosinstall file. The 'UID' column shows the unique ID of the
current (and specified) version. The 'URI' column shows the configured
URL of the repo.

If status is V, the difference between what was specified and what is
real is shown in the respective column. For SVN entries, the url is
split up according to standard layout (trunk/tags/branches).  The
ROS_PACKAGE_PATH follows the order of the table, earlier entries
overlay later entries.

When given one localname, just show the data of one element in list form.
This also has the generic properties element which is usually empty.

The --only option accepts keywords: %(opts)s

Examples:
$ %(prog)s info -t ~/ros/fuerte
$ %(prog)s info robot_model
$ %(prog)s info --yaml
$ %(prog)s info --only=path,cur_uri,cur_revision robot_model geometry
""" % {'prog': _PROGNAME, 'opts': only_option_valid_attrs},
                              epilog="See: http://www.ros.org/wiki/rosinstall for details\n")
        parser.add_option("--data-only", dest="data_only", default=False,
                          help="Does not provide explanations",
                          action="store_true")
        parser.add_option("--no-pkg-path", dest="no_pkg_path", default=False,
                          help="Suppress ROS_PACKAGE_PATH.",
                          action="store_true")
        parser.add_option("--pkg-path-only", dest="pkg_path_only", default=False,
                          help="Shows only ROS_PACKAGE_PATH separated by ':'. Supercedes all other options.",
                          action="store_true")
        parser.add_option("--only", dest="only", default=False,
                          help="Shows comma-separated lists of only given comma-separated attribute(s).",
                          action="store")
        parser.add_option("--yaml", dest="yaml", default=False,
                          help="Shows only version of single entry. Intended for scripting.",
                          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 = 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))
        if args == []:
            args = None
        # relevant for code completion, so these should yield quick response:
        if options.pkg_path_only:
            print(":".join(get_ros_package_path(config)))
            return 0
        elif options.only:
            only_options = options.only.split(",")
            if only_options == '':
                parser.error('No valid options given')

            lookup_required = False
            for attr in only_options:
                if not attr in only_option_valid_attrs:
                    parser.error("Invalid --only option '%s', valids are %s" % (attr, only_option_valid_attrs))
                if attr in ['cur_revision', 'cur_uri', 'revision']:
                    lookup_required = True
            elements = select_elements(config, args)
            for element in elements:
                if lookup_required and element.is_vcs_element():
                    spec = element.get_versioned_path_spec()
                else:
                    spec = element.get_path_spec()
                output = []
                for attr in only_options:
                    if 'localname' == attr:
                        output.append(spec.get_local_name() or '')
                    if 'path' == attr:
                        output.append(spec.get_path() or '')
                    if 'scmtype' == attr:
                        output.append(spec.get_scmtype() or '')
                    if 'uri' == attr:
                        output.append(spec.get_uri() or '')
                    if 'version' == attr:
                        output.append(spec.get_version() or '')
                    if 'revision' == attr:
                        output.append(spec.get_revision() or '')
                    if 'cur_uri' == attr:
                        output.append(spec.get_curr_uri() or '')
                    if 'cur_revision' == attr:
                        output.append(spec.get_current_revision() or '')
                print(','.join(output))
            return 0
        if options.yaml:
            source_aggregate = cmd_snapshot(config, localnames=args)
            print(yaml.safe_dump(source_aggregate))
            return 0

        # this call takes long, as it invokes scms.
        outputs = cmd_info(config, localnames=args)
        if args is not None and len(outputs) == 1:
            print(get_info_list(config.get_base_path(),
                                outputs[0],
                                options.data_only))
            return 0

        header = 'workspace: %s\nROS_ROOT: %s' % (target_path,
                                                  get_ros_stack_path(config))
        print(header)
        if not options.no_pkg_path:
            table = get_info_table(config.get_base_path(),
                                   outputs,
                                   options.data_only,
                                   reverse=reverse)
            if table is not None and table != '':
                print("\n%s" % table)

        return 0
예제 #20
0
def cmd_info(config, localnames=None):
    """This function compares what should be (config_file) with what is
    (directories) and returns a list of dictionary giving each local
    path and all the state information about it available.
    """

    class InfoRetriever():

        def __init__(self, element, path):
            self.element = element
            self.path = path

        def do_work(self):
            localname = ""
            scm = None
            uri = ""
            curr_uri = None
            exists = False
            version = ""  # what is given in config file
            modified = ""
            actualversion = ""  # revision number of version
            specversion = ""  # actual revision number
            localname = self.element.get_local_name()
            path = self.element.get_path() or localname

            if localname is None or localname == "":
                raise MultiProjectException("Missing local-name in element: %s" % self.element)
            if (os.path.exists(normabspath(path, self.path))):
                exists = True
            if self.element.is_vcs_element():
                if not exists:
                    path_spec = self.element.get_path_spec()
                    version = path_spec.get_version()
                else:
                    path_spec = self.element.get_versioned_path_spec()
                    version = path_spec.get_version()
                    curr_uri = path_spec.get_curr_uri()
                    status = self.element.get_status(self.path)
                    if (status is not None and
                        status.strip() != ''):
                        modified = True
                    specversion = path_spec.get_revision()
                    if (version is not None and
                        version.strip() != '' and
                        (specversion is None or specversion.strip() == '')):

                        specversion = '"%s"' % version
                    actualversion = path_spec.get_current_revision()
                scm = path_spec.get_scmtype()
                uri = path_spec.get_uri()
            return {'scm': scm,
                    'exists': exists,
                    'localname': localname,
                    'path': path,
                    'uri': uri,
                    'curr_uri': curr_uri,
                    'version': version,
                    'specversion': specversion,
                    'actualversion': actualversion,
                    'modified': modified,
                    'properties': self.element.get_properties()}
    path = config.get_base_path()
    # call SCM info in separate threads
    elements = config.get_config_elements()
    work = DistributedWork(len(elements))
    elements = select_elements(config, localnames)
    for element in elements:
        if element.get_properties() is None or not 'setup-file' in element.get_properties():
            work.add_thread(InfoRetriever(element, path))
    outputs = work.run()
    return outputs