From eccfcc543fd954519632308532ed634a6653ce64 Mon Sep 17 00:00:00 2001 From: Raykov-MS Date: Mon, 22 Jun 2026 10:48:49 +0300 Subject: [PATCH] fixes --- app/app_config.py | 2 +- app/path_settings.py | 6 ++-- app/pipeline/file_manager.py | 5 ++- app/pipeline/service.py | 62 +++++++++++++++++++++++------------- main.py | 19 +++++++++-- 5 files changed, 65 insertions(+), 29 deletions(-) diff --git a/app/app_config.py b/app/app_config.py index 5e5c357..3434e86 100644 --- a/app/app_config.py +++ b/app/app_config.py @@ -5,7 +5,7 @@ from pathlib import Path import streamlit as st SFM_SMB_BASE_PATH = "//sgo-fc01-r13/inbox-intech" -SFM_DEFAULT_INPUT_DIR = r"Exchange\SMBDEMO\test" +SFM_DEFAULT_INPUT_DIR = r"//sgo-fc01-r13/inbox-intech" ACCESS_SUPPORT_CONTACT = "администратору СФМ" USER_PATHS_KEY = "user_input_dirs" diff --git a/app/path_settings.py b/app/path_settings.py index f7e3516..a08d4bc 100644 --- a/app/path_settings.py +++ b/app/path_settings.py @@ -44,10 +44,10 @@ def render_path_editor() -> str | None: edited_path = st.text_input( "Путь", key=EDIT_PATH_VALUE_KEY, - placeholder=r"Exchange\SMBDEMO\test", + placeholder=r"//sgo-fc01-r13/inbox-intech/Exchange/SMBDEMO/test", help=( - "Укажите путь внутри SMB-шары относительно базового пути " - f"`{SFM_SMB_BASE_PATH}`." + "Укажите абсолютный UNC-путь к папке обработки, например " + f"`{SFM_SMB_BASE_PATH}/Exchange/SMBDEMO/test`." ), ) save_col, cancel_col = st.columns(2) diff --git a/app/pipeline/file_manager.py b/app/pipeline/file_manager.py index 2b2ddc1..6ac8892 100644 --- a/app/pipeline/file_manager.py +++ b/app/pipeline/file_manager.py @@ -199,7 +199,8 @@ def check_network_dir_access( def create_run_context( input_dir: str, samba_conn, now: datetime | None = None ) -> RunContext: - base_dir = get_parent_dir(input_dir) + # Артефакты формируем внутри указанного пользователем пути обработки. + base_dir = input_dir out_day_dir = build_out_dir(base_dir, now) error_dir = build_error_dir(base_dir) processed_dir = build_processed_dir(base_dir) @@ -240,6 +241,8 @@ def scan_input_files(input_dir: str, samba_conn) -> InputFileScanResult: invalid_files: list[RemoteFile] = [] for file_name in _list_samba_files(input_dir, samba_conn): + if not file_name.lower().endswith(".xml"): + continue remote_path = join_path(input_dir, file_name) if validate_file_name(file_name): valid_files.append(RemoteFile(path=remote_path, name=file_name)) diff --git a/app/pipeline/service.py b/app/pipeline/service.py index 184656a..83b5a46 100644 --- a/app/pipeline/service.py +++ b/app/pipeline/service.py @@ -86,7 +86,7 @@ def run_batch( scan_result = scan_input_files(input_dir=input_dir, samba_conn=samba_conn) log_lines.append( - f"{_now()} | scan files: valid={len(scan_result.valid_files)} invalid={len(scan_result.invalid_files)}" + f"{_now()} | scan files: valid={len(scan_result.valid_files)} invalid={len(scan_result.invalid_files)} " ) for remote_file in scan_result.invalid_files: @@ -108,12 +108,50 @@ def run_batch( processed_at=datetime.now(), ) ) - log_lines.append(f"{_now()} | invalid -> err: {remote_file.path} => {moved_to}") + if moved_to: + log_lines.append( + f"{_now()} | invalid -> err: {remote_file.path} => {moved_to}" + ) for remote_file in scan_result.valid_files: parse_result = _parse_remote_xml(remote_file.name, remote_file.path, samba_conn) report_rows.extend(_report_rows_from_parse(parse_result)) status, message = _resolve_parse_status(parse_result) + if status == "success": + try: + moved_to = move_file_to_processed( + file_path=remote_file.path, + file_name=remote_file.name, + processed_dir=run_context.processed_dir, + samba_conn=samba_conn, + ) + log_lines.append( + f"{_now()} | success -> processed: {remote_file.path} => {moved_to}" + ) + except Exception as exc: # noqa: BLE001 + status = "partial" + message = f"{message} Не удалось переместить в Processed: {exc}" + log_lines.append( + f"{_now()} | move to Processed failed: {remote_file.path}. {exc}" + ) + else: + try: + moved_to = move_file_to_error( + file_path=remote_file.path, + file_name=remote_file.name, + error_dir=run_context.error_dir, + samba_conn=samba_conn, + ) + log_lines.append( + f"{_now()} | {status} -> err: {remote_file.path} => {moved_to}" + ) + except Exception as exc: # noqa: BLE001 + message = f"{message} Не удалось переместить в Err: {exc}" + if status == "success": + status = "partial" + log_lines.append( + f"{_now()} | move to Err failed: {remote_file.path}. {exc}" + ) protocol_rows.append( ProtocolRow( file_name=remote_file.name, @@ -125,26 +163,6 @@ def run_batch( processed_at=datetime.now(), ) ) - if status == "success": - moved_to = move_file_to_processed( - file_path=remote_file.path, - file_name=remote_file.name, - processed_dir=run_context.processed_dir, - samba_conn=samba_conn, - ) - log_lines.append( - f"{_now()} | success -> processed: {remote_file.path} => {moved_to}" - ) - else: - moved_to = move_file_to_error( - file_path=remote_file.path, - file_name=remote_file.name, - error_dir=run_context.error_dir, - samba_conn=samba_conn, - ) - log_lines.append( - f"{_now()} | {status} -> err: {remote_file.path} => {moved_to}" - ) if not protocol_rows: protocol_rows.append( diff --git a/main.py b/main.py index 4c29118..de1ad60 100644 --- a/main.py +++ b/main.py @@ -59,7 +59,7 @@ def main() -> None: st.success("Путь сохранен.") st.rerun() else: - st.error(f"{message} Обратитесь к {ACCESS_SUPPORT_CONTACT}.") + st.error(_format_access_error(message)) resolved_input_dir = get_resolved_input_dir(user_id) st.caption(f"Текущий путь: `{resolved_input_dir}`") @@ -105,7 +105,7 @@ def main() -> None: samba_password=samba_password, ) if not ok: - st.error(f"{message} Обратитесь к {ACCESS_SUPPORT_CONTACT}.") + st.error(_format_access_error(message)) else: if files: st.success(f"Папка доступна. Найдено файлов: {len(files)}") @@ -118,5 +118,20 @@ def main() -> None: st.rerun() +def _format_access_error(message: str) -> str: + lowered = (message or "").lower() + user_input_keywords = ( + "логин", + "парол", + "status_logon_failure", + "logon", + "authentication", + "auth", + ) + if any(keyword in lowered for keyword in user_input_keywords): + return message + return f"{message} Обратитесь к {ACCESS_SUPPORT_CONTACT}." + + if __name__ == "__main__": main()