Exemplo n.º 1
0
 def test_remove(self):
     git1 = PathSpec('foo', 'git', 'git/uri', 'git.version')
     svn1 = PathSpec('foos', 'svn', 'svn/uri', '12345')
     hg1 = PathSpec('fooh', 'hg', 'hg/uri', 'hg.version')
     bzr1 = PathSpec('foob', 'bzr', 'bzr/uri', 'bzr.version')
     config = self._get_mock_config([git1, svn1, hg1, bzr1])
     self.assertEqual(4, len(config.get_config_elements()))
     self.assertFalse(config.remove_element(None))
     self.assertFalse(config.remove_element('bar'))
     self.assertEqual(4, len(config.get_config_elements()))
     self.assertTrue(config.remove_element('foo'))
     self.assertEqual(3, len(config.get_config_elements()))
     self.assertEqual('/install/path/foos',
                      config.get_config_elements()[0].get_path())
     self.assertEqual('/install/path/fooh',
                      config.get_config_elements()[1].get_path())
     self.assertEqual('/install/path/foob',
                      config.get_config_elements()[2].get_path())
     self.assertTrue(config.remove_element('fooh'))
     self.assertEqual(2, len(config.get_config_elements()))
     self.assertEqual('/install/path/foos',
                      config.get_config_elements()[0].get_path())
     self.assertEqual('/install/path/foob',
                      config.get_config_elements()[1].get_path())
     self.assertTrue(config.remove_element('foos'))
     self.assertEqual(1, len(config.get_config_elements()))
     self.assertTrue(config.remove_element('foob'))
     self.assertEqual(0, len(config.get_config_elements()))
Exemplo n.º 2
0
 def test_mock_install(self):
     test_root = tempfile.mkdtemp()
     try:
         git1 = PathSpec('foo', 'git', 'git/uri', 'git.version')
         svn1 = PathSpec('foos', 'svn', 'svn/uri', '12345')
         hg1 = PathSpec('fooh', 'hg', 'hg/uri', 'hg.version')
         bzr1 = PathSpec('foob', 'bzr', 'bzr/uri', 'bzr.version')
         config = Config(
             [git1, svn1, hg1, bzr1], test_root, None, {
                 "svn": MockVcsConfigElement,
                 "git": MockVcsConfigElement,
                 "hg": MockVcsConfigElement,
                 "bzr": MockVcsConfigElement
             })
         rosinstall.multiproject_cmd.cmd_install_or_update(config)
         rosinstall.multiproject_cmd.cmd_install_or_update(config)
         rosinstall.multiproject_cmd.cmd_install_or_update(config,
                                                           num_threads=10)
         rosinstall.multiproject_cmd.cmd_install_or_update(config,
                                                           num_threads=10)
         rosinstall.multiproject_cmd.cmd_install_or_update(config,
                                                           num_threads=1)
         rosinstall.multiproject_cmd.cmd_install_or_update(config,
                                                           num_threads=1)
     finally:
         shutil.rmtree(test_root)
Exemplo n.º 3
0
    def test_cmd_generate_ros_files_catkinpp(self):
        self.local_path = os.path.join(self.test_root_path, "ws4")
        os.makedirs(self.local_path)

        config = FakeConfig([
            PathSpec(self.ros_path),
            PathSpec('gitrepo', 'git', uri=self.git_path)
        ], self.local_path)
        rosinstall.rosinstall_cmd.cmd_generate_ros_files(config,
                                                         self.local_path,
                                                         nobuild=True,
                                                         rosdep_yes=False,
                                                         catkin=True,
                                                         catkinpp=True)
        self.assertFalse(
            os.path.exists(os.path.join(self.local_path, 'setup.sh')))
        self.assertFalse(
            os.path.exists(os.path.join(self.local_path, 'setup.bash')))
        self.assertFalse(
            os.path.exists(os.path.join(self.local_path, 'setup.zsh')))
        self.assertTrue(
            os.path.exists(os.path.join(self.local_path, 'CMakeLists.txt')))
        self.assertTrue(
            os.path.exists(
                os.path.join(self.local_path, 'workspace-config.cmake')))
