12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- #!/usr/bin/env python
- # -*- encoding: utf-8 -*-
- """
- @Contact : liuyuqi.gov@msn.cn
- @Time : 2024/07/22
- @License : Copyright © 2017-2022 liuyuqi. All Rights Reserved.
- @Desc : auto commit
- """
- import os
- from auto_commit.utils.colors import bcolors
- class AutoCommit(object):
- depth =2
- def __init__(self, params: dict, debug=False):
- self.params = params
- def _commit(self, path):
- """ git commit """
- os.chdir(path)
- print(f"{bcolors.OKGREEN} commiting {path}{bcolors.ENDC}")
- os.system("git add .")
- os.system("git commit -m \"Automatic Commit By liuyuqi\"")
- print(f"{bcolors.OKGREEN} commit finish{bcolors.ENDC}")
- # os.chdir(work_dir)
- def _check(self, path):
- """ git status """
- os.chdir(path)
- print(f"{bcolors.OKGREEN} checking {path}{bcolors.ENDC}")
- os.system("git status")
- # with os.popen("git status") as p:
- # output = p.read()
- # resData = re.split("\n", output)
- # if len(resData) > 2:
- # print(f"{bcolors.FAIL} check error: {resData} {bcolors.ENDC}")
- # exit(1)
- # print(f"{bcolors.OKGREEN} check finish{bcolors.ENDC}")
- # os.chdir(work_dir)
- def _sync(self, path):
- """ git pull """
- os.chdir(path)
- print(f"{bcolors.OKGREEN} syncing {path}{bcolors.ENDC}")
- os.system("git pull")
- os.system("git push")
- print(f"{bcolors.OKGREEN} sync finish{bcolors.ENDC}")
- # os.chdir(work_dir)
- def check(self):
- """ check project update"""
- if ".git" in os.listdir(self.params['path']):
- self._check(self.params['path'])
- else:
- for root, dirs, files in os.walk(self.params['path']):
- if ".git" in dirs:
- self._check(root)
- os.system("pause")
- def commit(self):
- """ run """
- if ".git" in os.listdir(self.params['path']):
- self._commit(self.params['path'])
- else:
- for root, dirs, files in os.walk(self.params['path']):
- if ".git" in dirs:
- self._commit(root)
- os.system("pause")
-
- def sync(self):
- """ sync """
- if ".git" in os.listdir(self.params['path']):
- self._sync(self.params['path'])
- else:
- for root, dirs, files in os.walk(self.params['path']):
- if ".git" in dirs:
- self._sync(root)
- os.system("pause")
|