update_reader.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. # THIS FILE IS A PART OF VCStudio
  2. # PYTHON 3
  3. import os
  4. from subprocess import *
  5. def get_update_info(win):
  6. # In the GTK version you could make updates by downloading new versions of
  7. # the files from the GIT repository. But it's not an easy thing to set up
  8. # seamlessly for the user. IK because similar system is already in place
  9. # for the Blender-Organizer.
  10. # This system will be somewhat simplified in the UI side of things. But a
  11. # tiny bit more complex from the underliying system. For example. In the old
  12. # release there was no notification of the update.
  13. # So this function here will check for updates.
  14. # Now I have no idea how to implement update notifications. And whether I
  15. # should in the first place. In the old update system I had often made
  16. # easy to fix mistakes. But I was relying a little bit on the fact that
  17. # people don't see immediatly that the update is available. Which I could
  18. # use to fix all the mistakes I found without calling a whole another
  19. # version. Maybe it's a good thing here too.
  20. # I think that since VCStudio Project-Manager is going to be ran as a kind
  21. # of launcher thingy... People will more often use the VCStudio it self and
  22. # rearly the launcher. And so, some kind of automatic update check could be
  23. # done. And no nasty notification. Just a number on the update icon.
  24. # Now to make it work. I need to separate the reading of network to a separate
  25. # python file. update_request.py . That I gonna run as a subprocess to this
  26. # file.
  27. # The updating it self will have to be confirmed by the user. For which will
  28. # need a UI layer. pm_updateLayer.py and a update download file for actually
  29. # donloading and saving those files. update_download.py
  30. # So let's start already.
  31. if "request" not in win.update:
  32. # This is going to open a SUBPROCESS for the getting of the update info
  33. # I'm doing it like this so there will not be lag.
  34. win.update["request"] = Popen(['stdbuf', '-o0', "python3", \
  35. os.getcwd()+"/project_manager/update_request.py"],\
  36. stdout=PIPE, universal_newlines=True)
  37. win.update["versions"] = {}
  38. win.update["get_files"] = []
  39. win.update["get_all_files"] = []
  40. while "END" not in win.update:
  41. # This going to read lines returned by the process on every frame.
  42. line = win.update["request"].stdout.readline()[:-1]
  43. if line:
  44. if line.startswith("VERSION "):
  45. try:
  46. now_version = float(line.replace("VERSION ", ""))
  47. if "count" not in win.update:
  48. win.update["count"] = 0
  49. if now_version > win.version:
  50. win.update["count"] += 1
  51. win.update["now_version"] = now_version
  52. if now_version not in win.update["versions"]:
  53. win.update["versions"][now_version] = {
  54. "open":False,
  55. "files":[],
  56. "link":"https://notabug.org/troler/foo"
  57. }
  58. except:
  59. raise()
  60. pass
  61. elif line.startswith("["):
  62. try:
  63. win.update["versions"][win.update["now_version"]]["link"] = \
  64. line[1:-1]
  65. except:
  66. pass
  67. elif line != "END":
  68. try:
  69. win.update["versions"][win.update["now_version"]]["files"]\
  70. .append(line)
  71. if win.update["now_version"] > win.version:
  72. if line not in win.update["get_files"]:
  73. win.update["get_files"].append(line)
  74. # All files. In case the user wants to update everything
  75. # or I made a mistake somewhere. There will be an option
  76. # in the update UI to download everything.
  77. if line not in win.update["get_all_files"]:
  78. win.update["get_all_files"].append(line)
  79. except:
  80. pass
  81. # To end the reading non-sense
  82. if line == "END":
  83. win.update["END"] = True