Exemplo n.º 4
0
 def test_mock_install_fail(self):
     test_root = tempfile.mkdtemp()
     try:
         # robust
         git1 = PathSpec('foo', 'git', 'git/uri', 'git.version')
         svn1 = PathSpec('foos', 'svn', 'svn/uri', '12345')
         hg1 = PathSpec('fooh', 'hg', 'hg/uri', 'hg.version')
         bzr1 = PathSpec('foob', 'bzr', 'bzr/uri', 'bzr.version')
         config = Config(
             [git1, svn1, hg1, bzr1], test_root, None, {
                 "svn": MockVcsConfigElement,
                 "git": MockVcsConfigElement,
                 "hg": MockVcsConfigElement,
                 "bzr": MockVcsConfigElement
             })
         config.get_config_elements()[1].install_success = False
         rosinstall.multiproject_cmd.cmd_install_or_update(config,
                                                           robust=True)
         try:
             rosinstall.multiproject_cmd.cmd_install_or_update(config,
                                                               robust=False)
             self.fail("expected Exception")
         except MultiProjectException:
             pass
     finally:
         shutil.rmtree(test_root)
Exemplo n.º 5
0
    def test_get_element_diff(self):
        cli = MultiprojectCLI(progname='multi_cli',
                              config_filename='.rosinstall')
        self.assertEqual('', cli._get_element_diff(None, None))
        self.assertEqual('', cli._get_element_diff(None, 42))
        self.assertEqual('', cli._get_element_diff(42, None))

        spec = PathSpec('foolocalname',
                        scmtype='fooscm',
                        uri='foouri',
                        version='fooversion',
                        path='foopath')

        spec2 = PathSpec('foolocalname')
        element2 = MockConfigElement(local_name='foolocalname', spec=spec2)

        elements = [element2]
        config = FakeConfig(celts=elements)

        output = cli._get_element_diff(spec, config)
        self.assertEqual(' foolocalname', output)

        output = cli._get_element_diff(spec, config, extra_verbose=True)
        snippets = [
            ' foolocalname', 'version = fooversion', 'specified uri = foouri',
            'scmtype = fooscm'
        ]
        for s in snippets:
            self.assertTrue(s in output,
                            "missing snippet: '%s' in '%s'" % (s, output))
Exemplo n.º 6
0
 def test_config_simple3(self):
     git1 = PathSpec('foo', 'git', 'git/uri', 'git.version')
     svn1 = PathSpec('foos', 'svn', 'svn/uri', '12345')
     bzr1 = PathSpec('foob', 'bzr', 'bzr/uri', 'bzr.version')
     hg1 = PathSpec('fooh', 'hg', 'hg/uri', 'hg.version')
     config = self._get_mock_config([git1, svn1, hg1, bzr1])
     self.assertEqual(4, len(config.get_config_elements()))
Exemplo n.º 7
0
 def test_config_merging_kill_append(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])
     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])
     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])
     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])
     self.assertEqual(2, 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())
     self.assertEqual('git', config.get_source()[1].get_scmtype())
     self.assertEqual('/install/path/git/uri',
                      config.get_source()[1].get_uri())
Exemplo n.º 8
0
 def test_gen_python_code_python3(self):
     # requires python3 to be installed, obviously
     config = Config([
         PathSpec(os.path.join("test", "example_dirs", "ros_comm")),
         PathSpec("bar.sh", tags=['setup-file']),
         PathSpec("baz")
     ], self.directory, None)
     rosinstall.config_yaml.generate_config_yaml(
         config, '.rosinstall', '')
     filename = os.path.join(self.directory, "test_gen.py")
     _add_to_file(filename,
                  rosinstall.setupfiles.generate_embedded_python())
     sh_filename = os.path.join(self.directory, "bar.sh")
     _add_to_file(sh_filename, "#! /usr/bin/env sh")
     cmd = "python3 %s" % filename
     p = subprocess.Popen(cmd,
                          shell=True,
                          cwd=self.directory,
                          stdout=subprocess.PIPE,
                          stderr=subprocess.PIPE)
     output, err = p.communicate()
     self.assertEqual(''.encode('UTF-8'), err, err)
     self.assertTrue(
         '/test/example_dirs/ros_comm'.encode('UTF-8') in output,
         output)
     self.assertTrue('baz'.encode('UTF-8') in output, output)
     self.assertTrue(
         'ROSINSTALL_PATH_SETUPFILE_SEPARATOR'.encode('UTF-8')
         in output, output)
     self.assertTrue(output.endswith('/bar.sh\n'.encode('UTF-8')),
                     output)
