checkout.py 668 B

12345678910111213141516171819202122232425262728293031323334
  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 as e:
  13. print("CheckoutError:", e)
  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()
  24. os.system('reboot')