checkout.py 633 B

123456789101112131415161718192021222324252627282930313233
  1. from dulwich import porcelain
  2. from dulwich import repo
  3. import os
  4. def ro():
  5. os.system("/etc/init.d/S01mount_ro start")
  6. def rw():
  7. os.system("/etc/init.d/S01mount_ro stop")
  8. def checkout(rep, branch):
  9. r = repo.Repo(rep)
  10. try:
  11. porcelain.checkout_branch(r, 'origin/' + branch)
  12. except porcelain.CheckoutError:
  13. print("Error")
  14. porcelain.reset(r, 'hard')
  15. porcelain.checkout_branch(r, 'origin/' + branch)
  16. localrep = "/home/"
  17. rw()
  18. if porcelain.active_branch(localrep) != b'master':
  19. checkout(localrep, 'master')
  20. else:
  21. checkout(localrep, 'en')
  22. os.remove("/root/CocoPi.py")
  23. ro()