Exemplo n.º 9
0
 def test_require_bootstrap(self):
     config = FakeConfig()
     self.assertFalse(
         rosinstall.rosinstall_cmd._ros_requires_boostrap(config))
     config = FakeConfig([PathSpec(self.ros_path, path=self.ros_path)])
     self.assertFalse(
         rosinstall.rosinstall_cmd._ros_requires_boostrap(config))
     config = FakeConfig(
         [PathSpec(self.ros_path, 'git', 'gituri', path=self.ros_path)])
     self.assertTrue(
         rosinstall.rosinstall_cmd._ros_requires_boostrap(config))
Exemplo n.º 10
0
 def test_source_setup_sh(self):
     test_folder = os.path.join(self.test_root_path, 'workspacetest')
     os.makedirs(test_folder)
     othersetupfile = os.path.join(test_folder, 'othersetup.sh')
     testsetupfile = os.path.join(test_folder, 'testsetup.sh')
     with open(othersetupfile, 'w') as fhand:
         fhand.write('unset ROS_WORKSPACE')
     config = Config([
         PathSpec(self.ros_path),
         PathSpec(othersetupfile, scmtype=None, tags=['setup-file'])
     ],
                     install_path=test_folder,
                     config_filename=ROSINSTALL_FILENAME)
     result = rosinstall.setupfiles.generate_setup_sh_text(
         config.get_base_path())
     self.assertTrue('export ROS_WORKSPACE=%s' % test_folder in result)
     with open(testsetupfile, 'w') as fhand:
         fhand.write(result)
     # check that sourcing setup.sh raises error when .rosinstall is missing
     raised = False
     try:
         subprocess.check_call(". %s" % testsetupfile,
                               shell=True,
                               env=self.new_environ)
     except:
         raised = True
     self.assertTrue(
         raised, 'sourcing setup.sh with missing .rosinstall should fail')
     # test that our otherscript really unsets ROS_WORKSPACE, else nexttest would be invalid
     # using basename to check var is not set
     raised = False
     try:
         cmd = "export ROS_WORKSPACE=foo && . %s && basename $ROS_WORKSPACE" % othersetupfile
         subprocess.check_call(cmd, shell=True, env=self.new_environ)
     except:
         raised = True
     self.assertTrue(raised, 'unsetting-sh-file did not unset var')
     # now test that when sourcing setup.sh that contains a
     # setup-file to other sh file which unsets ROS_WORKSPACE,
     # ROS_WORKSPACE is still set in the end
     generate_config_yaml(config, ROSINSTALL_FILENAME, '')
     self.assertTrue(
         os.path.isfile(os.path.join(test_folder, ROSINSTALL_FILENAME)))
     # using basename to check var is set
     cmd = "export ROS_WORKSPACE=foo && . %s && echo $ROS_WORKSPACE" % testsetupfile
     po = subprocess.Popen(cmd,
                           shell=True,
                           cwd=test_folder,
                           stdout=subprocess.PIPE)
     workspace = po.stdout.read().decode('UTF-8').rstrip('"').lstrip(
         '"').strip()
     po.stdout.close()
     self.assertEqual(test_folder, workspace)
Exemplo n.º 11
0
 def test_init(self):
     yaml = []
     install_path = '/install/path'
     config_filename = '.filename'
     config = Config(yaml, install_path, config_filename)
     self.assertEqual(install_path, config.get_base_path())
     self.assertEqual([], config.get_config_elements())
     config = Config([
         PathSpec("foo"),
         PathSpec(os.path.join("test", "example_dirs", "ros_comm")),
         PathSpec(os.path.join("test", "example_dirs", "ros")),
         PathSpec(os.path.join("test", "example_dirs", "roscpp")),
         PathSpec("bar")
     ], ".", None)
     self.assertEqual(os.path.abspath('.'), config.get_base_path())
Exemplo n.º 12
0
 def test_gen_setup_bash(self):
     config = Config([
         PathSpec(self.ros_path),
         PathSpec(os.path.join("test", "example_dirs", "ros_comm")),
         PathSpec("bar")
     ], self.test_root_path, None)
     result = rosinstall.setupfiles.generate_setup_bash_text('bash')
     self.assertTrue(result.count("#!/usr/bin/env bash") == 1)
     self.assertTrue(result.count("CATKIN_SHELL=bash") == 1)
     self.assertTrue(
         result.count("ROSSHELL_PATH=`rospack find rosbash`/rosbash") == 1)
     result = rosinstall.setupfiles.generate_setup_bash_text('zsh')
     self.assertTrue(result.count("#!/usr/bin/env zsh") == 1)
     self.assertTrue(result.count("CATKIN_SHELL=zsh") == 1)
     self.assertTrue(
         result.count("ROSSHELL_PATH=`rospack find rosbash`/roszsh") == 1)
