pull.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. localrep = "/home/backup"
  2. otaPath = "/root/preset/app/ota.py"
  3. from maix import camera, display, image # 引入python模块包
  4. image.load_freetype("/root/preset/fonts/simhei.ttf")
  5. hello_img = image.new(size=(320, 240), color=(0, 0, 0), mode="RGB")
  6. hello_img.draw_string(10, 115, 'Pull', scale=1.0, color=(255, 255, 255), thickness=1)
  7. display.show(hello_img)
  8. import git, time
  9. if not git.isOnline(localrep):
  10. hello_img = image.new(size=(320, 240), color=(0, 0, 0), mode="RGB")
  11. hello_img.draw_string(10, 115, 'Network connection error', scale=1.0, color=(255, 255, 255), thickness=1)
  12. display.show(hello_img)
  13. time.sleep(2)
  14. exit()
  15. from io import RawIOBase
  16. class NewStream(RawIOBase):
  17. def write(self, b):
  18. hello_img = image.new(size=(320, 240), color=(0, 0, 0), mode="RGB")
  19. hello_img.draw_string(10, 115, str(b), scale=1.0, color=(255, 255, 255), thickness=1)
  20. display.show(hello_img)
  21. return None
  22. git.rw()
  23. steam = NewStream()
  24. git.pull(localrep, steam)
  25. hello_img = image.new(size=(320, 240), color=(0, 0, 0), mode="RGB")
  26. commit, Author, Date, message = git.__log__(localrep)
  27. hello_img.draw_string(10, 50, commit, scale=1.0, color=(255, 255, 255), thickness=1)
  28. hello_img.draw_string(10, 100, Author, scale=1.0, color=(255, 255, 255), thickness=1)
  29. hello_img.draw_string(10, 150, Date, scale=1.0, color=(255, 255, 255), thickness=1)
  30. hello_img.draw_string(10, 200, message, scale=1.0, color=(255, 255, 255), thickness=1)
  31. display.show(hello_img)
  32. with open(otaPath) as f:
  33. code = f.read()
  34. exec(code)
  35. git.ro()