コード例 #1
0
ファイル: test_config.py プロジェクト: NikolausDemmel/wstool
 def test_config_simple2(self):
     git1 = PathSpec('foo', 'git', 'git/uri')
     svn1 = PathSpec('foos', 'svn', 'svn/uri')
     hg1 = PathSpec('fooh', 'hg', 'hg/uri')
     bzr1 = PathSpec('foob', 'bzr', 'bzr/uri')
     config = self._get_mock_config([git1, svn1, hg1, bzr1])
     self.assertEqual(4, len(config.get_config_elements()))
     self.assertEqual('foo', config.get_config_elements()[0].get_local_name())
     self.assertEqual('/install/path/foo', config.get_config_elements()[0].get_path())
     self.assertEqual('git', config.get_source()[0].get_scmtype())
     self.assertEqual('/install/path/git/uri', config.get_source()[0].get_uri())
     self.assertEqual('svn', config.get_source()[1].get_scmtype())
     self.assertEqual('/install/path/svn/uri', config.get_source()[1].get_uri())
     self.assertEqual('hg', config.get_source()[2].get_scmtype())
     self.assertEqual('/install/path/hg/uri', config.get_source()[2].get_uri())
     self.assertEqual('bzr', config.get_source()[3].get_scmtype())
     self.assertEqual('/install/path/bzr/uri', config.get_source()[3].get_uri())
コード例 #2
0
 def test_config_simple2(self):
     git1 = PathSpec('foo', 'git', 'git/uri')
     svn1 = PathSpec('foos', 'svn', 'svn/uri')
     hg1 = PathSpec('fooh', 'hg', 'hg/uri')
     bzr1 = PathSpec('foob', 'bzr', 'bzr/uri')
     config = self._get_mock_config([git1, svn1, hg1, bzr1])
     self.assertEqual(4, len(config.get_config_elements()))
     self.assertEqual('foo',
                      config.get_config_elements()[0].get_local_name())
     self.assertEqual('/install/path/foo',
                      config.get_config_elements()[0].get_path())
     self.assertEqual('git', config.get_source()[0].get_scmtype())
     self.assertEqual('/install/path/git/uri',
                      config.get_source()[0].get_uri())
     self.assertEqual('svn', config.get_source()[1].get_scmtype())
     self.assertEqual('/install/path/svn/uri',
                      config.get_source()[1].get_uri())
     self.assertEqual('hg', config.get_source()[2].get_scmtype())
     self.assertEqual('/install/path/hg/uri',
                      config.get_source()[2].get_uri())
     self.assertEqual('bzr', config.get_source()[3].get_scmtype())
     self.assertEqual('/install/path/bzr/uri',
                      config.get_source()[3].get_uri())
コード例 #3
0
ファイル: test_config.py プロジェクト: NikolausDemmel/wstool
    def test_config_merging_replace(self):
        git1 = PathSpec('foo', 'git', 'git/uri')
        svn1 = PathSpec('foo', 'svn', 'svn/uri')
        hg1 = PathSpec('foo', 'hg', 'hg/uri')
        bzr1 = PathSpec('foo', 'bzr', 'bzr/uri')
        config = self._get_mock_config([git1, svn1, hg1, bzr1], merge_strategy="MergeReplace")
        self.assertEqual(1, len(config.get_config_elements()))
        self.assertEqual('bzr', config.get_source()[0].get_scmtype())
        self.assertEqual('/install/path/bzr/uri', config.get_source()[0].get_uri())
        config = self._get_mock_config([git1, svn1, hg1, bzr1, git1], merge_strategy="MergeReplace")
        self.assertEqual(1, len(config.get_config_elements()))
        self.assertEqual('git', config.get_source()[0].get_scmtype())
        self.assertEqual('/install/path/git/uri', config.get_source()[0].get_uri())

        bzr1 = PathSpec('bar', 'bzr', 'bzr/uri')
        config = self._get_mock_config([git1, svn1, hg1, bzr1], merge_strategy="MergeReplace")
        self.assertEqual(2, len(config.get_config_elements()))
        self.assertEqual('hg', config.get_source()[0].get_scmtype())
        self.assertEqual('/install/path/hg/uri', config.get_source()[0].get_uri())
        self.assertEqual('bzr', config.get_source()[1].get_scmtype())
        self.assertEqual('/install/path/bzr/uri', config.get_source()[1].get_uri())
        config = self._get_mock_config([git1, svn1, hg1, bzr1, git1], merge_strategy="MergeReplace")
        self.assertEqual(2, len(config.get_config_elements()))
        self.assertEqual('git', config.get_source()[0].get_scmtype())
        self.assertEqual('/install/path/git/uri', config.get_source()[0].get_uri())
        self.assertEqual('bzr', config.get_source()[1].get_scmtype())
        self.assertEqual('/install/path/bzr/uri', config.get_source()[1].get_uri())
