pull.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. localrep = "/home"
  2. from maix import camera, display, image # 引入python模块包
  3. image.load_freetype("/root/preset/fonts/simhei.ttf")
  4. hello_img = image.new(size=(320, 240), color=(0, 0, 0), mode="RGB")
  5. hello_img.draw_string(10, 115, 'Pull', scale=1.0, color=(255, 255, 255), thickness=1)
  6. display.show(hello_img)
  7. import os, git, time
  8. if not git.isOnline(localrep):
  9. hello_img = image.new(size=(320, 240), color=(0, 0, 0), mode="RGB")
  10. hello_img.draw_string(10, 115, 'Network connection error', scale=1.0, color=(255, 255, 255), thickness=1)
  11. display.show(hello_img)
  12. time.sleep(2)
  13. exit()
  14. if os.path.exists(localrep + "/cclb_launch"):
  15. os.remove(localrep + "/cclb_launch")
  16. from io import RawIOBase
  17. class NewStream(RawIOBase):
  18. def write(self, b):
  19. hello_img = image.new(size=(320, 240), color=(0, 0, 0), mode="RGB")
  20. hello_img.draw_string(10, 115, str(b), scale=1.0, color=(255, 255, 255), thickness=1)
  21. display.show(hello_img)
  22. return None
  23. git.rw()
  24. steam = NewStream()
  25. git.pull(localrep, steam)
  26. hello_img = image.new(size=(320, 240), color=(0, 0, 0), mode="RGB")
  27. commit, Author, Date, message = git.__log__(localrep)
  28. hello_img.draw_string(10, 50, commit, scale=1.0, color=(255, 255, 255), thickness=1)
  29. hello_img.draw_string(10, 100, Author, scale=1.0, color=(255, 255, 255), thickness=1)
  30. hello_img.draw_string(10, 150, Date, scale=1.0, color=(255, 255, 255), thickness=1)
  31. hello_img.draw_string(10, 200, message, scale=1.0, color=(255, 255, 255), thickness=1)
  32. display.show(hello_img)
  33. os.system('chmod -R 777 /home')
  34. os.system('rsync -r --checksum /home/backup/ /root')
  35. os.system("ps | grep main.py | grep -v grep | awk '{print $1}' | xargs kill")
  36. git.ro()