auto_commit.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/env python
  2. # -*- encoding: utf-8 -*-
  3. """
  4. @Contact : liuyuqi.gov@msn.cn
  5. @Time : 2024/07/22
  6. @License : Copyright © 2017-2022 liuyuqi. All Rights Reserved.
  7. @Desc : auto commit
  8. """
  9. import os
  10. from auto_commit.utils.colors import bcolors
  11. class AutoCommit(object):
  12. depth =2
  13. def __init__(self, params: dict, debug=False):
  14. self.params = params
  15. def _commit(self, path):
  16. """ git commit """
  17. os.chdir(path)
  18. print(f"{bcolors.OKGREEN}commiting {path}{bcolors.ENDC}")
  19. os.system("git add .")
  20. os.system("git commit -m \"Automatic Commit By liuyuqi\"")
  21. print(f"{bcolors.OKGREEN}commit success{bcolors.ENDC}")
  22. # os.chdir(work_dir)
  23. def run(self):
  24. """ run """
  25. if ".git" in os.listdir(self.params['path']):
  26. self._commit(self.params['path'])
  27. else:
  28. for root, dirs, files in os.walk(self.params['path']):
  29. if ".git" in dirs:
  30. self._commit(root)
  31. os.system("pause")