Exemplo n.º 13
0
 def test_get_stack_element_in_config(self):
     self.test_root_path = tempfile.mkdtemp()
     self.install_path = os.path.join(self.test_root_path, "install")
     os.makedirs(self.install_path)
     f = io.open(os.path.join(self.install_path, 'stack.xml'), 'a')
     f.write(unicode("hello stack"))
     f.close()
     config = Config([PathSpec("foo"),
                      PathSpec("install"),
                      PathSpec("bar")],
                     self.test_root_path,
                     None)
     self.assertEqual(None, rosinstall.rosws_stacks_cli.get_stack_element_in_config(config, 'foo'))
     self.assertEqual(None, rosinstall.rosws_stacks_cli.get_stack_element_in_config(config, None))
     el = rosinstall.rosws_stacks_cli.get_stack_element_in_config(config, 'install')
     self.assertEqual(self.install_path, el.get_path())
     shutil.rmtree(self.test_root_path)
Exemplo n.º 14
0
 def test_config_simple1(self):
     mock1 = PathSpec('foo')
     config = self._get_mock_config([mock1])
     self.assertEqual(1, 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())
Exemplo n.º 15
0
    def test_config_simple1_with_setupfile(self):
        mock1 = PathSpec('setup.sh', tags='setup-file')
        config = self._get_mock_config([mock1])
        self.assertEqual(1, len(config.get_config_elements()))
        self.assertEqual('setup.sh',
                         config.get_config_elements()[0].get_local_name())
        self.assertEqual('/install/path/setup.sh',
                         config.get_config_elements()[0].get_path())

        mock1 = PathSpec('/foo')
        mock2 = PathSpec('/opt/setup.sh', tags='setup-file')
        mock3 = PathSpec('/bar')
        config = self._get_mock_config([mock1, mock2, mock3])
        self.assertEqual(3, len(config.get_config_elements()))
        self.assertEqual('/opt/setup.sh',
                         config.get_config_elements()[1].get_local_name())
        self.assertEqual('/opt/setup.sh',
                         config.get_config_elements()[1].get_path())
Exemplo n.º 16
0
 def test_long_localname(self):
     "Should source choose shorter local-name"
     mock1 = PathSpec("/foo/bar/boo/far/bim")
     config = self._get_mock_config([mock1], '/foo/bar/boo/far')
     self.assertEqual(1, len(config.get_config_elements()))
     self.assertEqual('/foo/bar/boo/far/bim',
                      config.get_config_elements()[0].get_local_name())
     self.assertEqual('/foo/bar/boo/far/bim',
                      config.get_config_elements()[0].get_path())
Exemplo n.º 17
0
 def test_unnormalized_localname(self):
     "Should source normalize local-name"
     mock1 = PathSpec('foo/bar/..')
     config = self._get_mock_config([mock1])
     self.assertEqual(1, 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())
Exemplo n.º 18
0
 def test_absolute_localname(self):
     mock1 = PathSpec('/foo/bim')
     config = self._get_mock_config([mock1],
                                    install_path='/foo/bar/ba/ra/baz/bam')
     self.assertEqual(1, len(config.get_config_elements()))
     self.assertEqual('/foo/bim',
                      config.get_config_elements()[0].get_local_name())
     self.assertEqual('/foo/bim',
                      config.get_config_elements()[0].get_path())
