Skip to content

Commit

Permalink
records: make arguments ready for drafts too
Browse files Browse the repository at this point in the history
  • Loading branch information
utnapischtim committed Jun 1, 2023
1 parent d1d18aa commit 2203789
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .ruff.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
select = ["ALL"]
ignore = ["ANN101", "ANN102", "D203", "D211", "D212", "D213", "D401", "INP001", "UP009", "S101", "BLE001"]
ignore = ["ANN101", "ANN102", "D203", "D211", "D212", "D213", "D401", "INP001", "UP009", "S101", "BLE001", "SLF001"]

exclude = ["docs"]
39 changes: 24 additions & 15 deletions repository_cli/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,11 +482,14 @@ def delete_file(data_model: str, pid: str, filename: str) -> None:
service = get_records_service(data_model=data_model)

try:
record = service.read(identity=identity, id_=pid)._record # noqa: SLF001
except PIDDoesNotExistError as error:
msg = f"Record id '{error.pid_value} ({data_model})' does not exist."
secho(msg, fg=Color.error)
return
record = service.read(identity=identity, id_=pid)._record
except PIDDoesNotExistError:
try:
record = service.read_draft(identity=identity, id_=pid)._record
except PIDDoesNotExistError as error:
msg = f"Record id '{error.pid_value} ({data_model})' does not exist."
secho(msg, fg=Color.error)
return

files = record.files
obj = None
Expand Down Expand Up @@ -526,11 +529,14 @@ def replace_file(
service = get_records_service(data_model=data_model)

try:
record = service.read(identity=identity, id_=pid)._record # noqa: SLF001
except PIDDoesNotExistError as error:
msg = f"Record id '{error.pid_value} ({data_model})' does not exist."
secho(msg, fg=Color.error)
return
record = service.read(identity=identity, id_=pid)._record
except PIDDoesNotExistError:
try:
record = service.read_draft(identity=identity, id_=pid)._record
except PIDDoesNotExistError as error:
msg = f"Record id '{error.pid_value} ({data_model})' does not exist."
secho(msg, fg=Color.error)
return

files = record.files
filename = Path(input_file.name).name # Path().name gets the filename only
Expand Down Expand Up @@ -581,11 +587,14 @@ def add_file(
service = get_records_service(data_model=data_model)

try:
record = service.read(identity=identity, id_=pid)._record # noqa: SLF001
except PIDDoesNotExistError as error:
msg = f"Record id '{error.pid_value} ({data_model})' does not exist."
secho(msg, fg=Color.error)
return
record = service.read(identity=identity, id_=pid)._record
except PIDDoesNotExistError:
try:
record = service.read_draft(identity=identity, id_=pid)._record
except PIDDoesNotExistError as error:
msg = f"Record id '{error.pid_value} ({data_model})' does not exist."
secho(msg, fg=Color.error)
return

files = record.files
filename = Path(input_file.name).name
Expand Down

0 comments on commit 2203789

Please sign in to comment.