Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/cli/client.py
Show First 20 Lines • Show All 187 Lines • ▼ Show 20 Lines | Returns: | ||||
'url': deposit's server main entry point | 'url': deposit's server main entry point | ||||
'deposit_type': deposit's type (binary, multipart, metadata) | 'deposit_type': deposit's type (binary, multipart, metadata) | ||||
'deposit_id': optional deposit identifier | 'deposit_id': optional deposit identifier | ||||
""" | """ | ||||
if archive_deposit and metadata_deposit: | if archive_deposit and metadata_deposit: | ||||
# too many flags use, remove redundant ones (-> multipart deposit) | # too many flags use, remove redundant ones (-> multipart deposit) | ||||
archive_deposit = False | archive_deposit = False | ||||
metadata_deposit = False | metadata_deposit = False | ||||
ardumont: meh, i just can add a scenario which mentions both and be done with this... | |||||
if not slug: # generate one as this is mandatory | if not slug: # generate one as this is mandatory | ||||
slug = generate_slug() | slug = generate_slug() | ||||
if not metadata: | if not metadata and not metadata_deposit and not replace: | ||||
if name and authors: | if name and authors: | ||||
metadata = generate_metadata_file(name, slug, authors, temp_dir) | metadata = generate_metadata_file(name, slug, authors, temp_dir) | ||||
elif not archive_deposit and not partial and not deposit_id: | elif not archive_deposit and not partial and not deposit_id: | ||||
# If we meet all the following conditions: | # If we meet all the following conditions: | ||||
# * there is not an archive-only deposit | # * this is not an archive-only deposit request | ||||
# * it is not part of a multipart deposit (either create/update | # * it is not part of a multipart deposit (either create/update | ||||
# or finish) | # or finish) | ||||
# * it misses either name or authors | # * it misses either name or authors | ||||
raise InputError( | raise InputError( | ||||
"Either a metadata file (--metadata) or both --author and " | "For metadata deposit request, either a metadata file with " | ||||
"--name must be provided, unless this is an archive-only " | "--metadata or both --author and --name must be provided. " | ||||
"deposit." | "If this is an archive deposit request, none is required." | ||||
) | ) | ||||
elif name or authors: | elif name or authors: | ||||
# If we are generating metadata, then all mandatory metadata | # If we are generating metadata, then all mandatory metadata | ||||
# must be present | # must be present | ||||
raise InputError( | raise InputError( | ||||
"Either a metadata file (--metadata) or both --author and " | "For metadata deposit request, either a metadata file with " | ||||
"--name must be provided." | "--metadata or both --author and --name must be provided." | ||||
) | ) | ||||
else: | else: | ||||
# TODO: this is a multipart deposit, we might want to check that | # TODO: this is a multipart deposit, we might want to check that | ||||
# metadata are deposited at some point | # metadata are deposited at some point | ||||
pass | pass | ||||
ardumontAuthorUnsubmitted Done Inline Actionsno idea how to reach this... so meh. ardumont: no idea how to reach this... so meh. | |||||
elif name or authors: | elif name or authors: | ||||
raise InputError( | raise InputError( | ||||
"Using a metadata file (--metadata) is incompatible with " | "Using --metadata flag is incompatible with both " | ||||
"--author and --name, which are used to generate one." | "--author and --name (Those are used to generate one metadata file)." | ||||
) | ) | ||||
if metadata_deposit: | if metadata_deposit: | ||||
archive = None | archive = None | ||||
if archive_deposit: | if archive_deposit: | ||||
metadata = None | metadata = None | ||||
if metadata_deposit and not metadata: | if metadata_deposit and not metadata: | ||||
raise InputError( | raise InputError( | ||||
"Metadata deposit must be provided for metadata " | "Metadata deposit must be provided for metadata " | ||||
"deposit (either a filepath or --name and --author)" | "deposit, either a filepath with --metadata or --name and --author" | ||||
) | ) | ||||
if not archive and not metadata and partial: | if not archive and not metadata and partial: | ||||
raise InputError( | raise InputError( | ||||
"Please provide an actionable command. See --help for more information" | "Please provide an actionable command. See --help for more information" | ||||
) | ) | ||||
if replace and not deposit_id: | if replace and not deposit_id: | ||||
raise InputError("To update an existing deposit, you must provide its id") | raise InputError("To update an existing deposit, you must provide its id") | ||||
ardumontAuthorUnsubmitted Done Inline Actionsthat was not covered before. ardumont: that was not covered before. | |||||
client = _client(url, username, password) | client = _client(url, username, password) | ||||
if not collection: | if not collection: | ||||
collection = _collection(client) | collection = _collection(client) | ||||
return { | return { | ||||
"archive": archive, | "archive": archive, | ||||
"username": username, | "username": username, | ||||
"password": password, | "password": password, | ||||
"metadata": metadata, | "metadata": metadata, | ||||
"collection": collection, | "collection": collection, | ||||
"slug": slug, | "slug": slug, | ||||
ardumontAuthorUnsubmitted Done Inline Actionsi can let it generate the slug, most likely. ardumont: i can let it generate the slug, most likely. | |||||
"in_progress": partial, | "in_progress": partial, | ||||
"client": client, | "client": client, | ||||
"url": url, | "url": url, | ||||
"deposit_id": deposit_id, | "deposit_id": deposit_id, | ||||
"replace": replace, | "replace": replace, | ||||
} | } | ||||
▲ Show 20 Lines • Show All 249 Lines • Show Last 20 Lines |
meh, i just can add a scenario which mentions both and be done with this...