Skip to content

Commit

Permalink
make artifact properties work as a dict for #293
Browse files Browse the repository at this point in the history
  • Loading branch information
beliaev-maksim committed Oct 1, 2021
1 parent e3ec6cd commit 0fb5af0
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion artifactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -1441,6 +1441,38 @@ def _init(self, *args, **kwargs):

super(ArtifactoryPath, self)._init(*args, **kwargs)

class _ArtifactProperties(dict):
def __init__(self, pathobj, *args, **kwargs):
self.pathobj = pathobj
super().__init__(*args, **kwargs)

def __setitem__(self, key, item):
self.pathobj.update_properties({key: item})
super().__setitem__(key, item)

def __delitem__(self, key):
self.pathobj.del_properties([key])
super().__delitem__(key)

def clear(self):
self.pathobj.del_properties(self)
return super().clear()

def copy(self):
raise ArtifactoryException(f"It is not allowed to copy {__class__}")

def update(self, *args, **kwargs):
super().update(*args, **kwargs)
# first run super(), since signature is unknown
self.pathobj.update_properties(super().copy())

def pop(self, *args):
self.pathobj.del_properties(args)
return super().pop(*args)

def __repr__(self):
return str(self.pathobj._accessor.get_properties(self.pathobj))

@property
def top(self):
obj = ArtifactoryPath(self.drive)
Expand Down Expand Up @@ -1981,7 +2013,7 @@ def properties(self):
"""
Fetch artifact properties
"""
return self._accessor.get_properties(self)
return self._ArtifactProperties(self, self._accessor.get_properties(self))

@properties.setter
def properties(self, properties):
Expand Down

0 comments on commit 0fb5af0

Please sign in to comment.