Write alias only if not already existing

This commit is contained in:
Paul S 2021-05-06 15:14:50 +02:00
parent 1dfe37a970
commit 5d367fa1a8
2 changed files with 28 additions and 17 deletions

View file

@ -1,6 +1,10 @@
# Changelog Backuppy # Changelog Backuppy
## [1.02.000] - 2021-05-05 ## [0.6] - 2021-05-06
### Added
- Write alias to Backuppy.sh into .bashrc/.zshrc only if not already existing
## [0.5.2] - 2021-05-05
### Added ### Added
- Now fully functional as the shell version - Now fully functional as the shell version
@ -11,11 +15,11 @@
### Fixed ### Fixed
- Fixed problem with the Bash/ZSH config - Fixed problem with the Bash/ZSH config
## [1.01.001] - 2021-05-04 ## [0.5.1] - 2021-05-04
### Changed ### Changed
- Use E-MAIL constant - Use E-MAIL constant
## [1.01.000] - 2021-05-04 ## [0.5] - 2021-05-04
### Added ### Added
- Graphical installer based on Python3 with PySide2 GUI framework (Qt-bindings for Python) - Graphical installer based on Python3 with PySide2 GUI framework (Qt-bindings for Python)
- Changelog.MD - Changelog.MD

View file

@ -1,7 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
""" """
project: Backuppy project: Backuppy
version: 1.02.000 version: 0.6
file: install.py file: install.py
summary: main entry python file summary: main entry python file
""" """
@ -10,16 +10,14 @@ summary: main entry python file
import os import os
# Third party imports # Third party imports
from PySide2 import QtCore from PySide2 import QtWidgets
from PySide2 import QtGui
from PySide2 import QtCore, QtWidgets
# local imports # local imports
from languages import english from languages import english
from languages import german from languages import german
# local globals # local globals
VERSION: str = "1.02.000" VERSION: str = "0.6"
EMAIL: str = "fotocoder@joschu.ch" EMAIL: str = "fotocoder@joschu.ch"
TARGET_SCRIPT: str = "Backuppy.sh" TARGET_SCRIPT: str = "Backuppy.sh"
EXCLUDE_FILE: str = "exclude.txt" EXCLUDE_FILE: str = "exclude.txt"
@ -44,7 +42,7 @@ def get_lang_text(search_str: str):
def trace(message_txt: str): def trace(message_txt: str):
""" Print a formatted message to std out. """ """ Print a formatted message to std out. """
print(f"[ OK ]", message_txt) print("[ OK ]" + message_txt)
class BackuppyWizard(QtWidgets.QWizard): class BackuppyWizard(QtWidgets.QWizard):
def __init__(self, parent=None): def __init__(self, parent=None):
@ -295,20 +293,29 @@ def create_shell_script(command_str: str):
user_home = os.environ.get("HOME") user_home = os.environ.get("HOME")
## STEP 1: update shell config scripts with alias for backuppy ## STEP 1: update shell config scripts with alias for backuppy
# .zshrc case1 and case2 # Check for installed ZSH
if current_shell in ("/usr/bin/zsh", "/bin/zsh"): if current_shell.upper().find("ZSH") > 0:
# Appending to bash config file
rc_filepath = os.path.join(user_home, ".zshrc") rc_filepath = os.path.join(user_home, ".zshrc")
# .bashrc case1 and case2 # Check for installed BASH
elif current_shell in ("/usr/bin/bash", "/bin/bash"): if current_shell.upper().find("BASH") > 0:
# Appending to zsh config file
rc_filepath = os.path.join(user_home, ".bashrc") rc_filepath = os.path.join(user_home, ".bashrc")
# Append our alias if not already existing
if os.path.isfile(rc_filepath): if os.path.isfile(rc_filepath):
with open(rc_filepath, 'a') as file1: fileRc = open(rc_filepath, "r") # open file in read mode
backuppy_entry_exists = False
for line in fileRc:
if "alias backuppy=" in line:
backuppy_entry_exists = True
break
if not backuppy_entry_exists:
trace(f"Writing {ALIAS_STR} to config file '{rc_filepath}'.") trace(f"Writing {ALIAS_STR} to config file '{rc_filepath}'.")
file1.write("\n# Following line was created by Backuppy\n" + ALIAS_STR + "\n") fileRc = open(rc_filepath, "a") # open file in append mode
fileRc.write("\n# Following line was created by Backuppy\n" + ALIAS_STR + "\n")
fileRc.close()
## STEP 2: Create the exclude script if desired ## STEP 2: Create the exclude script if desired
if EXCLUDE: if EXCLUDE: