From b24dabf2036b2f8170fbcbeb26f26ef9fa1ed7f7 Mon Sep 17 00:00:00 2001
From: Paul S
Date: Mon, 10 May 2021 11:29:40 +0200
Subject: [PATCH] Show message on Ctrl+C
- CLI-mode: Show text "Programm interrupted by user." instead of error message when Ctrl+C was pressed.
- CLI-mode: Removed obsolete trace messages
---
CHANGELOG.md | 5 +++
install.py | 118 +++++++++++++++++++++++++++------------------------
2 files changed, 68 insertions(+), 55 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 66e0b1d..7031763 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,10 @@
# Changelog Backuppy
+## [0.8.1] - 2021-05-10
+### Fixed
+- CLI-mode: Show text "Programm interrupted by user." instead of error message when Ctrl+C was pressed.
+- CLI-mode: Removed obsolete trace messages
+
## [0.8] - 2021-05-07
### Added
- GUI-mode: Introduce "Browse"-button on directory-selection dialogs
diff --git a/install.py b/install.py
index d6468be..34b04ac 100644
--- a/install.py
+++ b/install.py
@@ -35,8 +35,16 @@ def set_language(language):
global LANGUAGE
LANGUAGE = language
-def trace(message_txt):
- """ Print a formatted message to std out. """
+def trace(message_txt, prefix_crlf=False):
+ """ Print a formatted message to std out.
+
+ :param "message_txt" [in] The message text that should be displayed.
+ :param "prefix_crlf" [in] If True, a carriage return/line feed will be done prior to the message text.
+
+ """
+
+ if prefix_crlf:
+ print("\n")
print("[ OK ] " + message_txt)
def get_lang_text(search_str: str):
@@ -48,65 +56,71 @@ def get_lang_text(search_str: str):
return return_str
def main_install_cli():
- language = input("Hello, first of all, which language do you prefer: German [DE] or English [EN]?\n> ")
- if language.upper() == "DE":
- set_language(LANG_DE)
- print("Perfekt, nun ist das deutsche Sprachpaket aktiviert. Willkommen!\n")
- else:
- print("Perfect, the English language package is now activated. Welcome!.\n")
+ try:
+ language = input("Hello, first of all, which language do you prefer: German [DE] or English [EN]?\n> ")
+ if language.upper() == "DE":
+ set_language(LANG_DE)
+ print("Perfekt, nun ist das deutsche Sprachpaket aktiviert. Willkommen!\n")
+ else:
+ print("Perfect, the English language package is now activated. Welcome!.\n")
- time.sleep(1)
+ time.sleep(1)
- print("\n" + get_lang_text("intromsg1") + "\n")
- time.sleep(1)
+ print("\n" + get_lang_text("intromsg1") + "\n")
+ time.sleep(1)
- print("\n" + get_lang_text("intromsg2") + "\n")
- time.sleep(1)
+ print("\n" + get_lang_text("intromsg2") + "\n")
+ time.sleep(1)
- # which Rsync options are available and which one you want to use
- print(get_lang_text("rsyncopt") + "\n")
- time.sleep(1)
+ # which Rsync options are available and which one you want to use
+ print(get_lang_text("rsyncopt") + "\n")
+ time.sleep(1)
- # asks if you want to exclude files/directories from backup and creates an exclude file in case of Yes
- exclude = input(get_lang_text("excludefile1") + "\n> ")
- global EXCLUDE
- if exclude.upper() in ("J", "Y"):
- EXCLUDE = True
- print(get_lang_text("excludefile2") + "\n")
- else:
- EXCLUDE = False
- print(get_lang_text("excludefile3") + "\n")
- time.sleep(1)
+ # asks if you want to exclude files/directories from backup and creates an exclude file in case of Yes
+ exclude = input(get_lang_text("excludefile1") + "\n> ")
+ global EXCLUDE
+ if exclude.upper() in ("J", "Y"):
+ EXCLUDE = True
+ print(get_lang_text("excludefile2") + "\n")
+ else:
+ EXCLUDE = False
+ print(get_lang_text("excludefile3") + "\n")
+ time.sleep(1)
- # Asks for the source directory which should be saved
- print(get_lang_text("srcdir1"))
- time.sleep(1)
- sourcedir = input(get_lang_text("srcdir2") + "\n> ")
+ # Asks for the source directory which should be saved
+ print(get_lang_text("srcdir1"))
+ time.sleep(1)
+ sourcedir = input(get_lang_text("srcdir2") + "\n> ")
- print(f"{get_lang_text('srcdir3_1')} {sourcedir} {get_lang_text('srcdir3_2')}")
- time.sleep(1)
+ print(f"{get_lang_text('srcdir3_1')} {sourcedir} {get_lang_text('srcdir3_2')}")
+ time.sleep(1)
- # asks for the destination directory in which the backup should be saved
- targetdir = input(get_lang_text("targetdir1") + "\n> ")
- print(f"{get_lang_text('targetdir2_1')} {targetdir} {get_lang_text('targetdir2_2')}")
- time.sleep(1)
+ # asks for the destination directory in which the backup should be saved
+ targetdir = input(get_lang_text("targetdir1") + "\n> ")
+ print(f"{get_lang_text('targetdir2_1')} {targetdir} {get_lang_text('targetdir2_2')}")
+ time.sleep(1)
- # collects all the information needed to execute the rsync command and creates it.
- print(get_lang_text("collect") + "\n")
- time.sleep(1)
- exclude_file = os.path.join(MYDIR, EXCLUDE_FILE)
-
- RSYNC_CMD = f"rsync -aqp --exclude-from={exclude_file} {sourcedir} {targetdir}"
+ # collects all the information needed to execute the rsync command and creates it.
+ print(get_lang_text("collect") + "\n")
+ time.sleep(1)
+ exclude_file = os.path.join(MYDIR, EXCLUDE_FILE)
+
+ RSYNC_CMD = f"rsync -aqp --exclude-from={exclude_file} {sourcedir} {targetdir}"
- print(f"{RSYNC_CMD}")
- time.sleep(1)
+ print(f"{RSYNC_CMD}")
+ time.sleep(1)
- # Outro
- print(get_lang_text("outro1"))
- time.sleep(2)
- print(get_lang_text("outro2") + " " + EMAIL)
+ # Outro
+ print(get_lang_text("outro1"))
+ time.sleep(2)
+ print(get_lang_text("outro2") + " " + EMAIL)
+
+ return True, EXCLUDE, RSYNC_CMD
+
+ except KeyboardInterrupt:
+ trace("Programm interrupted by user.", prefix_crlf=True)
+ return False, None, None
- return True, EXCLUDE, RSYNC_CMD
def create_exclude_file(directory, exclude_file):
exclude_file = os.path.join(directory, exclude_file)
@@ -170,12 +184,6 @@ def main(argv):
else:
trace("Starting CLI-version.\n")
is_finalized, is_exclude, rsync_cmd = main_install_cli() # collect user input via CLI and store in env. variables
- if is_finalized:
- print("CLI finalized.")
- if is_exclude:
- print("exclude is true.")
- if rsync_cmd:
- print("rsync command returned: " + rsync_cmd)
if is_finalized:
do_the_install(is_exclude, rsync_cmd)