Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove relative to function #443

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 11 additions & 53 deletions artifactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ def get_stat_json(self, pathobj, key=None):
[
pathobj.drive.rstrip("/"),
"api/storage",
str(pathobj.relative_to(pathobj.drive)).strip("/"),
pathobj.repo + pathobj.path_in_repo.rstrip("/"),
]
)

Expand Down Expand Up @@ -1025,7 +1025,7 @@ def unlink(self, pathobj):
url = "/".join(
[
pathobj.drive.rstrip("/"),
str(pathobj.relative_to(pathobj.drive)).strip("/"),
pathobj.repo + pathobj.path_in_repo.rstrip("/"),
]
)

Expand Down Expand Up @@ -1224,12 +1224,12 @@ def copy(self, src, dst, suppress_layouts=False, fail_fast=False, dry_run=False)
[
src.drive.rstrip("/"),
"api/copy",
str(src.relative_to(src.drive)).strip("/"),
src.repo + src.path_in_repo.rstrip("/")
]
)

params = {
"to": str(dst.relative_to(dst.drive)).rstrip("/"),
"to": dst.repo + dst.path_in_repo.rstrip("/"),
"suppressLayouts": int(suppress_layouts),
"failFast": int(fail_fast),
"dry": int(dry_run),
Expand Down Expand Up @@ -1264,12 +1264,12 @@ def move(self, src, dst, suppress_layouts=False, fail_fast=False, dry_run=False)
[
src.drive.rstrip("/"),
"api/move",
str(src.relative_to(src.drive)).rstrip("/"),
src.repo + src.path_in_repo.rstrip("/"),
]
)

params = {
"to": str(dst.relative_to(dst.drive)).rstrip("/"),
"to": dst.repo + dst.path_in_repo.rstrip("/"),
"suppressLayouts": int(suppress_layouts),
"failFast": int(fail_fast),
"dry": int(dry_run),
Expand All @@ -1295,7 +1295,7 @@ def get_properties(self, pathobj):
[
pathobj.drive.rstrip("/"),
"api/storage",
str(pathobj.relative_to(pathobj.drive)).strip("/"),
pathobj.repo + pathobj.path_in_repo.rstrip("/"),
]
)

Expand Down Expand Up @@ -1328,7 +1328,7 @@ def set_properties(self, pathobj, props, recursive):
[
pathobj.drive.rstrip("/"),
"api/storage",
str(pathobj.relative_to(pathobj.drive)).strip("/"),
pathobj.repo + pathobj.path_in_repo.rstrip("/"),
]
)

Expand Down Expand Up @@ -1364,7 +1364,7 @@ def del_properties(self, pathobj, props, recursive):
[
pathobj.drive.rstrip("/"),
"api/storage",
str(pathobj.relative_to(pathobj.drive)).strip("/"),
pathobj.repo + pathobj.path_in_repo.rstrip("/"),
]
)

Expand Down Expand Up @@ -1397,7 +1397,7 @@ def update_properties(self, pathobj, properties, recursive=False):
[
pathobj.drive.rstrip("/"),
"api/metadata",
str(pathobj.relative_to(pathobj.drive)).strip("/"),
pathobj.repo + pathobj.path_in_repo.rstrip("/"),
]
)

Expand Down Expand Up @@ -1707,7 +1707,7 @@ def archive(self, archive_type="zip", check_sum=False):
raise NotImplementedError(archive_type + " is not support by current API")

archive_url = (
self.drive + "/api/archive/download/" + self.repo + self.path_in_repo
self.drive + "/api/archive/download/" + self.repo + self.path_in_repo.rstrip("/")
)
archive_obj = self.joinpath(archive_url)
archive_obj.session.params = {"archiveType": archive_type}
Expand All @@ -1717,20 +1717,6 @@ def archive(self, archive_type="zip", check_sum=False):

return archive_obj

def relative_to(self, *other):
"""
Return the relative path to another path identified by the passed
arguments. If the operation is not possible (because this is not
a subpath of the other path), raise ValueError.
"""
obj = super(ArtifactoryPath, self).relative_to(*other)
obj.auth = self.auth
obj.verify = self.verify
obj.cert = self.cert
obj.session = self.session
obj.timeout = self.timeout
return obj

def joinpath(self, *args):
"""
Combine this path with one or several arguments, and return a
Expand Down Expand Up @@ -2807,31 +2793,3 @@ def promote_build(
cert=self.cert,
timeout=self.timeout,
)


def walk(pathobj, topdown=True):
"""
os.walk like function to traverse the URI like a file system.

The only difference is that this function takes and returns Path objects
in places where original implementation will return strings
"""
dirs = []
nondirs = []
for child in pathobj:
relpath = str(child.relative_to(str(pathobj)))
if relpath.startswith("/"):
relpath = relpath[1:]
if relpath.endswith("/"):
relpath = relpath[:-1]
if child.is_dir():
dirs.append(relpath)
else:
nondirs.append(relpath)
if topdown:
yield pathobj, dirs, nondirs
for dir in dirs:
for result in walk(pathobj / dir):
yield result
if not topdown:
yield pathobj, dirs, nondirs
4 changes: 0 additions & 4 deletions tests/unit/test_artifactory_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -1211,10 +1211,6 @@ def test_auth_inheritance(self):
c = b.parent
self.assertEqual(c.auth, ("foo", "bar"))

b = P("http://b/artifactory/c/d", auth=("foo", "bar"))
c = b.relative_to("http://b/artifactory/c")
self.assertEqual(c.auth, ("foo", "bar"))

b = P("http://b/artifactory/c/d", auth=("foo", "bar"))
c = b.joinpath("d")
self.assertEqual(c.auth, ("foo", "bar"))
Expand Down
Loading