From 82ec2d220bb9dd976dcab15076eed77a9ec57deb Mon Sep 17 00:00:00 2001 From: pinb-mini Date: Fri, 30 Aug 2024 22:36:11 +0900 Subject: [PATCH 1/2] bug fix: add try~catch --- bunnysync.py | 2 +- sync.py | 53 +++++++++++++++++++++++++++------------------------- 2 files changed, 29 insertions(+), 26 deletions(-) diff --git a/bunnysync.py b/bunnysync.py index 5babead..1fb0130 100644 --- a/bunnysync.py +++ b/bunnysync.py @@ -13,4 +13,4 @@ if __name__ == '__main__': sys.exit(app.exec_()) -# pyinstaller --onefile bunnysync.py --add-data "images/realrabbit.ico:images" --add-data "images/realrabbit2.png:images" --icon=images/realrabbit.png --noconsole \ No newline at end of file +# pyinstaller --onefile bunnysync.py --add-data "images/realrabbit.png:images" --add-data "images/realrabbit2.png:images" --icon=images/realrabbit.png --noconsole \ No newline at end of file diff --git a/sync.py b/sync.py index 44ec267..b048875 100644 --- a/sync.py +++ b/sync.py @@ -74,32 +74,35 @@ class FolderSynchronizer: count_sync = 0 for root, _, files in os.walk(src_folder): for filename in files: - src_path = os.path.join(root, filename) - rel_dir = os.path.relpath(root, src_folder) - dest_path = os.path.join(dest_folder, rel_dir, filename) - total_sync += 1 - - src_modified = os.path.getmtime(src_path) - file_info = self.get_file_info(rel_dir, filename) - - if not file_info: - # New file - os.makedirs(os.path.dirname(dest_path), exist_ok=True) - shutil.copy2(src_path, dest_path) - count_sync += 1 - dest_modified = current_time - modified1, exist1, modified2, exist2 = src_modified, 1, dest_modified, 1 - else: - # Existing file - if src_modified > file_info[3] or not file_info[4]: - shutil.copy2(src_path, dest_path) - count_sync += 1 - dest_modified = current_time - modified1, exist1, modified2, exist2 = src_modified, 1, dest_modified, 1 + try: + src_path = os.path.join(root, filename) + rel_dir = os.path.relpath(root, src_folder) + dest_path = os.path.join(dest_folder, rel_dir, filename) + total_sync += 1 + + src_modified = os.path.getmtime(src_path) + file_info = self.get_file_info(rel_dir, filename) + + if not file_info: + # New file + os.makedirs(os.path.dirname(dest_path), exist_ok=True) + shutil.copy2(src_path, dest_path) + count_sync += 1 + dest_modified = current_time + modified1, exist1, modified2, exist2 = src_modified, 1, dest_modified, 1 else: - modified1, exist1, modified2, exist2 = src_modified, 1, file_info[5], file_info[6] - - self.update_db(rel_dir, filename, modified1, exist1, modified2, exist2) + # Existing file + if src_modified > file_info[3] or not file_info[4]: + shutil.copy2(src_path, dest_path) + count_sync += 1 + dest_modified = current_time + modified1, exist1, modified2, exist2 = src_modified, 1, dest_modified, 1 + else: + modified1, exist1, modified2, exist2 = src_modified, 1, file_info[5], file_info[6] + except: + pass + finally: + self.update_db(rel_dir, filename, modified1, exist1, modified2, exist2) return total_sync, count_sync From abf1d1ee959ac256a7058181e7a79d8c6ae491df Mon Sep 17 00:00:00 2001 From: pinb-mini Date: Fri, 30 Aug 2024 22:42:36 +0900 Subject: [PATCH 2/2] add gitignore --- .gitignore | 6 ++++++ bunnysync.spec | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 .gitignore create mode 100644 bunnysync.spec diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..aea8ea0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +/venv +/dist +/build +/__pycache__ +my_data.db +.DS_Store \ No newline at end of file diff --git a/bunnysync.spec b/bunnysync.spec new file mode 100644 index 0000000..9710c4f --- /dev/null +++ b/bunnysync.spec @@ -0,0 +1,45 @@ +# -*- mode: python ; coding: utf-8 -*- + + +a = Analysis( + ['bunnysync.py'], + pathex=[], + binaries=[], + datas=[('images/realrabbit.ico', 'images'), ('images/realrabbit2.png', 'images')], + hiddenimports=[], + hookspath=[], + hooksconfig={}, + runtime_hooks=[], + excludes=[], + noarchive=False, + optimize=0, +) +pyz = PYZ(a.pure) + +exe = EXE( + pyz, + a.scripts, + a.binaries, + a.datas, + [], + name='bunnysync', + debug=False, + bootloader_ignore_signals=False, + strip=False, + upx=True, + upx_exclude=[], + runtime_tmpdir=None, + console=False, + disable_windowed_traceback=False, + argv_emulation=False, + target_arch=None, + codesign_identity=None, + entitlements_file=None, + icon=['images/realrabbit.ico'], +) +app = BUNDLE( + exe, + name='bunnysync.app', + icon='images/realrabbit.ico', + bundle_identifier=None, +)