pull.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. localrep = "/home/backup"
  2. remoteurl = 'https://git.cocorobo.cn/liushuai/CocoPi_upgrade.git'
  3. otaPath = "/root/preset/app/ota.py"
  4. from maix import camera, display, image # 引入python模块包
  5. image.load_freetype("/root/preset/fonts/simhei.ttf")
  6. hello_img = image.new(size=(320, 240), color=(0, 0, 0), mode="RGB")
  7. hello_img.draw_string(10, 115, 'Pull', scale=1.0, color=(255, 255, 255), thickness=1)
  8. display.show(hello_img)
  9. import git, time
  10. if not git.isOnline(localrep):
  11. hello_img = image.new(size=(320, 240), color=(0, 0, 0), mode="RGB")
  12. hello_img.draw_string(10, 115, 'Network connection error', scale=1.0, color=(255, 255, 255), thickness=1)
  13. display.show(hello_img)
  14. time.sleep(2)
  15. exit()
  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. git.swRemote(localrep, remoteurl)
  25. steam = NewStream()
  26. git.pull(localrep, steam)
  27. # hello_img = image.new(size=(320, 240), color=(0, 0, 0), mode="RGB")
  28. # commit, Author, Date, message = git.__log__(localrep)
  29. # hello_img.draw_string(10, 50, commit, scale=1.0, color=(255, 255, 255), thickness=1)
  30. # hello_img.draw_string(10, 100, Author, scale=1.0, color=(255, 255, 255), thickness=1)
  31. # hello_img.draw_string(10, 150, Date, scale=1.0, color=(255, 255, 255), thickness=1)
  32. # hello_img.draw_string(10, 200, message, scale=1.0, color=(255, 255, 255), thickness=1)
  33. # display.show(hello_img)
  34. with open(otaPath) as f:
  35. code = f.read()
  36. exec(code)
  37. git.ro()