release_patch.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. import re
  2. import os
  3. lastNum = re.compile(r'(?:[^\d]*(\d+)[^\d]*)+')
  4. def title(t):
  5. print("\n---------------------------------")
  6. print(t)
  7. print("---------------------------------")
  8. def cmd(c):
  9. print("\n" + c)
  10. os.system(c)
  11. def increment(s):
  12. """ look for the last sequence of number(s) in a string and increment """
  13. m = lastNum.search(s)
  14. if m:
  15. next = str(int(m.group(1))+1)
  16. start, end = m.span(1)
  17. s = s[:max(end-len(next), start)] + next + s[end:]
  18. return s, str(next)
  19. def lvgl_clone():
  20. title("lvgl: Clone")
  21. cmd("git clone https://github.com/littlevgl/lvgl.git")
  22. os.chdir("./lvgl")
  23. cmd("git co master")
  24. def lvgl_update_version():
  25. title("lvgl: Update version number")
  26. f = open("./src/lv_version.h", "r")
  27. outbuf = ""
  28. major_ver = -1
  29. minor_ver = -1
  30. patch_ver = -1
  31. for i in f.read().splitlines():
  32. r = re.search(r'^#define LVGL_VERSION_MAJOR ', i)
  33. if r:
  34. m = lastNum.search(i)
  35. if m: major_ver = m.group(1)
  36. r = re.search(r'^#define LVGL_VERSION_MINOR ', i)
  37. if r:
  38. m = lastNum.search(i)
  39. if m: minor_ver = m.group(1)
  40. r = re.search(r'^#define LVGL_VERSION_PATCH ', i)
  41. if r:
  42. i, patch_ver = increment(i)
  43. r = re.search(r'^#define LVGL_VERSION_INFO ', i)
  44. if r:
  45. i = "#define LVGL_VERSION_INFO \"\""
  46. outbuf += i + '\n'
  47. f.close()
  48. f = open("./src/lv_version", "w")
  49. f.write(outbuf)
  50. f.close()
  51. s = "v" + str(major_ver) + "." + str(minor_ver) + "." + str(patch_ver)
  52. print("New version:" + s)
  53. return s
  54. def lvgl_update_library_json(v):
  55. title("lvgl: Update version number in library.json")
  56. f = open("./library.json", "r")
  57. outbuf = ""
  58. for i in f.read().splitlines():
  59. r = re.search(r'"version": ', i)
  60. if r:
  61. i = ' "version": "' + v + '",'
  62. outbuf += i + '\n'
  63. f.close()
  64. f = open("./library.json", "w")
  65. f.write(outbuf)
  66. f.close()
  67. def lvgl_commit_push(v):
  68. title("lvgl: commit and push release")
  69. cmd('git ci -am "Release ' + v + '"')
  70. cmd('git tag -a ' + v + ' -m "Release ' + v +'"')
  71. cmd('git push origin master')
  72. cmd('git push origin ' + v)
  73. def lvgl_update_api_docs():
  74. title("lvgl: Update API with Doxygen")
  75. cmd("cd scripts; doxygen");
  76. def docs_clone():
  77. title("docs: Clone")
  78. os.chdir("../")
  79. cmd("git clone --recursive https://github.com/littlevgl/docs.git")
  80. os.chdir("./docs")
  81. cmd("git co master")
  82. def docs_get_api():
  83. title("docs: Get API files")
  84. cmd("rm -rf xml");
  85. cmd("cp -r ../lvgl/docs/api_doc/xml .");
  86. def docs_update_version(v):
  87. title("docs: Update version number")
  88. f = open("./conf.py", "r")
  89. outbuf = ""
  90. for i in f.read().splitlines():
  91. r = re.search(r'^version = ', i)
  92. if r:
  93. i = "version = '" + v + "'"
  94. r = re.search(r'^release = ', i)
  95. if r:
  96. i = "version = '" + v + "'"
  97. outbuf += i + '\n'
  98. f.close()
  99. f = open("./conf.py", "w")
  100. f.write(outbuf)
  101. f.close()
  102. def docs_update_trans():
  103. title("docs: Update translations")
  104. cmd("cd en && ./trans_push.py && ./trans_pull.py")
  105. def docs_build():
  106. title("docs: Build")
  107. cmd("./build.py clean")
  108. def docs_commit_push(v):
  109. title("docs: Commit release")
  110. cmd('git add .')
  111. cmd('git ci -am "Release ' + v + '"')
  112. cmd('git tag -a ' + v + ' -m "Release ' + v +'"')
  113. cmd('git push origin master')
  114. cmd('git push origin ' + v)
  115. def clean_up():
  116. title("Clean up repos")
  117. os.chdir("..")
  118. cmd("rm -rf lvgl docs")
  119. lvgl_clone()
  120. lvgl_update_api_docs()
  121. ver_str = lvgl_update_version()
  122. lvgl_update_library_json(ver_str)
  123. lvgl_commit_push(ver_str)
  124. docs_clone()
  125. docs_get_api()
  126. docs_update_version(ver_str)
  127. docs_update_trans()
  128. docs_build()
  129. docs_commit_push(ver_str)
  130. clean_up()