From b362edeca06503f826cb445ac8a92f22cb38b0a6 Mon Sep 17 00:00:00 2001 From: KWON Date: Mon, 28 Jul 2025 16:20:31 +0900 Subject: [PATCH] =?UTF-8?q?pos=5Fupdate=5Fgui=20=ED=8C=8C=EC=9D=BC?= =?UTF-8?q?=EB=8F=84=20=EB=8F=99=EC=9D=BC=ED=95=98=EA=B2=8C=20=EB=AA=A8?= =?UTF-8?q?=EB=8B=88=ED=84=B0=EB=A7=81=ED=95=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/file_watch.py | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/lib/file_watch.py b/lib/file_watch.py index 7f0315d..c55be77 100644 --- a/lib/file_watch.py +++ b/lib/file_watch.py @@ -4,15 +4,14 @@ from watchdog.observers import Observer from watchdog.events import FileSystemEventHandler import threading -# pos_update_bill 모듈에서 main 함수를 가져옵니다. -# pos_update_bill.py가 같은 폴더 혹은 PYTHONPATH에 있어야 합니다. import pos_update_bill +import pos_update_gui # 추가 DATA_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '../data')) -# 감시할 파일 확장자 및 패턴 정의 (pos_update_bill.py 내와 일치해야 함) FILE_EXTENSIONS = ('.xls', '.xlsx') -FILE_PREFIX = "영수증별매출상세현황" +BILL_PREFIX = "영수증별매출상세현황" +GUI_PREFIX = "일자별 (상품별)" class NewFileHandler(FileSystemEventHandler): def __init__(self): @@ -25,9 +24,12 @@ class NewFileHandler(FileSystemEventHandler): return filepath = event.src_path filename = os.path.basename(filepath) - if filename.startswith(FILE_PREFIX) and filename.endswith(FILE_EXTENSIONS): + if not filename.endswith(FILE_EXTENSIONS): + return + + # 처리 대상 여부 확인 + if filename.startswith(BILL_PREFIX) or filename.startswith(GUI_PREFIX): print(f"[WATCHER] 신규 파일 감지: {filename}") - # 별도의 스레드에서 처리 (감시 중단 방지) threading.Thread(target=self.process_file, args=(filepath, filename), daemon=True).start() def process_file(self, filepath, filename): @@ -38,15 +40,19 @@ class NewFileHandler(FileSystemEventHandler): self._processing_files.add(filename) try: - # 파일이 완전히 쓰여질 때까지 대기 (간단히 3초 대기, 필요 시 로직 강화) - time.sleep(3) + time.sleep(3) # 파일 쓰기 완료 대기 print(f"[WATCHER] 파일 처리 시작: {filename}") - # pos_update_bill.main() 내부가 파일 리스트를 탐색해서 처리하므로 - # 신규 파일이 존재하는 상태에서 호출하면 정상 동작함. - pos_update_bill.main() + if filename.startswith(BILL_PREFIX): + pos_update_bill.main() + elif filename.startswith(GUI_PREFIX): + pos_update_gui.main() + else: + print(f"[WATCHER] 처리 대상이 아님: {filename}") + return + except Exception as e: - print(f"[WATCHER] 파일 처리 중 오류 발생: {filename} / {e}") + print(f"[WATCHER] 처리 중 오류 발생: {filename} / {e}") else: try: os.remove(filepath) @@ -58,7 +64,7 @@ class NewFileHandler(FileSystemEventHandler): self._processing_files.discard(filename) def start_watching(): - print(f"[WATCHER] {DATA_DIR} 폴더 감시 시작") + print(f"[WATCHER] '{DATA_DIR}' 폴더 감시 시작") event_handler = NewFileHandler() observer = Observer() observer.schedule(event_handler, DATA_DIR, recursive=False)