From ceef4b03b0a0973fb42786a07bb98155a813c64a Mon Sep 17 00:00:00 2001 From: qwjyh Date: Tue, 25 Jun 2024 19:19:33 +0900 Subject: [PATCH] qpdfview: fix: check file existence before operation --- extra_configs/qpdfview/update_config.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/extra_configs/qpdfview/update_config.py b/extra_configs/qpdfview/update_config.py index ddebd60..9498674 100755 --- a/extra_configs/qpdfview/update_config.py +++ b/extra_configs/qpdfview/update_config.py @@ -10,10 +10,19 @@ import shutil # ======================================================================================= QPDFVIEW_CONFIGDIR = os.path.expanduser("~/.config/qpdfview/") +if not os.path.exists(QPDFVIEW_CONFIGDIR): + print("qpdfview config directory not found.") + print("Install qpdfview first and rerun this script.") + print("Exiting...") + exit(1) + +# ======================================================================================= + QPDFVIEW_CONFIG_CONFIG = QPDFVIEW_CONFIGDIR + "qpdfview.conf" print(f"{QPDFVIEW_CONFIG_CONFIG=}") -shutil.copyfile(QPDFVIEW_CONFIG_CONFIG, QPDFVIEW_CONFIG_CONFIG + ".orig") +if os.path.exists(QPDFVIEW_CONFIG_CONFIG): + shutil.copyfile(QPDFVIEW_CONFIG_CONFIG, QPDFVIEW_CONFIG_CONFIG + ".orig") config = configparser.RawConfigParser() config.optionxform = lambda optionstr: optionstr @@ -42,7 +51,8 @@ with open(QPDFVIEW_CONFIG_CONFIG, "w") as file: QPDFVIEW_CONFIG_SHORTCUTS = QPDFVIEW_CONFIGDIR + "shortcuts.conf" -shutil.copyfile(QPDFVIEW_CONFIG_SHORTCUTS, QPDFVIEW_CONFIG_SHORTCUTS + ".orig") +if os.path.exists(QPDFVIEW_CONFIG_SHORTCUTS): + shutil.copyfile(QPDFVIEW_CONFIG_SHORTCUTS, QPDFVIEW_CONFIG_SHORTCUTS + ".orig") config = configparser.RawConfigParser() config.optionxform = lambda optionstr: optionstr