Skip to content

Commit 6777ab4

Browse files
committed
revert braindead last commit
1 parent b402203 commit 6777ab4

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed

CHANGES.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ Issue tracker: https://github.com/HumanBrainProject/pyunicore
55

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

1111
Version 1.0.1 (Mar 22, 2024)
1212
----------------------------

pyunicore/client.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,8 @@ def new_job(self, job_description, inputs=[], autostart=True):
407407
if len(inputs) > 0:
408408
working_dir = job.working_dir
409409
for input_item in inputs:
410-
working_dir.upload(input_item)
410+
with open(input_item, "rb") as f:
411+
working_dir.upload(f, input_item)
411412
if autostart and job_description.get("haveClientStageIn", None) == "true":
412413
job.start()
413414
return job
@@ -725,6 +726,20 @@ def makedirs(self, name):
725726
"""create directory"""
726727
return self.mkdir(name)
727728

729+
def upload(self, source, destination):
730+
"""upload data to the destination file on this storage
731+
732+
Args:
733+
source (str-like or file-like): this will be uploaded
734+
destination: target path (parent directory will be created if needed)
735+
736+
"""
737+
_headers = {"Content-Type": "application/octet-stream"}
738+
with self.transport.put(
739+
url=self._to_file_url(destination), headers=_headers, stream=True, data=source
740+
) as r:
741+
r.close()
742+
728743
def send_file(
729744
self,
730745
file_name,
@@ -888,19 +903,6 @@ def download(self, file):
888903
for chunk in resp.iter_content(chunk_size):
889904
file.write(chunk)
890905

891-
def upload(self, source):
892-
"""upload data or file
893-
894-
Args:
895-
source (str-like or file-like): this will be uploaded
896-
897-
"""
898-
_headers = {"Content-Type": "application/octet-stream"}
899-
with self.transport.put(
900-
url=self.resource_url, headers=_headers, stream=True, data=source
901-
) as r:
902-
r.close()
903-
904906
def raw(self, offset=0, size=-1):
905907
"""access the raw http response for a streaming download.
906908
The optional 'offset' and 'size' parameters allow to download only

tests/integration/test_storage.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ def test_upload_download(self):
4545
home = self.get_home_storage()
4646
_path = "tests/integration/files/script.sh"
4747
_length = os.stat(_path).st_size
48-
remote_file = home.stat("script.sh")
4948
with open(_path, "rb") as f:
50-
remote_file.upload(f)
49+
home.upload(f, "script.sh")
50+
remote_file = home.stat("script.sh")
5151
self.assertEqual(_length, int(remote_file.properties["size"]))
5252
_out = BytesIO()
5353
remote_file.download(_out)
@@ -58,8 +58,8 @@ def test_upload_download_data(self):
5858
home = self.get_home_storage()
5959
_data = "this is some test data"
6060
_length = len(_data)
61+
home.upload(_data, "test.txt")
6162
remote_file = home.stat("test.txt")
62-
remote_file.upload(_data)
6363
self.assertEqual(_length, int(remote_file.properties["size"]))
6464
_out = BytesIO()
6565
remote_file.download(_out)
@@ -71,7 +71,7 @@ def test_transfer(self):
7171
_path = "tests/integration/files/script.sh"
7272
_length = os.stat(_path).st_size
7373
with open(_path, "rb") as f:
74-
storage1.stat("script.sh").upload(f)
74+
storage1.upload(f, "script.sh")
7575
site_client = self.get_client()
7676
storage2 = site_client.new_job({}).working_dir
7777
transfer = storage2.receive_file(storage1.resource_url + "/files/script.sh", "script.sh")

0 commit comments

Comments
 (0)