Skip to content

Commit

Permalink
[#65] retrieving file checksums on-demand
Browse files Browse the repository at this point in the history
  • Loading branch information
pkdash committed May 21, 2024
1 parent 78b1242 commit 7e07551
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions hsclient/hydroshare.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,13 @@ class File(str):
:param checksum: the md5 checksum of the file
"""

def __new__(cls, value, file_url, checksum):
def __new__(cls, value, file_url, checksum, aggregation):
return super(File, cls).__new__(cls, value)

def __init__(self, value, file_url, checksum):
def __init__(self, value, file_url, checksum, aggregation):
self._file_url = file_url
self._checksum = checksum
self._aggregation = aggregation

@property
def path(self) -> str:
Expand All @@ -93,6 +94,10 @@ def folder(self) -> str:
@property
def checksum(self):
"""The md5 checksum of the file"""
if self._checksum is None:
_ = self._aggregation._checksums
path = urljoin('data/contents', quote(self.path))
self._checksum = self._aggregation._checksums.get(path, "")
return self._checksum

@property
Expand Down Expand Up @@ -174,21 +179,26 @@ def _files(self):
"data/contents/",
)[1]
)
f = File(file_path, unquote(file.path), self._checksums[file_checksum_path])
if self._parsed_checksums is not None:
checksum = self._checksums[file_checksum_path]
else:
checksum = None
f = File(file_path, unquote(file.path), checksum, self)

self._parsed_files.append(f)
return self._parsed_files

@property
def _aggregations(self):

def populate_metadata(_aggr):
_aggr._metadata
_ = _aggr._metadata

if self._parsed_aggregations is None:
self._parsed_aggregations = []
for file in self._map.describes.files:
if is_aggregation(str(file)):
self._parsed_aggregations.append(Aggregation(unquote(file.path), self._hs_session, self._checksums))
self._parsed_aggregations.append(Aggregation(unquote(file.path), self._hs_session, None))

# load metadata for all aggregations (metadata is needed to create any typed aggregation)
with ThreadPoolExecutor() as executor:
Expand Down Expand Up @@ -1109,7 +1119,7 @@ def file_rename(self, path: str, new_path: str, refresh=False) -> None:

# update the parsed_files
checksum_path = urljoin("data", "contents", new_path)
new_file = File(new_path, unquote(new_path), self._checksums[checksum_path])
new_file = File(new_path, unquote(new_path), self._checksums[checksum_path], self)
self._parsed_files = [new_file if file == path else file for file in self._parsed_files]

@refresh
Expand Down

0 comments on commit 7e07551

Please sign in to comment.