You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.8KB

  1. #!/usr/bin/env python3
  2. #
  3. # Update plugin manifest.json from information contained in repository submodule
  4. #
  5. import os
  6. import sys
  7. import re
  8. import json
  9. # Community repository root
  10. REPO_ROOT = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")
  11. def get_plugin_version(plugin_path):
  12. with open(os.path.join(plugin_path, "Makefile"), "r") as f:
  13. version = [line for line in f.readlines() if "VERSION" in line][0]
  14. return version.split("=")[1].split()[0].strip() # Ignore comments on line
  15. def write_plugin_version(manifest_path, version):
  16. # Use OrderedDict to preserve key order in json file
  17. from collections import OrderedDict
  18. mj = None
  19. with open(manifest_path, "r") as f:
  20. mj = json.loads(f.read(), object_pairs_hook=OrderedDict)
  21. with open(manifest_path, "w") as f:
  22. mj["latestVersion"] = version
  23. json.dump(mj, f, indent=2)
  24. def validate_version(version):
  25. # Valid Rack plugin version has three digits, e.g. 0.6.0
  26. return re.match(r"^[0-9]\.[0-9]\.[0-9]$", version)
  27. def main():
  28. errors = False
  29. for repo in os.listdir(os.path.join(REPO_ROOT, "repos")):
  30. repo_path = os.path.join(REPO_ROOT, "repos", repo)
  31. plugin_version = get_plugin_version(repo_path)
  32. if (validate_version(plugin_version)):
  33. manifest_path = os.path.join(REPO_ROOT, "manifests", repo+".json")
  34. if os.path.exists(manifest_path):
  35. write_plugin_version(manifest_path, plugin_version)
  36. else:
  37. print("[%s] Manifest does not exist" % repo)
  38. errors = True
  39. continue
  40. else:
  41. print("[%s] Invalid version: %s" % (repo, plugin_version))
  42. errors = True
  43. continue
  44. return 0 if not errors else 1
  45. if __name__ == "__main__":
  46. sys.exit(main())