123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- #!/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 _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 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")
|