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
This commit is contained in:
Paul S 2021-05-10 11:29:40 +02:00
parent 21f6b4b3ac
commit b24dabf203
2 changed files with 68 additions and 55 deletions

View file

@ -1,5 +1,10 @@
# Changelog Backuppy # 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 ## [0.8] - 2021-05-07
### Added ### Added
- GUI-mode: Introduce "Browse"-button on directory-selection dialogs - GUI-mode: Introduce "Browse"-button on directory-selection dialogs

View file

@ -35,8 +35,16 @@ def set_language(language):
global LANGUAGE global LANGUAGE
LANGUAGE = language LANGUAGE = language
def trace(message_txt): def trace(message_txt, prefix_crlf=False):
""" Print a formatted message to std out. """ """ 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) print("[ OK ] " + message_txt)
def get_lang_text(search_str: str): def get_lang_text(search_str: str):
@ -48,6 +56,7 @@ def get_lang_text(search_str: str):
return return_str return return_str
def main_install_cli(): def main_install_cli():
try:
language = input("Hello, first of all, which language do you prefer: German [DE] or English [EN]?\n> ") language = input("Hello, first of all, which language do you prefer: German [DE] or English [EN]?\n> ")
if language.upper() == "DE": if language.upper() == "DE":
set_language(LANG_DE) set_language(LANG_DE)
@ -108,6 +117,11 @@ def main_install_cli():
return True, EXCLUDE, RSYNC_CMD return True, EXCLUDE, RSYNC_CMD
except KeyboardInterrupt:
trace("Programm interrupted by user.", prefix_crlf=True)
return False, None, None
def create_exclude_file(directory, exclude_file): def create_exclude_file(directory, exclude_file):
exclude_file = os.path.join(directory, exclude_file) exclude_file = os.path.join(directory, exclude_file)
with open(exclude_file, "w") as fExclude: with open(exclude_file, "w") as fExclude:
@ -170,12 +184,6 @@ def main(argv):
else: else:
trace("Starting CLI-version.\n") trace("Starting CLI-version.\n")
is_finalized, is_exclude, rsync_cmd = main_install_cli() # collect user input via CLI and store in env. variables 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: if is_finalized:
do_the_install(is_exclude, rsync_cmd) do_the_install(is_exclude, rsync_cmd)