Skip to content

Commit

Permalink
Remove relative to
Browse files Browse the repository at this point in the history
  • Loading branch information
zhan9san committed Feb 20, 2024
1 parent b116902 commit 1fce50d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 57 deletions.
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

0 comments on commit 1fce50d

Please sign in to comment.