forked from FotoCoder/Backuppy
check if user paths from user-input exists and differs
- CLI-mode: check if user paths from user-input exists - CLI-mode: prevent identical source and target path
This commit is contained in:
parent
f9dc51340c
commit
eb8e536617
4 changed files with 50 additions and 25 deletions
29
install.py
29
install.py
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/env python3
|
||||
"""
|
||||
project: Backuppy
|
||||
version: 0.9
|
||||
version: 0.10
|
||||
file: install.py
|
||||
summary: python installer-script in CLI-mode
|
||||
"""
|
||||
|
@ -11,10 +11,10 @@ import sys
|
|||
import os
|
||||
|
||||
# local imports
|
||||
from utils import set_language, query, _print, trace
|
||||
from utils import set_language, query, query_path, _print, trace, paths_are_identical
|
||||
|
||||
# local globals
|
||||
VERSION: str = "0.9"
|
||||
VERSION: str = "0.10"
|
||||
EMAIL = "fotocoder@joschu.ch"
|
||||
EXCLUDE_FILE = "exclude.txt"
|
||||
BACKUPPY_SCRIPT = "Backuppy.sh"
|
||||
|
@ -32,7 +32,7 @@ def main_install_cli(mydir, exclude_file):
|
|||
_print("intromsg2")
|
||||
|
||||
# which Rsync options are available and which one you want to use
|
||||
_print("rsyncopt")
|
||||
_print("rsyncopt", wait=2)
|
||||
|
||||
# asks if you want to exclude files/directories from backup and creates an exclude file in case of Yes
|
||||
exclude = query("excludefile1")
|
||||
|
@ -47,32 +47,35 @@ def main_install_cli(mydir, exclude_file):
|
|||
|
||||
# Asks for the source directory which should be saved
|
||||
_print("srcdir1")
|
||||
sourcedir = query("srcdir2")
|
||||
sourcedir = query_path("srcdir2")
|
||||
if not sourcedir:
|
||||
return False, None, None
|
||||
|
||||
_print("srcdir3_1")
|
||||
print(sourcedir)
|
||||
#_print("srcdir3_1")
|
||||
#print(sourcedir)
|
||||
_print("srcdir3_2")
|
||||
|
||||
# asks for the destination directory in which the backup should be saved
|
||||
targetdir = query("targetdir1")
|
||||
targetdir = query_path("targetdir1")
|
||||
while paths_are_identical(sourcedir, targetdir):
|
||||
_print("paths_must_differ")
|
||||
targetdir = query_path("targetdir1")
|
||||
if not targetdir:
|
||||
return False, None, None
|
||||
return False, None, None
|
||||
|
||||
_print("targetdir2_1")
|
||||
print(targetdir)
|
||||
#_print("targetdir2_1")
|
||||
#print(targetdir)
|
||||
_print("targetdir2_2")
|
||||
|
||||
# collects all the information needed to execute the rsync command and creates it.
|
||||
_print("collect")
|
||||
_print("collect", wait=2)
|
||||
|
||||
rsync_cmd = f"rsync -aqp --exclude-from={os.path.join(mydir, exclude_file)} {sourcedir} {targetdir}"
|
||||
|
||||
print(f"{rsync_cmd}")
|
||||
|
||||
# Outro
|
||||
_print("outro1")
|
||||
_print("outro1", wait=2)
|
||||
|
||||
_print("outro2")
|
||||
print(EMAIL)
|
||||
|
|
|
@ -9,7 +9,11 @@ Yes="Yes"
|
|||
|
||||
No="No"
|
||||
|
||||
welcome="Hello, first of all, which language do you prefer: German [DE] or English [EN]?"
|
||||
welcome="Hello, first of all, which language do you prefer: German or English [de/EN]?"
|
||||
|
||||
path_not_existing="Specified directory does not exist!"
|
||||
|
||||
paths_must_differ="Source dir and target dir must differ!"
|
||||
|
||||
languagepack="Perfect, the English language package is now activated. Welcome!"
|
||||
|
||||
|
@ -17,9 +21,9 @@ intromsg1="Thanks for using Backuppy to make your backups!"
|
|||
|
||||
intromsg2="The installer will now ask you a few things to adapt your backup script to your requirements."
|
||||
|
||||
rsyncopt="rsync offers various options, but to simplify the installation process, I have activated the options -a, -q and -p. \n If you want to set more options, you can do thjat in the file 'Backuppy.sh'."
|
||||
rsyncopt="rsync offers various options, but to simplify the installation process, I have activated the options -a, -q and -p.\nIf you want to set more options, you can do that in the file 'Backuppy.sh'."
|
||||
|
||||
excludefile1="Now I need to know if you want to exclude one or more files/directories from your backups.\nThen you can adjust this in the 'exclude.txt'.\nThere you can exclude directories and files in the format '/directory' '/file.txt'.\nDo you want to exclude files/directories or not? [Y/N]"
|
||||
excludefile1="Now I need to know if you want to exclude one or more files/directories from your backups.\nThen you can adjust this in the 'exclude.txt'.\nThere you can exclude directories and files in the format '/directory' '/file.txt'.\nDo you want to exclude files/directories or not? [y/N]"
|
||||
|
||||
excludefile2="Perfect, then you can enter your files/directories to be excluded in the file 'exclude.txt' after completing the installation of Backuppy."
|
||||
|
||||
|
@ -30,12 +34,12 @@ srcdir1="Now we come to one of the most important parts of installing Backuppy:"
|
|||
srcdir2="Which directory do you want to save (e.g. the home directory)? Please enter an absolute path (e.g. '/home/username/')."
|
||||
|
||||
srcdir3_1="you have typed in the following source path: "
|
||||
srcdir3_2="if this path is not correct, adjust it in the file 'Backuppy.sh'."
|
||||
srcdir3_2="(You may adjust this any time in the file 'Backuppy.sh'.)"
|
||||
|
||||
targetdir1="Now I need to know where Backuppy should save your backups, i.e. the target directory. \n Please enter this carefully and in the same way as for the source directory."
|
||||
|
||||
targetdir2_1="you have typed in the following destination path:"
|
||||
targetdir2_2="if this path is not correct, adjust it in the file 'Backuppy.sh'."
|
||||
targetdir2_2="(You may adjust this any time in the file 'Backuppy.sh'.)"
|
||||
|
||||
collect="Now we have almost reached the end of the installer. I will now create the rsync command for you and show it to you.\n If you notice a mistake, just cancel the installer and start again from the beginning.\nNote: I recommend that you download Backuppy completely again in this case."
|
||||
|
||||
|
|
|
@ -9,15 +9,19 @@ Yes="Ja"
|
|||
|
||||
No="Nein"
|
||||
|
||||
path_not_existing="Der angegebene Pfad existiert nicht!"
|
||||
|
||||
paths_must_differ="Quell- and Zielpfad dürfen nicht identisch sein!"
|
||||
|
||||
languagepack="Perfekt, nun ist das deutsche Sprachpaket aktiviert. Willkommen!"
|
||||
|
||||
intromsg1="Danke, dass du Backuppy nutzt, um deine Backups zu erstellen!"
|
||||
|
||||
intromsg2="Der Installer wird dich nun einige Dinge abfragen, um dein Backup-Skript an deine Anforderungen anzupassen."
|
||||
|
||||
rsyncopt="rsync bietet verschiedene Optionen an, um das Ganze jedoch zu vereinfachen, habe ich die Optionen -a, -q und -p aktiviert. \n Wenn du mehr einstellen willst, kannst du das in der Datei 'Backuppy.sh' machen."
|
||||
rsyncopt="rsync bietet verschiedene Optionen an, um das Ganze jedoch zu vereinfachen, habe ich die Optionen -a, -q und -p aktiviert.\nWenn du mehr einstellen willst, kannst du das in der Datei 'Backuppy.sh' machen."
|
||||
|
||||
excludefile1="Nun muss ich noch wissen, ob du ein oder mehrere Dateien/Verzeichnisse vom Backup ausschliessen möchtest.\nDann kannst du das in der 'exclude.txt' anpassen.\nDort kannst du dann im Format '/Verzeichnis' '/Datei.txt' Verzeichnisse und Dateien ausschliessen.\nMöchtest du Dateien/Verzeichnisse ausschliessen oder nicht? [J/N]"
|
||||
excludefile1="Nun muss ich noch wissen, ob du ein oder mehrere Dateien/Verzeichnisse vom Backup ausschliessen möchtest.\nDann kannst du das in der 'exclude.txt' anpassen.\nDort kannst du dann im Format '/Verzeichnis' '/Datei.txt' Verzeichnisse und Dateien ausschliessen.\nMöchtest du Dateien/Verzeichnisse ausschliessen oder nicht? [j/N]"
|
||||
|
||||
excludefile2="Perfekt, dann kannst du nach der Fertigstellung der Installation von Backuppy deine auszuschliessenden\nDateien/Verzeichnisse in der Datei 'exclude.txt eintragen."
|
||||
|
||||
|
@ -28,12 +32,12 @@ srcdir1="Nun kommen wir zu einem der wichtigesten Teile der Installation von Bac
|
|||
srcdir2="Welches Verzeichnis möchtest du sichern (z.B. das Homeverzeichnis)? Bitte gib einen absoluten Pfad (z.B. '/home/username/') an."
|
||||
|
||||
srcdir3_1="du hast folgenden Quellpfad eingetippt: "
|
||||
srcdir3_2="wenn dieser Pfad nicht stimmen sollte, dann passe ihn in der Datei 'Backuppy.sh' an."
|
||||
srcdir3_2="(Der Pfad kann jederzeit in der Datei 'Backuppy.sh' angepasst werden.)"
|
||||
|
||||
targetdir1="Nun muss ich noch wissen, wo Backuppy dein Backup ablegen soll, das Zielverzeichnis also.\nBitte tippe dieses gewissenhaft und auf die Weise wie beim Quellverzeichnis ein."
|
||||
|
||||
targetdir2_1="du hast folgenden Zielpfad eingetippt:"
|
||||
targetdir2_2="wenn dieser Pfad nicht stimmen sollte, dann passe ihn in der Datei 'Backuppy.sh' an."
|
||||
targetdir2_2="(Der Pfad kann jederzeit in der Datei 'Backuppy.sh' angepasst werden.)"
|
||||
|
||||
collect="Nun sind wir fast am Ende des Installers angelangt. Ich erstelle nun den rsync-Befehl für dich und zeige ihn\ndir nachher nochmal.\nWenn dir da etwas auffallen sollte, brich den Installer einfach ab und fange nochmal von Vorne an.\nAchtung: ich empfehle dir, Backuppy in diesem Fall nochmal komplett neu zu installieren."
|
||||
|
||||
|
|
20
utils.py
20
utils.py
|
@ -8,6 +8,7 @@ summary: utilities script
|
|||
|
||||
# Standard library imports
|
||||
import time
|
||||
import os
|
||||
|
||||
# local imports
|
||||
from languages import english
|
||||
|
@ -25,7 +26,6 @@ class bcolors:
|
|||
ERROR = '\033[91m' #RED
|
||||
RESET = '\033[0m' #RESET COLOR
|
||||
|
||||
|
||||
def trace(message_txt, prefix_crlf=False, err=False):
|
||||
""" Print a formatted message to std out.
|
||||
|
||||
|
@ -49,9 +49,9 @@ def get_lang_text(search_str: str):
|
|||
return_str = eval("german." + search_str)
|
||||
return return_str
|
||||
|
||||
def _print(message_txt: str):
|
||||
def _print(message_txt: str, wait: int=1):
|
||||
print("\n" + get_lang_text(message_txt) + "\n")
|
||||
time.sleep(1)
|
||||
time.sleep(wait)
|
||||
|
||||
def set_language(language):
|
||||
""" Set global constant "LANGUAGE" to given language ("EN"/"DE"). """
|
||||
|
@ -62,6 +62,20 @@ def set_language(language):
|
|||
else:
|
||||
LANGUAGE = LANG_EN
|
||||
|
||||
def paths_are_identical(path1: str, path2: str):
|
||||
if os.path.isdir(path1):
|
||||
if path1 == path2:
|
||||
return True
|
||||
return False
|
||||
|
||||
def query_path(question_txt: str):
|
||||
path = query(question_txt)
|
||||
while not os.path.isdir(path):
|
||||
_print("path_not_existing")
|
||||
#path = input("Please retype an existing directory.\n> ")
|
||||
path = query(question_txt)
|
||||
return path
|
||||
|
||||
def query(question_txt: str):
|
||||
try:
|
||||
answer_txt = input(get_lang_text(question_txt) + "\n> ")
|
||||
|
|
Loading…
Reference in a new issue