diff --git a/stor/obs.py b/stor/obs.py index 977833f6..8559ec7f 100644 --- a/stor/obs.py +++ b/stor/obs.py @@ -123,6 +123,10 @@ def resource(self): return self.parts_class(joined_resource) if joined_resource else None + def splitdrive(self): + """Split drive for obs paths from the rest""" + return self.path_class(self.drive), self[len(self.drive):] + def normpath(self): """Normalize path following linux conventions (keeps drive prefix)""" normed = posixpath.normpath('/' + str(self)[len(self.drive):])[1:] diff --git a/stor/tests/test_dx_path_compat.py b/stor/tests/test_dx_path_compat.py index 8d2680ed..c818b707 100644 --- a/stor/tests/test_dx_path_compat.py +++ b/stor/tests/test_dx_path_compat.py @@ -223,3 +223,9 @@ def test_splitpath(self): assert f.splitpath() == (DXCanonicalPath("dx://project-123456789012345678901234:"), '') f = DXPath('dx://project-123456789012345678901234') assert f.splitpath() == (DXCanonicalPath("dx://project-123456789012345678901234:"), '') + + def test_splitdrive(self): + f = DXPath('dx://') + assert f.splitdrive() == (DXPath('dx://'), '') + f = DXPath('dx://project:prefix/dir/file') + assert f.splitdrive() == (DXPath('dx://'), 'project:prefix/dir/file') diff --git a/stor/tests/test_s3_path_compat.py b/stor/tests/test_s3_path_compat.py index dd9f79d9..2290ee31 100644 --- a/stor/tests/test_s3_path_compat.py +++ b/stor/tests/test_s3_path_compat.py @@ -54,3 +54,9 @@ def test_properties(self): # .ext self.assertEqual(f.ext, '.csv') self.assertEqual(f.parent.ext, '') + + def test_splitdrive(self): + f = S3Path('s3://') + assert f.splitdrive() == (S3Path('s3://'), '') + f = S3Path('s3://bucket/prefix/whatever.csv') + assert f.splitdrive() == (S3Path('s3://'), 'bucket/prefix/whatever.csv') diff --git a/stor/tests/test_swift_path_compat.py b/stor/tests/test_swift_path_compat.py index 19d2df1b..88ef1c3c 100644 --- a/stor/tests/test_swift_path_compat.py +++ b/stor/tests/test_swift_path_compat.py @@ -54,3 +54,9 @@ def test_properties(self): # .ext self.assertEqual(f.ext, '.csv') self.assertEqual(f.parent.ext, '') + + def test_splitdrive(self): + f = SwiftPath("swift://") + assert f.splitdrive() == (SwiftPath('swift://'), '') + f = SwiftPath("swift://foo") + assert f.splitdrive() == (SwiftPath('swift://'), 'foo')