commit message from python script
This commit is contained in:
@@ -1,44 +1,33 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import os, git
|
|
||||||
|
|
||||||
class my_git():
|
import os, shutil, crontab, sys
|
||||||
def __init__(self, check_folder = str) -> None:
|
|
||||||
self.check_folders = check_folder
|
def search_str(file_path, word):
|
||||||
def check_folder(self):
|
with open(file_path, 'r') as file:
|
||||||
li_all_fo_git = []
|
# read all content of a file
|
||||||
for root, dirs, files in os.walk(self.check_folders, topdown=False):
|
content = file.read()
|
||||||
for name in dirs:
|
# check if string present in a file
|
||||||
FullPATH = str(os.path.join(root, name))
|
if word in content:
|
||||||
if name == ".git":
|
return True
|
||||||
li_all_fo_git.append(root)
|
|
||||||
return li_all_fo_git
|
|
||||||
|
|
||||||
def git_pull(self, git_folder):
|
|
||||||
repo = git.Repo(git_folder)
|
|
||||||
for remote in repo.remotes:
|
|
||||||
remote_name = repo.remote(name=remote.name)
|
|
||||||
remote_name.pull()
|
|
||||||
|
|
||||||
def git_push(self, git_folder):
|
|
||||||
repo = git.Repo(git_folder)
|
|
||||||
if not repo.is_dirty(untracked_files=True):
|
|
||||||
print('No Changes detected.')
|
|
||||||
else:
|
else:
|
||||||
print("Changes detected.")
|
return False
|
||||||
for remote in repo.remotes:
|
|
||||||
print(remote.name, remote.url)
|
|
||||||
repo.git.add('--all')
|
user_bin = os.environ["HOME"] + os.sep + "bin"
|
||||||
repo.git.commit('-m', 'commit message from python script')
|
user_zshrc = os.environ["HOME"] + "/.zshrc"
|
||||||
remote_name = repo.remote(name=remote.name)
|
|
||||||
remote_name.push()
|
if not os.path.exists(user_bin):
|
||||||
|
os.mkdir(user_bin)
|
||||||
def git_main(self):
|
|
||||||
list_git_folder = my_git.check_folder(self)
|
if not search_str(user_zshrc, 'PATH=$PATH:'):
|
||||||
for git_folder_s in list_git_folder:
|
with open(user_zshrc, 'a') as zshrc:
|
||||||
print(git_folder_s)
|
print('PATH=$PATH:' + user_bin, file=zshrc)
|
||||||
#my_git.git_pull(self, git_folder=git_folder_s)
|
else:
|
||||||
my_git.git_push(self, git_folder=git_folder_s)
|
print('PATH=$PATH:', "exist in", user_zshrc, sep=' ')
|
||||||
|
|
||||||
if __name__ == "__main__":
|
try:
|
||||||
check_my_git = my_git(check_folder= os.sep + "home" + os.sep + os.environ["USER"] + os.sep + "Projekte")
|
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")
|
||||||
check_my_git.git_main()
|
|
||||||
|
os.chmod(user_bin + os.sep + "pull_and_push",0o775)
|
||||||
|
except FileExistsError:
|
||||||
|
print("File konnte nicht kopiert werden")
|
||||||
44
check_and_add_pull_git/pull_and_push.py
Normal file
44
check_and_add_pull_git/pull_and_push.py
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
import os, git
|
||||||
|
|
||||||
|
class my_git():
|
||||||
|
def __init__(self, check_folder = str) -> None:
|
||||||
|
self.check_folders = check_folder
|
||||||
|
def check_folder(self):
|
||||||
|
li_all_fo_git = []
|
||||||
|
for root, dirs, files in os.walk(self.check_folders, topdown=False):
|
||||||
|
for name in dirs:
|
||||||
|
FullPATH = str(os.path.join(root, name))
|
||||||
|
if name == ".git":
|
||||||
|
li_all_fo_git.append(root)
|
||||||
|
return li_all_fo_git
|
||||||
|
|
||||||
|
def git_pull(self, git_folder):
|
||||||
|
repo = git.Repo(git_folder)
|
||||||
|
for remote in repo.remotes:
|
||||||
|
remote_name = repo.remote(name=remote.name)
|
||||||
|
remote_name.pull()
|
||||||
|
|
||||||
|
def git_push(self, git_folder):
|
||||||
|
repo = git.Repo(git_folder)
|
||||||
|
if not repo.is_dirty(untracked_files=True):
|
||||||
|
print('No Changes detected.')
|
||||||
|
else:
|
||||||
|
print("Changes detected.")
|
||||||
|
for remote in repo.remotes:
|
||||||
|
print(remote.name, remote.url)
|
||||||
|
repo.git.add('--all')
|
||||||
|
repo.git.commit('-m', 'commit message from python script')
|
||||||
|
remote_name = repo.remote(name=remote.name)
|
||||||
|
remote_name.push()
|
||||||
|
|
||||||
|
def git_main(self):
|
||||||
|
list_git_folder = my_git.check_folder(self)
|
||||||
|
for git_folder_s in list_git_folder:
|
||||||
|
print(git_folder_s)
|
||||||
|
#my_git.git_pull(self, git_folder=git_folder_s)
|
||||||
|
my_git.git_push(self, git_folder=git_folder_s)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
check_my_git = my_git(check_folder= os.sep + "home" + os.sep + os.environ["USER"] + os.sep + "Projekte")
|
||||||
|
check_my_git.git_main()
|
||||||
Reference in New Issue
Block a user