Ejemplo n.º 1
0
    def test_split_protocol(self):
        """Test split protocol test."""

        assert util.split_protocol("http://abc/cde") == ("http://", "abc/cde")
        assert util.split_protocol("https://yay/yay") == ("https://", "yay/yay")
        assert util.split_protocol("ftp://ups/spu") == ("ftp://", "ups/spu")
        assert util.split_protocol("file:///test/file") == ("file://", "/test/file")
        assert util.split_protocol("nfs:ups/spu:/abc:opts") == ("", "nfs:ups/spu:/abc:opts")
        assert util.split_protocol("http:/typo/test") == ("", "http:/typo/test")
        assert util.split_protocol("") == ("", "")

        with pytest.raises(ValueError):
            util.split_protocol("http://ftp://ups/this/is/not/correct")
Ejemplo n.º 2
0
 def path(self):
     """Get absolute repository root path."""
     if self.relative_path == ".":
         return self._root_path
     else:
         protocol, url = split_protocol(os.path.join(self._root_path, self.relative_path))
         # resolve problems with relative path especially useful for NFS (root/path/../new_path)
         url = os.path.normpath(url)
         return protocol + url
Ejemplo n.º 3
0
    def split_protocol_test(self):
        """Test split protocol test."""

        self.assertEqual(util.split_protocol("http://abc/cde"),
                         ("http://", "abc/cde"))
        self.assertEqual(util.split_protocol("https://yay/yay"),
                         ("https://", "yay/yay"))
        self.assertEqual(util.split_protocol("ftp://ups/spu"),
                         ("ftp://", "ups/spu"))
        self.assertEqual(util.split_protocol("file:///test/file"),
                         ("file://", "/test/file"))
        self.assertEqual(util.split_protocol("nfs:ups/spu:/abc:opts"),
                         ("", "nfs:ups/spu:/abc:opts"))
        self.assertEqual(util.split_protocol("http:/typo/test"),
                         ("", "http:/typo/test"))
        self.assertEqual(util.split_protocol(""), ("", ""))

        with self.assertRaises(ValueError):
            util.split_protocol("http://ftp://ups/this/is/not/correct")
Ejemplo n.º 4
0
    def _get_url(root_url, relative_path):
        """Get the URL of the repository."""
        if relative_path == ".":
            return root_url

        # Get the protocol.
        protocol, root_path = split_protocol(root_url)

        # Create the absolute path.
        absolute_path = join_paths(root_path, relative_path)

        # Normalize the URL to solve problems with a relative path.
        # This is especially useful for NFS (root/path/../new_path).
        return protocol + os.path.normpath(absolute_path)
Ejemplo n.º 5
0
    def path(self):
        """Absolute path of the repository."""
        if self._relative_path == ".":
            return self._root_path

        # Create the absolute path.
        full_path = os.path.join(self._root_path, self._relative_path)
        protocol, url = split_protocol(full_path)

        # Normalize the URL to solve problems with a relative path.
        # This is especially useful for NFS (root/path/../new_path).
        url = os.path.normpath(url)

        return protocol + url