Skip to content

Commit

Permalink
Merge pull request #13 from hydroshare/windows-fix
Browse files Browse the repository at this point in the history
update for windows path compatibility
  • Loading branch information
sblack-usu authored Apr 29, 2021
2 parents 3f1466c + e55693c commit 50bf9b6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
19 changes: 9 additions & 10 deletions hsclient/hydroshare.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
from datetime import datetime
from posixpath import basename, dirname, join as urljoin, splitext
from typing import Dict, List, Union
from urllib.parse import urlparse
from urllib.request import pathname2url, url2pathname
from urllib.parse import urlparse, quote, unquote
from zipfile import ZipFile

import pandas
Expand Down Expand Up @@ -111,12 +110,12 @@ def _files(self):
if not file.path == self.metadata_path:
if not str(file.path).endswith('/'): # checking for folders, shouldn't have to do this
file_checksum_path = file.path.split(self._resource_path, 1)[1].strip("/")
file_path = url2pathname(
file_path = unquote(
file_checksum_path.split(
"data/contents/",
)[1]
)
f = File(file_path, url2pathname(file.path), self._checksums[file_checksum_path])
f = File(file_path, unquote(file.path), self._checksums[file_checksum_path])
self._parsed_files.append(f)
return self._parsed_files

Expand All @@ -127,7 +126,7 @@ def _aggregations(self):
for file in self._map.describes.files:
if is_aggregation(str(file)):
self._parsed_aggregations.append(
Aggregation(url2pathname(file.path), self._hs_session, self._checksums)
Aggregation(unquote(file.path), self._hs_session, self._checksums)
)
return self._parsed_aggregations

Expand Down Expand Up @@ -156,7 +155,7 @@ def _retrieve_and_parse(self, path):
def _retrieve_checksums(self, path):
file_str = self._hs_session.retrieve_string(path)
data = {
pathname2url(path): checksum
quote(path): checksum
for checksum, path in (line.split(" ") for line in file_str.split("\n") if line)
}
return data
Expand All @@ -174,7 +173,7 @@ def _download(self, save_path: str = "", unzip_to: str = None) -> str:

with zipfile.ZipFile(downloaded_zip, 'r') as zip_ref:
zip_ref.extractall(unzip_to)
os.remove(downloaded_zip)
os.remove(downloaded_zip)
return unzip_to
return downloaded_zip

Expand Down Expand Up @@ -576,8 +575,8 @@ def file_upload(self, *files: str, destination_path: str = "") -> None:
self._upload(files[0], destination_path=destination_path)
else:
with tempfile.TemporaryDirectory() as tmpdir:
zipped_file = urljoin(tmpdir, 'files.zip')
with ZipFile(urljoin(tmpdir, zipped_file), 'w') as zipped:
zipped_file = os.path.join(tmpdir, 'files.zip')
with ZipFile(zipped_file, 'w') as zipped:
for file in files:
zipped.write(file, basename(file))
self._upload(zipped_file, destination_path=destination_path)
Expand Down Expand Up @@ -679,7 +678,7 @@ def retrieve_file(self, path, save_path=""):

cd = file.headers['content-disposition']
filename = cd.split("filename=")[1].strip('"')
downloaded_file = urljoin(save_path, filename)
downloaded_file = os.path.join(save_path, filename)
with open(downloaded_file, 'wb') as f:
f.write(file.content)
return downloaded_file
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='hsclient',
version='0.1.5',
version='0.1.6',
packages=find_packages(include=['hsclient', 'hsclient.*'],
exclude=("tests",)),
install_requires=[
Expand Down

0 comments on commit 50bf9b6

Please sign in to comment.