コード例 #4
0
def generate_config_yaml(config,
                         filename,
                         header,
                         pretty=False,
                         sort_with_localname=False,
                         spec=True,
                         exact=False,
                         vcs_only=False):
    """
    Writes file filename with header first and then the config as YAML.

    :param config: The configuration containing all the entries to be included
    in the generated YAML.
    :param filename: If filename is not an absolute path, it will be assumed to
    be relative to config.get_base_path(). If filename is None, the output will
    be sent to stdout instead of a file.
    :param header: A header to be included with the generated config YAML.
    :param pretty: If True, the generated config YAML will be printed in
    long-form YAML. If false, the default flow style will be used instead.
    :param sort_with_localname: If true, config entries will be sorted by their
    localname fields. If false, the order will be as passed in through config.
    :param spec: If True, the version information will come from the workspace
    .rosinstall. If False, the version information will come from the current
    work trees.
    :param exact: If True, the versions will be set to the exact commit UUIDs.
    If False, the version name will be used, which might be a branch name
    aut cetera.
    :param vcs_only: If True, the generated config YAML will include only
    version-controlled entries. If False, all entries in current workspace will
    be included.
    """
    assert isinstance(config, wstool.config.Config)

    if not os.path.exists(config.get_base_path()):
        os.makedirs(config.get_base_path())

    content = ""
    if header:
        content += header

    # Do a pass-through if just pulling versioning information straight from
    # the .rosinstall
    passthrough = spec and not exact
    items = config.get_source(not passthrough, vcs_only)
    if sort_with_localname:
        items = sorted(items, key=lambda x: x.get_local_name())
    items = [x.get_legacy_yaml(spec, exact) for x in items]

    if items:
        if pretty:
            content += yaml.safe_dump(items,
                                      allow_unicode=True,
                                      default_flow_style=False)
        else:
            content += yaml.safe_dump(items)

    if filename:
        config_filepath = filename if os.path.isabs(filename) else \
            os.path.realpath(os.path.join(config.get_base_path(), filename))

        with open(config_filepath, 'w+b') as f:
            f.write(content.encode('UTF-8'))
    else:
        print(content)
コード例 #5
0
    def test_config_merging_replace(self):
        git1 = PathSpec('foo', 'git', 'git/uri')
        svn1 = PathSpec('foo', 'svn', 'svn/uri')
        hg1 = PathSpec('foo', 'hg', 'hg/uri')
        bzr1 = PathSpec('foo', 'bzr', 'bzr/uri')
        config = self._get_mock_config([git1, svn1, hg1, bzr1],
                                       merge_strategy="MergeReplace")
        self.assertEqual(1, len(config.get_config_elements()))
        self.assertEqual('bzr', config.get_source()[0].get_scmtype())
        self.assertEqual('/install/path/bzr/uri',
                         config.get_source()[0].get_uri())
        config = self._get_mock_config([git1, svn1, hg1, bzr1, git1],
                                       merge_strategy="MergeReplace")
        self.assertEqual(1, len(config.get_config_elements()))
        self.assertEqual('git', config.get_source()[0].get_scmtype())
        self.assertEqual('/install/path/git/uri',
                         config.get_source()[0].get_uri())

        bzr1 = PathSpec('bar', 'bzr', 'bzr/uri')
        config = self._get_mock_config([git1, svn1, hg1, bzr1],
                                       merge_strategy="MergeReplace")
        self.assertEqual(2, len(config.get_config_elements()))
        self.assertEqual('hg', config.get_source()[0].get_scmtype())
        self.assertEqual('/install/path/hg/uri',
                         config.get_source()[0].get_uri())
        self.assertEqual('bzr', config.get_source()[1].get_scmtype())
        self.assertEqual('/install/path/bzr/uri',
                         config.get_source()[1].get_uri())
        config = self._get_mock_config([git1, svn1, hg1, bzr1, git1],
                                       merge_strategy="MergeReplace")
        self.assertEqual(2, len(config.get_config_elements()))
        self.assertEqual('git', config.get_source()[0].get_scmtype())
        self.assertEqual('/install/path/git/uri',
                         config.get_source()[0].get_uri())
        self.assertEqual('bzr', config.get_source()[1].get_scmtype())
        self.assertEqual('/install/path/bzr/uri',
                         config.get_source()[1].get_uri())