Commit 0aa931a6 authored by Laros's avatar Laros
Browse files

Added sanity check.

parent bf16401b
......@@ -124,6 +124,12 @@ def completed(output_handle, server_name, client_id, ssl_check):
TransferClient(server_name, ssl_check).completed(client_id))
def _minimal_metadata(title):
if title:
return {'title': title, 'files': []}
return {'files': []}
def _make_metadata(log_handle, file_handles, title):
Given a list of files, generate the metadata according to the minimal
......@@ -135,7 +141,7 @@ def _make_metadata(log_handle, file_handles, title):
:returns dict: Metadata in JSON format.
metadata = {'title': title, 'files': []}
metadata = _minimal_metadata(title)
for file_handle in file_handles:
......@@ -177,10 +183,20 @@ def transfer(log_handle, file_handles, server_name, user_id, title, ssl_check):
:arg bool ssl_check: Check server SSL certificate.
transfer_client = TransferClient(server_name, ssl_check)
# Sanity check before we do anything.
test_metadata = _minimal_metadata(None)
{'filename': 'a', 'md5': '00000000000000000000000000000000'})
jsonschema.validate(test_metadata, transfer_client.schema(user_id))
# Make the metadata.
fake_handle = io.StringIO(
json.dumps(_make_metadata(log_handle, file_handles, title)).decode()) = 'metadata.json'
# Transfer the files.
# TODO: dump metadata on error.
transfer_id = transfer_client.transfers(user_id, fake_handle)['id']
log_handle.write('Transfer ID: {}.\n'.format(transfer_id))
for file_handle in file_handles:
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment