replace.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import sys
  2. from pprint import pprint
  3. import re
  4. import datetime
  5. VERSION_PATTERN = re.compile(r'^PLUGIN_VERSION\s+=\s+"([^"]+)"$', re.MULTILINE)
  6. if __name__ == "__main__":
  7. channel = sys.argv[2] if len(sys.argv) == 3 else "stable"
  8. now = datetime.datetime.now()
  9. date = now.strftime("%d.%m.%Y - %H:%M:%S")
  10. # Addon
  11. with open("src/consts.py", "r") as f:
  12. version_match = VERSION_PATTERN.search(f.read())
  13. if version_match:
  14. VERSION = version_match.group(1)
  15. else:
  16. VERSION = "0.0.0"
  17. content = ""
  18. with open("addon_template.xml", "r") as f:
  19. content = f.read()
  20. with open("addon.xml", "w") as f:
  21. f.write(
  22. content
  23. .replace("%RELEASE%", "" if channel == "stable" else "_beta")
  24. .replace("%CHANNEL%", channel)
  25. .replace("%NEWLINE%", "\n")
  26. .replace("%VERSION%", VERSION)
  27. .replace("%DATE%", date)
  28. )
  29. # Settings
  30. content = ""
  31. with open("settings_template.xml", "r") as f:
  32. content = f.read()
  33. with open("resources/settings.xml", "w") as f:
  34. f.write(content
  35. .replace("%RELEASE%", "" if channel == "stable" else "_beta")
  36. .replace("%CHANNEL%", channel)
  37. .replace("%NEWLINE%", "\n")
  38. .replace("%VERSION%", VERSION)
  39. .replace("%DATE%", date))
  40. content = ""
  41. with open(sys.argv[1], "r") as f:
  42. content = f.read()
  43. content = content.replace("%RELEASE%", channel)
  44. content = re.sub(r"\nfrom ((?:utils|viewids|watchdog|consts|compressedcookielib|portal|api|playerwatcher).*)", "", content)
  45. content = re.sub(r"\nimport ((?:utils|viewids|watchdog|consts|compressedcookielib|portal|api|playerwatcher).*)", "", content)
  46. with open(sys.argv[1], "w") as f:
  47. f.write(content)