Write alias only if not already existing
This commit is contained in:
parent
1dfe37a970
commit
5d367fa1a8
2 changed files with 28 additions and 17 deletions
10
CHANGELOG.md
10
CHANGELOG.md
|
@ -1,6 +1,10 @@
|
|||
# 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
|
||||
- Now fully functional as the shell version
|
||||
|
||||
|
@ -11,11 +15,11 @@
|
|||
### Fixed
|
||||
- Fixed problem with the Bash/ZSH config
|
||||
|
||||
## [1.01.001] - 2021-05-04
|
||||
## [0.5.1] - 2021-05-04
|
||||
### Changed
|
||||
- Use E-MAIL constant
|
||||
|
||||
## [1.01.000] - 2021-05-04
|
||||
## [0.5] - 2021-05-04
|
||||
### Added
|
||||
- Graphical installer based on Python3 with PySide2 GUI framework (Qt-bindings for Python)
|
||||
- Changelog.MD
|
||||
|
|
35
install.py
35
install.py
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/env python3
|
||||
"""
|
||||
project: Backuppy
|
||||
version: 1.02.000
|
||||
version: 0.6
|
||||
file: install.py
|
||||
summary: main entry python file
|
||||
"""
|
||||
|
@ -10,16 +10,14 @@ summary: main entry python file
|
|||
import os
|
||||
|
||||
# Third party imports
|
||||
from PySide2 import QtCore
|
||||
from PySide2 import QtGui
|
||||
from PySide2 import QtCore, QtWidgets
|
||||
from PySide2 import QtWidgets
|
||||
|
||||
# local imports
|
||||
from languages import english
|
||||
from languages import german
|
||||
|
||||
# local globals
|
||||
VERSION: str = "1.02.000"
|
||||
VERSION: str = "0.6"
|
||||
EMAIL: str = "fotocoder@joschu.ch"
|
||||
TARGET_SCRIPT: str = "Backuppy.sh"
|
||||
EXCLUDE_FILE: str = "exclude.txt"
|
||||
|
@ -44,7 +42,7 @@ def get_lang_text(search_str: str):
|
|||
|
||||
def trace(message_txt: str):
|
||||
""" Print a formatted message to std out. """
|
||||
print(f"[ OK ]", message_txt)
|
||||
print("[ OK ]" + message_txt)
|
||||
|
||||
class BackuppyWizard(QtWidgets.QWizard):
|
||||
def __init__(self, parent=None):
|
||||
|
@ -295,20 +293,29 @@ def create_shell_script(command_str: str):
|
|||
user_home = os.environ.get("HOME")
|
||||
|
||||
## STEP 1: update shell config scripts with alias for backuppy
|
||||
# .zshrc case1 and case2
|
||||
if current_shell in ("/usr/bin/zsh", "/bin/zsh"):
|
||||
# Appending to bash config file
|
||||
# Check for installed ZSH
|
||||
if current_shell.upper().find("ZSH") > 0:
|
||||
rc_filepath = os.path.join(user_home, ".zshrc")
|
||||
|
||||
# .bashrc case1 and case2
|
||||
elif current_shell in ("/usr/bin/bash", "/bin/bash"):
|
||||
# Appending to zsh config file
|
||||
# Check for installed BASH
|
||||
if current_shell.upper().find("BASH") > 0:
|
||||
rc_filepath = os.path.join(user_home, ".bashrc")
|
||||
|
||||
# Append our alias if not already existing
|
||||
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}'.")
|
||||
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
|
||||
if EXCLUDE:
|
||||
|
|
Loading…
Reference in a new issue