def add_uris(config,
             additional_uris,
             merge_strategy="KillAppend",
             allow_other_element=True):
    """
    changes the given config by merging with the additional_uris

    :param config: a Config objects
    :param additional_uris: the location of config specifications or folders
    :param config_filename: name of files which may be looked at for config
    information
    :param merge_strategy: One of 'KillAppend, 'MergeKeep', 'MergeReplace'
    :param allow_other_element: if False, discards elements to be added with
    no SCM information
    :returns: a dict {<local-name>: (<action>, <path-spec>), <local-name>: ...}
    determined by the merge_strategy
    :raises MultiProjectException: on plenty of errors
    """
    if config is None:
        raise MultiProjectException("Need to provide a Config.")

    if not additional_uris:
        return {}

    if config.get_config_filename() is None:
        added_uris = additional_uris
    else:
        added_uris = []
        # reject if the additional uri points to the same file as our
        # config is based on
        for uri in additional_uris:
            # check whether we try to merge with other workspace
            comp_uri = None
            if (os.path.isfile(uri)
                    and os.path.basename(uri) == config.get_config_filename()):
                # add from other workspace by file
                comp_uri = os.path.dirname(uri)
            if (os.path.isdir(uri) and os.path.isfile(
                    os.path.join(uri, config.get_config_filename()))):
                # add from other workspace by dir
                comp_uri = uri
            if (comp_uri is not None and realpath_relation(
                    os.path.abspath(comp_uri),
                    os.path.abspath(config.get_base_path())) == 'SAME_AS'):
                print(
                    'Warning: Discarding config basepath as additional uri: %s'
                    % uri)
                continue
            added_uris.append(uri)

    actions = {}
    if len(added_uris) > 0:
        path_specs = aggregate_from_uris(added_uris,
                                         config.get_config_filename(),
                                         allow_other_element)
        for path_spec in path_specs:
            action = config.add_path_spec(path_spec, merge_strategy)
            actions[path_spec.get_local_name()] = (action, path_spec)

    return actions
def add_uris(config,
             additional_uris,
             merge_strategy="KillAppend",
             allow_other_element=True):
    """
    changes the given config by merging with the additional_uris

    :param config: a Config objects
    :param additional_uris: the location of config specifications or folders
    :param config_filename: name of files which may be looked at for config
    information
    :param merge_strategy: One of 'KillAppend, 'MergeKeep', 'MergeReplace'
    :param allow_other_element: if False, discards elements to be added with
    no SCM information
    :returns: a dict {<local-name>: (<action>, <path-spec>), <local-name>: ...}
    determined by the merge_strategy
    :raises MultiProjectException: on plenty of errors
    """
    if config is None:
        raise MultiProjectException("Need to provide a Config.")

    if not additional_uris:
        return {}

    if config.get_config_filename() is None:
        added_uris = additional_uris
    else:
        added_uris = []
        # reject if the additional uri points to the same file as our
        # config is based on
        for uri in additional_uris:
            # check whether we try to merge with other workspace
            comp_uri = None
            if (os.path.isfile(uri)
                and os.path.basename(uri) == config.get_config_filename()):
                # add from other workspace by file
                comp_uri = os.path.dirname(uri)
            if (os.path.isdir(uri)
                and os.path.isfile(os.path.join(uri, config.get_config_filename()))):
                # add from other workspace by dir
                comp_uri = uri
            if (comp_uri is not None and
                realpath_relation(os.path.abspath(comp_uri),
                                  os.path.abspath(config.get_base_path())) == 'SAME_AS'):
                print('Warning: Discarding config basepath as additional uri: %s' % uri)
                continue
            added_uris.append(uri)

    actions = {}
    if len(added_uris) > 0:
        path_specs = aggregate_from_uris(added_uris,
                                         config.get_config_filename(),
                                         allow_other_element)
        for path_spec in path_specs:
            action = config.add_path_spec(path_spec, merge_strategy)
            actions[path_spec.get_local_name()] = (action, path_spec)

    return actions
 def test_aggregate_from_uris(self):
     self.directory = tempfile.mkdtemp()
     config = rosinstall.config.Config([PathSpec('ros', 'svn', 'some/uri')], self.directory)
     rosinstall.config_yaml.generate_config_yaml(config, 'foo', "# Hello\n")
     ryaml = aggregate_from_uris([self.directory], config.get_config_filename())
     self.assertEqual(ryaml[0].get_legacy_yaml(), {'other': {'local-name': self.directory}})
     self.assertRaises(MultiProjectException,
                       aggregate_from_uris,
                       [self.directory],
                       config.get_config_filename(),
                       allow_other_element=False)
Beispiel #4
0
 def test_aggregate_from_uris(self):
     self.directory = tempfile.mkdtemp()
     config = rosinstall.config.Config(
         [PathSpec('ros', 'svn', 'some/uri')], self.directory)
     rosinstall.config_yaml.generate_config_yaml(config, 'foo', "# Hello\n")
     ryaml = aggregate_from_uris(
         [self.directory], config.get_config_filename())
     self.assertEqual(ryaml[0].get_legacy_yaml(),
                      {'other': {'local-name': self.directory}})
     self.assertRaises(MultiProjectException,
                       aggregate_from_uris,
                       [self.directory],
                       config.get_config_filename(),
                       allow_other_element=False)
Beispiel #5
0
def add_uris(config, additional_uris, merge_strategy="KillAppend"):
    """
    changes the given config by merging with the additional_uris

    :param config: a Config objects
    :param additional_uris: the location of config specifications or folders
    :param config_filename: name of files which may be looked at for config information
    :param merge_strategy: One of 'KillAppend, 'MergeKeep', 'MergeReplace'
    :returns: a dict {<local-name>: (<action>, <path-spec>), <local-name>: ...} determined by the merge_strategy
    :raises MultiProjectException: on plenty of errors
    """
    if config is None:
        raise MultiProjectException("Need to provide a Config.")

    if additional_uris is None or len(additional_uris) == 0:
        return {}

    added_uris = []
    if config.get_config_filename() is not None:
        for uri in additional_uris:
            comp_uri = None
            if (os.path.isfile(uri)
                    and os.path.basename(uri) == config.get_config_filename()):

                comp_uri = os.path.dirname(uri)
            if (os.path.isdir(uri) and os.path.isfile(
                    os.path.join(uri, config.get_config_filename()))):
                comp_uri = uri
            if (comp_uri is not None and realpath_relation(
                    os.path.abspath(comp_uri),
                    os.path.abspath(config.get_base_path())) == 'SAME_AS'):
                print(
                    'Warning: Discarding config basepath as additional uri: %s'
                    % uri)
                continue
            added_uris.append(uri)

    path_specs = aggregate_from_uris(added_uris, config.get_config_filename())

    actions = {}
    for path_spec in path_specs:
        action = config.add_path_spec(path_spec, merge_strategy)
        actions[path_spec.get_local_name()] = (action, path_spec)

    return actions
Beispiel #6
0
def add_uris(config, additional_uris, merge_strategy="KillAppend"):
    """
    changes the given config by merging with the additional_uris

    :param config: a Config objects
    :param additional_uris: the location of config specifications or folders
    :param config_filename: name of files which may be looked at for config information
    :param merge_strategy: One of 'KillAppend, 'MergeKeep', 'MergeReplace'
    :returns: a dict {<local-name>: (<action>, <path-spec>), <local-name>: ...} determined by the merge_strategy
    :raises MultiProjectException: on plenty of errors
    """
    if config is None:
        raise MultiProjectException("Need to provide a Config.")

    if additional_uris is None or len(additional_uris) == 0:
        return {}

    added_uris = []
    if config.get_config_filename() is not None:
        for uri in additional_uris:
            comp_uri = None
            if (os.path.isfile(uri)
                and os.path.basename(uri) == config.get_config_filename()):

                comp_uri = os.path.dirname(uri)
            if (os.path.isdir(uri)
                and os.path.isfile(os.path.join(uri, config.get_config_filename()))):
                comp_uri = uri
            if (comp_uri is not None and
                realpath_relation(os.path.abspath(comp_uri),
                                  os.path.abspath(config.get_base_path())) == 'SAME_AS'):
                print('Warning: Discarding config basepath as additional uri: %s' % uri)
                continue
            added_uris.append(uri)

    path_specs = aggregate_from_uris(added_uris, config.get_config_filename())

    actions = {}
    for path_spec in path_specs:
        action = config.add_path_spec(path_spec, merge_strategy)
        actions[path_spec.get_local_name()] = (action, path_spec)

    return actions