Skip to content

Commit 6feda60

Browse files
committed
Merge pull request #53 from Duke-GCB/update_files
Update files
2 parents c77995f + b95eb43 commit 6feda60

File tree

7 files changed

+49
-16
lines changed

7 files changed

+49
-16
lines changed

ddsc/core/ddsapi.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,19 @@ def create_file(self, parent_kind, parent_id, upload_id):
378378
}
379379
return self._post("/files/", data)
380380

381+
def update_file(self, file_id, upload_id):
382+
"""
383+
Send PUT request to /files/{file_id} to update the file contents to upload_id and sets a label.
384+
:param file_id: str uuid of file
385+
:param upload_id: str uuid of the upload where all the file chunks where uploaded
386+
:param label: str short display label for the file
387+
:return: requests.Response containing the successful result
388+
"""
389+
put_data = {
390+
"upload[id]": upload_id,
391+
}
392+
return self._put("/files/" + file_id, put_data, content_type=ContentType.form)
393+
381394
def send_external(self, http_verb, host, url, http_headers, chunk):
382395
"""
383396
Used with create_upload_url to send a chunk the the possibly external object store.

ddsc/core/fileuploader.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,13 @@ def upload(self, project_id, parent_kind, parent_id):
5656
chunk_processor = self._make_chunk_processor()
5757
chunk_processor.run()
5858
self.data_service.complete_upload(self.upload_id)
59-
result = self.data_service.create_file(parent_kind, parent_id, self.upload_id)
60-
return result.json()['id']
59+
if self.local_file.remote_id:
60+
file_id = self.local_file.remote_id
61+
self.data_service.update_file(file_id, self.upload_id)
62+
return file_id
63+
else:
64+
result = self.data_service.create_file(parent_kind, parent_id, self.upload_id)
65+
return result.json()['id']
6166

6267
@staticmethod
6368
def send_file_external(data_service, url_json, chunk):

ddsc/core/localstore.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -209,18 +209,10 @@ def update_remote_ids(self, remote_file):
209209
Based on a remote file try to assign a remote_id and compare hash info.
210210
:param remote_file: RemoteFile remote data pull remote_id from
211211
"""
212-
# Since right now the remote server allows duplicates
213-
# this could be called multiple times for the same local file
214-
# as long as one matches we have the file uploaded.
215-
216-
# if we don't have a uuid yet any will do
217-
if not self.need_to_send:
218-
self.remote_id = remote_file.id
219-
# but we prefer the one that matches our hash
212+
self.remote_id = remote_file.id
220213
(alg, file_hash) = self.get_hashpair()
221214
if alg == remote_file.hash_alg and file_hash == remote_file.file_hash:
222215
self.need_to_send = False
223-
self.remote_id = remote_file.id
224216

225217
def set_remote_id_after_send(self, remote_id):
226218
"""

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
setup(name='DukeDSClient',
5-
version='0.2.5',
5+
version='0.2.6',
66
description='Command line tool(ddsclient) to upload/manage projects on the duke-data-service.',
77
url='https://github.com/Duke-GCB/DukeDSClient',
88
keywords='duke dds dukedataservice',

test_scripts/inside_docker.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ echo "upload_workers: $UPLOAD_WORKERS" >> $CONFIG_FILE
99

1010
set -e
1111
echo "Installing ddsclient"
12-
eval $TEST_PYTHON setup.py install 2>/dev/null >/dev/null
12+
$TEST_PYTHON setup.py install 2>/dev/null >/dev/null
1313

1414
echo "Running tests"
1515
$TEST_PYTHON -m unittest discover test_scripts/tests/
16+

test_scripts/run.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,22 @@ run_test()
6565
-e TEST_PYTHON=$TEST_PYTHON -e DDS_IP=$DDS_IP \
6666
-e DDS_USER_KEY=$DDS_USER_KEY -e DDS_AGENT_KEY=$DDS_AGENT_KEY \
6767
-v $CUR_DIR/../DukeDSClientData:/tmp/DukeDSClientData \
68-
dds_test | tee -a $TEMPFILE
69-
if [ "$?" -ne "0" ]
68+
dds_test > $TEMPFILE
69+
RET=$?
70+
echo "Test exit status $RET"
71+
if [ "$RET" -ne "0" ]
7072
then
7173
echo "ERROR: $TEST_PYTHON tests failed"
72-
echo "see $TEMP for more"
74+
tail -n 10 $TEMPFILE
75+
echo "see $TEMPFILE for more"
7376
exit 1
7477
fi
7578
delete_user_data
7679
rm $TEMPFILE
7780
}
7881

82+
docker rm $(docker ps -a -q --filter="name=dukedataservice_") 2>/dev/null
83+
7984
build_docker_file
8085
start_dds
8186

test_scripts/tests/test_upload.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,26 @@ def test_upload_download_docs(self):
8181
shutil.rmtree("../my_docs")
8282

8383
def test_upload_download_bigfile(self):
84+
"""
85+
Uploads a really big file. This takes quite a while to run.
86+
"""
8487
self.assertUploadWorks("upload -p bigfile /tmp/DukeDSClientData/bigfile.tar")
8588
self.assertDownloadWorks("download -p bigfile /tmp/bf")
8689
self.assertFilesSame('/tmp/DukeDSClientData/bigfile.tar', '/tmp/bf/bigfile.tar')
8790

91+
def test_update_file(self):
92+
"""
93+
Test that we can update the contents of a file after uploading it.
94+
"""
95+
with open("/tmp/abc.txt", "w") as data_file:
96+
data_file.write("one line")
97+
self.assertUploadWorks("upload -p change_it /tmp/abc.txt")
98+
with open("/tmp/abc.txt", "w") as data_file:
99+
data_file.write("one line")
100+
data_file.write("two line")
101+
self.assertUploadWorks("upload -p change_it /tmp/abc.txt")
102+
self.assertDownloadWorks("download -p change_it /tmp/change_it")
103+
self.assertFilesSame('/tmp/abc.txt', '/tmp/change_it/abc.txt')
104+
88105
if __name__ == '__main__':
89106
unittest.main()

0 commit comments

Comments
 (0)