fixes
This commit is contained in:
parent
ec5ab34686
commit
eccfcc543f
@ -5,7 +5,7 @@ from pathlib import Path
|
|||||||
import streamlit as st
|
import streamlit as st
|
||||||
|
|
||||||
SFM_SMB_BASE_PATH = "//sgo-fc01-r13/inbox-intech"
|
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 = "администратору СФМ"
|
ACCESS_SUPPORT_CONTACT = "администратору СФМ"
|
||||||
|
|
||||||
USER_PATHS_KEY = "user_input_dirs"
|
USER_PATHS_KEY = "user_input_dirs"
|
||||||
|
|||||||
@ -44,10 +44,10 @@ def render_path_editor() -> str | None:
|
|||||||
edited_path = st.text_input(
|
edited_path = st.text_input(
|
||||||
"Путь",
|
"Путь",
|
||||||
key=EDIT_PATH_VALUE_KEY,
|
key=EDIT_PATH_VALUE_KEY,
|
||||||
placeholder=r"Exchange\SMBDEMO\test",
|
placeholder=r"//sgo-fc01-r13/inbox-intech/Exchange/SMBDEMO/test",
|
||||||
help=(
|
help=(
|
||||||
"Укажите путь внутри SMB-шары относительно базового пути "
|
"Укажите абсолютный UNC-путь к папке обработки, например "
|
||||||
f"`{SFM_SMB_BASE_PATH}`."
|
f"`{SFM_SMB_BASE_PATH}/Exchange/SMBDEMO/test`."
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
save_col, cancel_col = st.columns(2)
|
save_col, cancel_col = st.columns(2)
|
||||||
|
|||||||
@ -199,7 +199,8 @@ def check_network_dir_access(
|
|||||||
def create_run_context(
|
def create_run_context(
|
||||||
input_dir: str, samba_conn, now: datetime | None = None
|
input_dir: str, samba_conn, now: datetime | None = None
|
||||||
) -> RunContext:
|
) -> RunContext:
|
||||||
base_dir = get_parent_dir(input_dir)
|
# Артефакты формируем внутри указанного пользователем пути обработки.
|
||||||
|
base_dir = input_dir
|
||||||
out_day_dir = build_out_dir(base_dir, now)
|
out_day_dir = build_out_dir(base_dir, now)
|
||||||
error_dir = build_error_dir(base_dir)
|
error_dir = build_error_dir(base_dir)
|
||||||
processed_dir = build_processed_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] = []
|
invalid_files: list[RemoteFile] = []
|
||||||
|
|
||||||
for file_name in _list_samba_files(input_dir, samba_conn):
|
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)
|
remote_path = join_path(input_dir, file_name)
|
||||||
if validate_file_name(file_name):
|
if validate_file_name(file_name):
|
||||||
valid_files.append(RemoteFile(path=remote_path, name=file_name))
|
valid_files.append(RemoteFile(path=remote_path, name=file_name))
|
||||||
|
|||||||
@ -86,7 +86,7 @@ def run_batch(
|
|||||||
|
|
||||||
scan_result = scan_input_files(input_dir=input_dir, samba_conn=samba_conn)
|
scan_result = scan_input_files(input_dir=input_dir, samba_conn=samba_conn)
|
||||||
log_lines.append(
|
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:
|
for remote_file in scan_result.invalid_files:
|
||||||
@ -108,12 +108,50 @@ def run_batch(
|
|||||||
processed_at=datetime.now(),
|
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:
|
for remote_file in scan_result.valid_files:
|
||||||
parse_result = _parse_remote_xml(remote_file.name, remote_file.path, samba_conn)
|
parse_result = _parse_remote_xml(remote_file.name, remote_file.path, samba_conn)
|
||||||
report_rows.extend(_report_rows_from_parse(parse_result))
|
report_rows.extend(_report_rows_from_parse(parse_result))
|
||||||
status, message = _resolve_parse_status(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(
|
protocol_rows.append(
|
||||||
ProtocolRow(
|
ProtocolRow(
|
||||||
file_name=remote_file.name,
|
file_name=remote_file.name,
|
||||||
@ -125,26 +163,6 @@ def run_batch(
|
|||||||
processed_at=datetime.now(),
|
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:
|
if not protocol_rows:
|
||||||
protocol_rows.append(
|
protocol_rows.append(
|
||||||
|
|||||||
19
main.py
19
main.py
@ -59,7 +59,7 @@ def main() -> None:
|
|||||||
st.success("Путь сохранен.")
|
st.success("Путь сохранен.")
|
||||||
st.rerun()
|
st.rerun()
|
||||||
else:
|
else:
|
||||||
st.error(f"{message} Обратитесь к {ACCESS_SUPPORT_CONTACT}.")
|
st.error(_format_access_error(message))
|
||||||
resolved_input_dir = get_resolved_input_dir(user_id)
|
resolved_input_dir = get_resolved_input_dir(user_id)
|
||||||
st.caption(f"Текущий путь: `{resolved_input_dir}`")
|
st.caption(f"Текущий путь: `{resolved_input_dir}`")
|
||||||
|
|
||||||
@ -105,7 +105,7 @@ def main() -> None:
|
|||||||
samba_password=samba_password,
|
samba_password=samba_password,
|
||||||
)
|
)
|
||||||
if not ok:
|
if not ok:
|
||||||
st.error(f"{message} Обратитесь к {ACCESS_SUPPORT_CONTACT}.")
|
st.error(_format_access_error(message))
|
||||||
else:
|
else:
|
||||||
if files:
|
if files:
|
||||||
st.success(f"Папка доступна. Найдено файлов: {len(files)}")
|
st.success(f"Папка доступна. Найдено файлов: {len(files)}")
|
||||||
@ -118,5 +118,20 @@ def main() -> None:
|
|||||||
st.rerun()
|
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__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user