Exemplo n.º 19
0
    def test_config_realfolders(self):
        try:
            root_path = tempfile.mkdtemp()
            share_path = os.path.join(root_path, "share")
            os.makedirs(share_path)
            ros_path = os.path.join(share_path, "ros")
            os.makedirs(ros_path)

            p1 = PathSpec('share')
            p2 = PathSpec('share/ros')
            config = self._get_mock_config([p1, p2])
            self.assertEqual(2, len(config.get_config_elements()))
            try:
                p1 = PathSpec('share', 'git', 'git/uri', 'git.version')
                p2 = PathSpec('share/ros', 'hg', 'hg/uri', 'hg.version')
                config = self._get_mock_config([p1, p2])
                self.fail("expected overlap Exception")
            except MultiProjectException:
                pass
            try:
                p1 = PathSpec('share', 'git', 'git/uri', 'git.version')
                p2 = PathSpec('share/ros', 'hg', 'hg/uri', 'hg.version')
                config = self._get_mock_config([p2, p1])
                self.fail("expected overlap Exception")
            except MultiProjectException:
                pass
            try:
                p1 = PathSpec('share', 'git', 'git/uri', 'git.version')
                p2 = PathSpec('share/ros')
                config = self._get_mock_config([p2, p1])
                self.fail("expected overlap Exception")
            except MultiProjectException:
                pass
            try:
                p1 = PathSpec('share', 'git', 'git/uri', 'git.version')
                p2 = PathSpec('share/ros')
                config = self._get_mock_config([p1, p2])
                self.fail("expected overlap Exception")
            except MultiProjectException:
                pass
        finally:
            shutil.rmtree(root_path)
Exemplo n.º 20
0
 def test_generate_with_stack(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")
     filepath = os.path.join(self.directory, 'foo')
     self.assertTrue(os.path.exists(filepath))
     with open(filepath, 'r') as f:
         read_data = f.read()
     lines = read_data.splitlines()
     self.assertEqual("# Hello", lines[0])
     self.assertEqual("- svn: {local-name: ros, uri: %s/some/uri}" % self.directory, lines[1])
Exemplo n.º 21
0
 def get_path_spec(self):
     "yaml as from source"
     version = self.version
     if version == '':
         version = None
     return PathSpec(local_name=self.get_local_name(),
                     path=self.get_path(),
                     scmtype=self.get_vcs_type_name(),
                     uri=self.uri,
                     version=version,
                     tags=self.get_properties())
Exemplo n.º 22
0
 def test_init_fail(self):
     try:
         Config(None, "path", None)
         self.fail("expected Exception")
     except MultiProjectException:
         pass
     try:
         Config([PathSpec('foo', 'bar')], "path", None)
         self.fail("expected Exception")
     except MultiProjectException:
         pass
 def test_get_ros_stack_path(self):
     config = Config([
         PathSpec("foo"),
         PathSpec(os.path.join("test", "example_dirs", "ros_comm")),
         PathSpec(os.path.join("test", "example_dirs", "roscpp")),
         PathSpec("bar")
     ], ".", None)
     self.assertEqual(None, rosinstall.helpers.get_ros_stack_path(config))
     config = Config([
         PathSpec("foo"),
         PathSpec(os.path.join("test", "example_dirs", "ros_comm")),
         PathSpec(os.path.join("test", "example_dirs", "ros")),
         PathSpec(os.path.join("test", "example_dirs", "roscpp")),
         PathSpec("bar")
     ], ".", None)
     self.assertEqual(os.path.abspath("test/example_dirs/ros"),
                      rosinstall.helpers.get_ros_stack_path(config))
Exemplo n.º 24
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
Exemplo n.º 25
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
Exemplo n.º 26
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)
Exemplo n.º 27
0
    def test_gen_setup(self):
        try:
            config = Config([
                PathSpec(os.path.join("test", "example_dirs", "ros_comm")),
                PathSpec("bar")
            ], self.test_root_path, None)
            rosinstall.setupfiles.generate_setup(config)
            self.fail('expected exception')
        except ROSInstallException:
            pass

        config = Config([
            PathSpec(self.ros_path),
            PathSpec(os.path.join("test", "example_dirs", "ros_comm")),
            PathSpec("bar")
        ], self.test_root_path, None)
        rosinstall.setupfiles.generate_setup(config)
        self.assertTrue(
            os.path.isfile(os.path.join(self.test_root_path, 'setup.sh')))
        self.assertTrue(
            os.path.isfile(os.path.join(self.test_root_path, 'setup.bash')))
        self.assertTrue(
            os.path.isfile(os.path.join(self.test_root_path, 'setup.zsh')))
