A flat-file CMS written in Python and Flask
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

git.py 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import re
  2. import sh
  3. from yird.settings import Settings
  4. class GitService:
  5. git = sh.git.bake(_cwd=Settings().YIRD_PATH)
  6. @classmethod
  7. def get_status(cls):
  8. files = []
  9. initialized = False
  10. try:
  11. status = cls.git.status("-s", "-uall").strip()
  12. for line in status.split("\n"):
  13. if line[0:9] == "\x1b[31mM\x1b[m":
  14. files.append({
  15. "filename": line[10:],
  16. "status": "modified"
  17. })
  18. elif line[0:9] == "\x1b[32mM\x1b[m":
  19. files.append({
  20. "filename": line[10:],
  21. "status": "added and modified"
  22. })
  23. elif line[0:10] == "\x1b[31m??\x1b[m":
  24. files.append({
  25. "filename": line[11:],
  26. "status": "untracked"
  27. })
  28. initialized = True
  29. except sh.ErrorReturnCode_128 as e:
  30. if re.search('not a git repository', str(e)):
  31. initialized = False
  32. return {
  33. "git": {
  34. "initialized": initialized,
  35. "file_statuses": files
  36. }
  37. }
  38. @classmethod
  39. def init(cls):
  40. cls.git.init()