Files
python_skripte/check_and_add_pull_git/main.py

33 lines
966 B
Python

#!/usr/bin/env python3
import os, shutil, crontab, sys
def search_str(file_path, word):
with open(file_path, 'r') as file:
# read all content of a file
content = file.read()
# check if string present in a file
if word in content:
return True
else:
return False
user_bin = os.environ["HOME"] + os.sep + "bin"
user_zshrc = os.environ["HOME"] + "/.zshrc"
if not os.path.exists(user_bin):
os.mkdir(user_bin)
if not search_str(user_zshrc, 'PATH=$PATH:'):
with open(user_zshrc, 'a') as zshrc:
print('PATH=$PATH:' + user_bin, file=zshrc)
else:
print('PATH=$PATH:', "exist in", user_zshrc, sep=' ')
try:
copy_file = shutil.copyfile(os.path.dirname(os.path.realpath(sys.argv[0])) + os.sep + "pull_and_push.py", user_bin + os.sep + "pull_and_push")
os.chmod(user_bin + os.sep + "pull_and_push",0o775)
except FileExistsError:
print("File konnte nicht kopiert werden")