Exemplo n.º 28
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())
Exemplo n.º 29
0
 def test_rewrite_included_source_setupfile(self):
     base_path = '/foo/bar'
     version = 'common_rosdeps-1.0.2'
     uri = 'https://kforge.ros.org/common/rosdepcore'
     # same simple
     struct = [PathSpec('local', tags='setup-file')]
     rewrite_included_source(struct, "/foo/bar")
     self.assertEqual(PathSpec(os.path.join(base_path, "local"), tags='setup-file'), struct[0])
     # absolute path
     struct = [PathSpec("/opt/poo", tags='setup-file')]
     rewrite_included_source(struct, "/foo/bar")
     self.assertEqual([PathSpec("/opt/poo", tags='setup-file')], struct)
     # absolute path, relative basepath
     struct = [PathSpec("/opt/poo", tags='setup-file')]
     rewrite_included_source(struct, "foo/bar")
     self.assertEqual([PathSpec("/opt/poo", tags='setup-file')], struct)
     # relative base path
     struct = [PathSpec("../opt/poo", tags='setup-file')]
     rewrite_included_source(struct, "foo/bar")
     self.assertEqual([PathSpec("foo/opt/poo", tags='setup-file')], struct)
Exemplo n.º 30
0
    def test_gen_setupsh(self):
        config = Config([
            PathSpec(self.ros_path),
            PathSpec(os.path.join("test", "example_dirs", "ros_comm")),
            PathSpec("bar")
        ], self.test_root_path, None)
        result = rosinstall.setupfiles.generate_setup_sh_text(
            config.get_base_path())
        self.assertTrue(result.count("#!/usr/bin/env sh") == 1)

        config = Config([
            PathSpec(self.ros_path),
            PathSpec(os.path.join("test", "example_dirs", "ros_comm")),
            PathSpec("bar.sh", tags=['setup-file'])
        ], self.test_root_path, None)
        result = rosinstall.setupfiles.generate_setup_sh_text(
            config.get_base_path())
        self.assertTrue(result.count("#!/usr/bin/env sh") == 1, result)
Exemplo n.º 31
0
 def get_versioned_path_spec(self):
     "yaml looking up current version"
     version = self.version
     if version == '':
         version = None
     revision = None
     if version is not None:
         # revision is the UID of the version spec, can be them same
         revision = self._get_vcsc().get_version(self.version)
     currevision = self._get_vcsc().get_version()
     uri = self.uri
     curr_uri = self._get_vcsc().get_url()
     # uri might be a shorthand notation equivalent to curr_uri
     if self._get_vcsc().url_matches(curr_uri, uri):
         curr_uri = uri
     return PathSpec(local_name=self.get_local_name(),
                     path=self.get_path(),
                     scmtype=self.get_vcs_type_name(),
                     uri=self.uri,
                     version=version,
                     revision=revision,
                     currevision=currevision,
                     curr_uri=curr_uri,
                     tags=self.get_properties())
Exemplo n.º 32
0
    def cmd_set(self, target_path, argv, config=None):
        """
        command for modifying/adding a single entry
        :param target_path: where to look for config
        :param config: config to use instead of parsing file anew
        """
        usage = ("usage: %s set [localname] [SCM-URI]?  [--(%ssvn|hg|git|bzr)] [--version=VERSION]]" %
                 (self.progname, 'detached|' if self.allow_other_element else ''))
        parser = OptionParser(
            usage=usage,
            formatter=IndentedHelpFormatterWithNL(),
            description=__MULTIPRO_CMD_DICT__["set"] + """
The command will infer whether you want to add or modify an entry. If
you modify, it will only change the details you provide, keeping
those you did not provide. if you only provide a uri, will use the
basename of it as localname unless such an element already exists.

The command only changes the configuration, to checkout or update
the element, run %(progname)s update afterwards.

Examples:
$ %(progname)s set robot_model --hg https://kforge.ros.org/robotmodel/robot_model
$ %(progname)s set robot_model --version-new robot_model-1.7.1
%(detached)s
""" % { 'progname': self.progname,
        'detached': '$ %s set robot_model --detached' % self.progname
        if self.allow_other_element
        else ''},
            epilog="See: http://www.ros.org/wiki/rosinstall for details\n")
        if self.allow_other_element:
            parser.add_option("--detached", dest="detach", default=False,
                              help="make an entry unmanaged (default for new element)",
                              action="store_true")
        parser.add_option("-v", "--version-new", dest="version", default=None,
                          help="point SCM to this version",
                          action="store")
        parser.add_option("--git", dest="git", default=False,
                          help="make an entry a git entry",
                          action="store_true")
        parser.add_option("--svn", dest="svn", default=False,
                          help="make an entry a subversion entry",
                          action="store_true")
        parser.add_option("--hg", dest="hg", default=False,
                          help="make an entry a mercurial entry",
                          action="store_true")
        parser.add_option("--bzr", dest="bzr", default=False,
                          help="make an entry a bazaar entry",
                          action="store_true")
        parser.add_option("-y", "--confirm", dest="confirm", default='',
                          help="Do not ask for confirmation",
                          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 not self.allow_other_element:
            options.detach = False

        if len(args) > 2:
            print("Error: Too many 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))

        scmtype = None
        count_scms = 0
        if options.git:
            scmtype = 'git'
            count_scms += 1
        if options.svn:
            scmtype = 'svn'
            count_scms += 1
        if options.hg:
            scmtype = 'hg'
            count_scms += 1
        if options.bzr:
            scmtype = 'bzr'
            count_scms += 1
        if options.detach:
            count_scms += 1
        if count_scms > 1:
            parser.error(
                "You cannot provide more than one scm provider option")

        if len(args) == 0:
            parser.error("Must provide a localname")

        element = select_element(config.get_config_elements(), args[0])

        uri = None
        if len(args) == 2:
            uri = args[1]
        version = None
        if options.version is not None:
            version = options.version.strip("'\"")

        # create spec object
        if element is None:
            if scmtype is None and not self.allow_other_element:
                # for modification, not re-stating the scm type is
                # okay, for new elements not
                parser.error("You have to provide one scm provider option")
            # asssume is insert, choose localname
            localname = os.path.normpath(args[0])
            rel_path = os.path.relpath(os.path.realpath(localname),
                                       os.path.realpath(config.get_base_path()))
            if os.path.isabs(localname):
                # use shorter localname for folders inside workspace
                if not rel_path.startswith('..'):
                    localname = rel_path
            else:
                # got a relative path as localname, could point to a dir or be
                # meant relative to workspace
                if not samefile(os.getcwd(), config.get_base_path()):
                    if os.path.isdir(localname):
                        parser.error(
                            "Cannot decide which one you want to add:\n%s\n%s" % (
                                os.path.abspath(localname),
                                os.path.join(config.get_base_path(), localname)))
                    if not rel_path.startswith('..'):
                        localname = rel_path

            spec = PathSpec(local_name=localname,
                            uri=normalize_uri(uri, config.get_base_path()),
                            version=version,
                            scmtype=scmtype)
        else:
            # modify
            old_spec = element.get_path_spec()
            if options.detach:
                spec = PathSpec(local_name=element.get_local_name())
            else:
                # '' evals to False, we do not want that
                if version is None:
                    version = old_spec.get_version()
                spec = PathSpec(local_name=element.get_local_name(),
                                uri=normalize_uri(uri or old_spec.get_uri(),
                                                  config.get_base_path()),
                                version=version,
                                scmtype=scmtype or old_spec.get_scmtype(),
                                path=old_spec.get_path())
            if spec.get_legacy_yaml() == old_spec.get_legacy_yaml():
                if not options.detach and spec.get_scmtype() is not None:
                    parser.error(
                        "Element %s already exists, did you mean --detached ?" % spec)
                parser.error("Element %s already exists" % spec)

        (newconfig, path_changed) = prompt_merge(
            target_path,
            additional_uris=[],
            additional_specs=[spec],
            merge_strategy='MergeReplace',
            confirmed=options.confirm,
            confirm=not options.confirm,
            show_verbosity=False,
            show_advanced=False,
            config_filename=self.config_filename,
            config=config,
            allow_other_element=self.allow_other_element)

        if newconfig is not None:
            print("Overwriting %s" % os.path.join(
                newconfig.get_base_path(), self.config_filename))
            shutil.move(
                os.path.join(newconfig.get_base_path(), self.config_filename),
                "%s.bak" % os.path.join(newconfig.get_base_path(), self.config_filename))
            self.config_generator(newconfig, self.config_filename)
            if path_changed:
                print("\nDo not forget to do ...\n$ source %s/setup.sh\n... in every open terminal." % target_path)
            if (spec.get_scmtype() is not None):
                print("Config changed, remember to run '%s update %s' to update the folder from %s" %
                      (self.progname, spec.get_local_name(), spec.get_scmtype()))
        else:
            print("New element %s could not be added, " % spec)
            return 1
        # auto-install not a good feature, maybe make an option
        # for element in config.get_config_elements():
        #   if element.get_local_name() == spec.get_local_name():
        #     if element.is_vcs_element():
        #       element.install(checkout=not os.path.exists(os.path.join(config.get_base_path(), spec.get_local_name())))
        #       break
        return 0