Skip to content

Commit

Permalink
revert braindead last commit
Browse files Browse the repository at this point in the history
  • Loading branch information
BerndSchuller committed Apr 12, 2024
1 parent b402203 commit 6777ab4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
4 changes: 2 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Issue tracker: https://github.com/HumanBrainProject/pyunicore

Version 1.1.0 (mmm dd, 2024)
----------------------------
- new feature: added upload() method on PathFile object
- API CHANGE: remove Storage.upload() method
- API CHANGE: Storage.upload() method now accepts str-like or
file-like data to upload and requires destination name

Version 1.0.1 (Mar 22, 2024)
----------------------------
Expand Down
30 changes: 16 additions & 14 deletions pyunicore/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,8 @@ def new_job(self, job_description, inputs=[], autostart=True):
if len(inputs) > 0:
working_dir = job.working_dir
for input_item in inputs:
working_dir.upload(input_item)
with open(input_item, "rb") as f:
working_dir.upload(f, input_item)
if autostart and job_description.get("haveClientStageIn", None) == "true":
job.start()
return job
Expand Down Expand Up @@ -725,6 +726,20 @@ def makedirs(self, name):
"""create directory"""
return self.mkdir(name)

def upload(self, source, destination):
"""upload data to the destination file on this storage
Args:
source (str-like or file-like): this will be uploaded
destination: target path (parent directory will be created if needed)
"""
_headers = {"Content-Type": "application/octet-stream"}
with self.transport.put(
url=self._to_file_url(destination), headers=_headers, stream=True, data=source
) as r:
r.close()

def send_file(
self,
file_name,
Expand Down Expand Up @@ -888,19 +903,6 @@ def download(self, file):
for chunk in resp.iter_content(chunk_size):
file.write(chunk)

def upload(self, source):
"""upload data or file
Args:
source (str-like or file-like): this will be uploaded
"""
_headers = {"Content-Type": "application/octet-stream"}
with self.transport.put(
url=self.resource_url, headers=_headers, stream=True, data=source
) as r:
r.close()

def raw(self, offset=0, size=-1):
"""access the raw http response for a streaming download.
The optional 'offset' and 'size' parameters allow to download only
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ def test_upload_download(self):
home = self.get_home_storage()
_path = "tests/integration/files/script.sh"
_length = os.stat(_path).st_size
remote_file = home.stat("script.sh")
with open(_path, "rb") as f:
remote_file.upload(f)
home.upload(f, "script.sh")
remote_file = home.stat("script.sh")
self.assertEqual(_length, int(remote_file.properties["size"]))
_out = BytesIO()
remote_file.download(_out)
Expand All @@ -58,8 +58,8 @@ def test_upload_download_data(self):
home = self.get_home_storage()
_data = "this is some test data"
_length = len(_data)
home.upload(_data, "test.txt")
remote_file = home.stat("test.txt")
remote_file.upload(_data)
self.assertEqual(_length, int(remote_file.properties["size"]))
_out = BytesIO()
remote_file.download(_out)
Expand All @@ -71,7 +71,7 @@ def test_transfer(self):
_path = "tests/integration/files/script.sh"
_length = os.stat(_path).st_size
with open(_path, "rb") as f:
storage1.stat("script.sh").upload(f)
storage1.upload(f, "script.sh")
site_client = self.get_client()
storage2 = site_client.new_job({}).working_dir
transfer = storage2.receive_file(storage1.resource_url + "/files/script.sh", "script.sh")
Expand Down

0 comments on commit 6777ab4

Please sign in to comment.