Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/cli/client.py
Show First 20 Lines • Show All 135 Lines • ▼ Show 20 Lines | def client_command_parse_input( | ||||
archive: Optional[str], | archive: Optional[str], | ||||
metadata: Optional[str], | metadata: Optional[str], | ||||
archive_deposit: bool, | archive_deposit: bool, | ||||
metadata_deposit: bool, | metadata_deposit: bool, | ||||
collection: Optional[str], | collection: Optional[str], | ||||
slug: Optional[str], | slug: Optional[str], | ||||
partial: bool, | partial: bool, | ||||
deposit_id: Optional[int], | deposit_id: Optional[int], | ||||
swhid: Optional[str], | |||||
replace: bool, | replace: bool, | ||||
url: str, | url: str, | ||||
name: Optional[str], | name: Optional[str], | ||||
authors: List[str], | authors: List[str], | ||||
temp_dir: str, | temp_dir: str, | ||||
) -> Dict[str, Any]: | ) -> Dict[str, Any]: | ||||
"""Parse the client subcommand options and make sure the combination | """Parse the client subcommand options and make sure the combination | ||||
is acceptable*. If not, an InputError exception is raised | is acceptable*. If not, an InputError exception is raised | ||||
Show All 31 Lines | Returns: | ||||
'metadata': the metadata file to deposit | 'metadata': the metadata file to deposit | ||||
'collection': the username's associated client | 'collection': the username's associated client | ||||
'slug': the slug or external id identifying the deposit to make | 'slug': the slug or external id identifying the deposit to make | ||||
'partial': if the deposit is partial or not | 'partial': if the deposit is partial or not | ||||
'client': instantiated class | 'client': instantiated class | ||||
'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 | ||||
'swhid': optional deposit swhid | |||||
""" | """ | ||||
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 | ||||
if not slug: # generate one as this is mandatory | if not slug: # generate one as this is mandatory | ||||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | return { | ||||
"password": password, | "password": password, | ||||
"metadata": metadata, | "metadata": metadata, | ||||
"collection": collection, | "collection": collection, | ||||
"slug": slug, | "slug": slug, | ||||
"in_progress": partial, | "in_progress": partial, | ||||
"client": client, | "client": client, | ||||
"url": url, | "url": url, | ||||
"deposit_id": deposit_id, | "deposit_id": deposit_id, | ||||
"swhid": swhid, | |||||
"replace": replace, | "replace": replace, | ||||
} | } | ||||
def _subdict(d: Dict[str, Any], keys: Tuple[str, ...]) -> Dict[str, Any]: | def _subdict(d: Dict[str, Any], keys: Tuple[str, ...]) -> Dict[str, Any]: | ||||
"return a dict from d with only given keys" | "return a dict from d with only given keys" | ||||
return {k: v for k, v in d.items() if k in keys} | return {k: v for k, v in d.items() if k in keys} | ||||
Show All 19 Lines | def deposit_update(config: Dict[str, Any]) -> Dict[str, Any]: | ||||
keys = ( | keys = ( | ||||
"collection", | "collection", | ||||
"deposit_id", | "deposit_id", | ||||
"archive", | "archive", | ||||
"metadata", | "metadata", | ||||
"slug", | "slug", | ||||
"in_progress", | "in_progress", | ||||
"replace", | "replace", | ||||
"swhid", | |||||
) | ) | ||||
return client.deposit_update(**_subdict(config, keys)) | return client.deposit_update(**_subdict(config, keys)) | ||||
@deposit.command() | @deposit.command() | ||||
@click.option("--username", required=True, help="(Mandatory) User's name") | @click.option("--username", required=True, help="(Mandatory) User's name") | ||||
@click.option( | @click.option( | ||||
"--password", required=True, help="(Mandatory) User's associated password" | "--password", required=True, help="(Mandatory) User's associated password" | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | @click.option( | ||||
), | ), | ||||
) # noqa | ) # noqa | ||||
@click.option( | @click.option( | ||||
"--deposit-id", | "--deposit-id", | ||||
default=None, | default=None, | ||||
help="(Optional) Update an existing partial deposit with its identifier", | help="(Optional) Update an existing partial deposit with its identifier", | ||||
) # noqa | ) # noqa | ||||
@click.option( | @click.option( | ||||
"--swhid", | |||||
default=None, | |||||
help="(Optional) Update existing completed deposit (status done) with new metadata", | |||||
) | |||||
@click.option( | |||||
"--replace/--no-replace", | "--replace/--no-replace", | ||||
default=False, | default=False, | ||||
help="(Optional) Update by replacing existing metadata to a deposit", | help="(Optional) Update by replacing existing metadata to a deposit", | ||||
) # noqa | ) # noqa | ||||
@click.option( | @click.option( | ||||
"--url", | "--url", | ||||
default="https://deposit.softwareheritage.org", | default="https://deposit.softwareheritage.org", | ||||
help=( | help=( | ||||
Show All 25 Lines | def upload( | ||||
archive: Optional[str] = None, | archive: Optional[str] = None, | ||||
metadata: Optional[str] = None, | metadata: Optional[str] = None, | ||||
archive_deposit: bool = False, | archive_deposit: bool = False, | ||||
metadata_deposit: bool = False, | metadata_deposit: bool = False, | ||||
collection: Optional[str] = None, | collection: Optional[str] = None, | ||||
slug: Optional[str] = None, | slug: Optional[str] = None, | ||||
partial: bool = False, | partial: bool = False, | ||||
deposit_id: Optional[int] = None, | deposit_id: Optional[int] = None, | ||||
swhid: Optional[str] = None, | |||||
replace: bool = False, | replace: bool = False, | ||||
url: str = "https://deposit.softwareheritage.org", | url: str = "https://deposit.softwareheritage.org", | ||||
verbose: bool = False, | verbose: bool = False, | ||||
name: Optional[str] = None, | name: Optional[str] = None, | ||||
author: List[str] = [], | author: List[str] = [], | ||||
output_format: Optional[str] = None, | output_format: Optional[str] = None, | ||||
): | ): | ||||
"""Software Heritage Public Deposit Client | """Software Heritage Public Deposit Client | ||||
Show All 20 Lines | with tempfile.TemporaryDirectory() as temp_dir: | ||||
archive, | archive, | ||||
metadata, | metadata, | ||||
archive_deposit, | archive_deposit, | ||||
metadata_deposit, | metadata_deposit, | ||||
collection, | collection, | ||||
slug, | slug, | ||||
partial, | partial, | ||||
deposit_id, | deposit_id, | ||||
swhid, | |||||
replace, | replace, | ||||
url, | url, | ||||
name, | name, | ||||
author, | author, | ||||
temp_dir, | temp_dir, | ||||
) | ) | ||||
except InputError as e: | except InputError as e: | ||||
logger.error("Problem during parsing options: %s", e) | logger.error("Problem during parsing options: %s", e) | ||||
▲ Show 20 Lines • Show All 76 Lines • Show Last 20 Lines |