publish_controller(file_path: PublishFilePathOpt = DEFAULT_PUBLISH_FILE_PATH, dry_run: DryRunOpt = DEFAULT_DRY_RUN, id_element: IdOpt = None) -> None
Publishes an Excel file into the SFTP server of iMarina service. If the Excel is not provided it will be deduced from the output folder using the date in the filename or the last modification date. By default, only connects to the SFTP server but does not do the upload. To upload the file the parameter --dry-run false must be provided.
If id_element is given and file_path is not, the file to publish is instead sourced from that request's "iMarina Excel output link" field (see CLAUDE.md's publish section). Publishing an explicit file_path with no id_element keeps no record of the publish on any MS List request, which CLAUDE.md flags as something that can cause problems -- a warning is shown in that case.
Source code in source/src/imarina_load_researchers/commands/publish/cli.py
| def publish_controller(
file_path: PublishFilePathOpt = DEFAULT_PUBLISH_FILE_PATH,
dry_run: DryRunOpt = DEFAULT_DRY_RUN,
id_element: IdOpt = None,
) -> None:
"""
Publishes an Excel file into the SFTP server of iMarina service.
If the Excel is not provided it will be deduced from the output folder using the date in the filename or the last
modification date.
By default, only connects to the SFTP server but does not do the upload. To upload the file the parameter --dry-run
false must be provided.
If `id_element` is given and `file_path` is not, the file to publish is
instead sourced from that request's "iMarina Excel output link" field
(see CLAUDE.md's `publish` section). Publishing an explicit `file_path`
with no `id_element` keeps no record of the publish on any MS List
request, which CLAUDE.md flags as something that can cause problems --
a warning is shown in that case.
"""
file_path = _resolve_file_path(file_path, id_element)
if id_element is not None:
try:
update_list_item_fields(
str(id_element), {FIELD_WORKFLOW_STATE: WorkflowState.PUBLISHING}
)
except Exception:
# Best-effort bookkeeping: must not block the actual publish below.
logger.exception("Error updating Workflow State to Publishing")
credentials = FtpCredentials(
host=read_secret(SecretName.FTP_HOST),
port=int(read_secret(SecretName.FTP_PORT)),
username=read_secret(SecretName.FTP_USER),
password=read_secret(SecretName.FTP_PASSWORD),
)
try:
upload_file_ftp(
path=file_path,
credentials=credentials,
dry_run=dry_run,
upload_filename=FTP_UPLOAD_PATH,
)
# Broad on purpose: CLI boundary turns any failure into a clean exit(1).
except Exception as e:
logger.exception("Error publishing file to iMarina FTP server")
raise typer.Exit(code=1) from e
if dry_run:
# upload_file_ftp() returns normally without uploading on a dry run --
# nothing was actually published, so there is nothing to archive or
# record.
return
_archive_published_file(file_path, id_element)
|