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:
parent
21f6b4b3ac
commit
b24dabf203
2 changed files with 68 additions and 55 deletions
|
@ -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
|
||||||
|
|
116
install.py
116
install.py
|
@ -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,65 +56,71 @@ def get_lang_text(search_str: str):
|
||||||
return return_str
|
return return_str
|
||||||
|
|
||||||
def main_install_cli():
|
def main_install_cli():
|
||||||
language = input("Hello, first of all, which language do you prefer: German [DE] or English [EN]?\n> ")
|
try:
|
||||||
if language.upper() == "DE":
|
language = input("Hello, first of all, which language do you prefer: German [DE] or English [EN]?\n> ")
|
||||||
set_language(LANG_DE)
|
if language.upper() == "DE":
|
||||||
print("Perfekt, nun ist das deutsche Sprachpaket aktiviert. Willkommen!\n")
|
set_language(LANG_DE)
|
||||||
else:
|
print("Perfekt, nun ist das deutsche Sprachpaket aktiviert. Willkommen!\n")
|
||||||
print("Perfect, the English language package is now activated. Welcome!.\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")
|
print("\n" + get_lang_text("intromsg1") + "\n")
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
print("\n" + get_lang_text("intromsg2") + "\n")
|
print("\n" + get_lang_text("intromsg2") + "\n")
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
# which Rsync options are available and which one you want to use
|
# which Rsync options are available and which one you want to use
|
||||||
print(get_lang_text("rsyncopt") + "\n")
|
print(get_lang_text("rsyncopt") + "\n")
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
# asks if you want to exclude files/directories from backup and creates an exclude file in case of Yes
|
# 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> ")
|
exclude = input(get_lang_text("excludefile1") + "\n> ")
|
||||||
global EXCLUDE
|
global EXCLUDE
|
||||||
if exclude.upper() in ("J", "Y"):
|
if exclude.upper() in ("J", "Y"):
|
||||||
EXCLUDE = True
|
EXCLUDE = True
|
||||||
print(get_lang_text("excludefile2") + "\n")
|
print(get_lang_text("excludefile2") + "\n")
|
||||||
else:
|
else:
|
||||||
EXCLUDE = False
|
EXCLUDE = False
|
||||||
print(get_lang_text("excludefile3") + "\n")
|
print(get_lang_text("excludefile3") + "\n")
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
# Asks for the source directory which should be saved
|
# Asks for the source directory which should be saved
|
||||||
print(get_lang_text("srcdir1"))
|
print(get_lang_text("srcdir1"))
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
sourcedir = input(get_lang_text("srcdir2") + "\n> ")
|
sourcedir = input(get_lang_text("srcdir2") + "\n> ")
|
||||||
|
|
||||||
print(f"{get_lang_text('srcdir3_1')} {sourcedir} {get_lang_text('srcdir3_2')}")
|
print(f"{get_lang_text('srcdir3_1')} {sourcedir} {get_lang_text('srcdir3_2')}")
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
# asks for the destination directory in which the backup should be saved
|
# asks for the destination directory in which the backup should be saved
|
||||||
targetdir = input(get_lang_text("targetdir1") + "\n> ")
|
targetdir = input(get_lang_text("targetdir1") + "\n> ")
|
||||||
print(f"{get_lang_text('targetdir2_1')} {targetdir} {get_lang_text('targetdir2_2')}")
|
print(f"{get_lang_text('targetdir2_1')} {targetdir} {get_lang_text('targetdir2_2')}")
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
# collects all the information needed to execute the rsync command and creates it.
|
# collects all the information needed to execute the rsync command and creates it.
|
||||||
print(get_lang_text("collect") + "\n")
|
print(get_lang_text("collect") + "\n")
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
exclude_file = os.path.join(MYDIR, EXCLUDE_FILE)
|
exclude_file = os.path.join(MYDIR, EXCLUDE_FILE)
|
||||||
|
|
||||||
RSYNC_CMD = f"rsync -aqp --exclude-from={exclude_file} {sourcedir} {targetdir}"
|
RSYNC_CMD = f"rsync -aqp --exclude-from={exclude_file} {sourcedir} {targetdir}"
|
||||||
|
|
||||||
print(f"{RSYNC_CMD}")
|
print(f"{RSYNC_CMD}")
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
# Outro
|
# Outro
|
||||||
print(get_lang_text("outro1"))
|
print(get_lang_text("outro1"))
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
print(get_lang_text("outro2") + " " + EMAIL)
|
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):
|
def create_exclude_file(directory, exclude_file):
|
||||||
exclude_file = os.path.join(directory, exclude_file)
|
exclude_file = os.path.join(directory, exclude_file)
|
||||||
|
@ -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)
|
||||||
|
|
Loading…
Reference in a new issue