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.

99 lines
2.7KB

  1. import sys
  2. import os
  3. import glob
  4. import json
  5. import time
  6. import common
  7. PACKAGES_DIR = "../packages"
  8. # Get the timestamp of the earliest commit touching the manifest file
  9. def get_plugin_build(plugin):
  10. slug = plugin['slug']
  11. version = plugin['version']
  12. arch = 'lin'
  13. package_filename = f"{slug}-{version}-{arch}.zip"
  14. package_path = PACKAGES_DIR + "/" + package_filename
  15. return os.path.getmtime(package_path)
  16. # Get the timestamp of the earliest commit touching the manifest file
  17. def get_plugin_creation(manifest_filename):
  18. stdout = common.system(f"git log --format=%ct -- {manifest_filename} | tail -1")
  19. return float(stdout.strip())
  20. # Get the timestamp of the earliest commit having the module slug
  21. def get_module_creation(manifest_filename, module_slug):
  22. stdout = common.system(f"git log --format='%H %ct' -- {manifest_filename}")
  23. # Use current time as a fallback because if there's no commit with the module, it was added just now.
  24. earliestTime = time.time()
  25. for line in stdout.strip().split("\n"):
  26. hash, timestamp = line.split(" ")
  27. try:
  28. stdout = common.system(f"git show {hash}:{manifest_filename}")
  29. manifest = json.loads(stdout)
  30. # If the module exists in this commit, keep iterating
  31. if not common.find(manifest.get('modules', []), lambda module: module['slug'] == module_slug):
  32. break
  33. except:
  34. # If git fails, then the commit didn't actually touch the manifest file, so we can skip it.
  35. continue
  36. earliestTime = float(timestamp)
  37. return earliestTime
  38. def update():
  39. # Load existing dataset
  40. cache_filename = "manifests-cache.json"
  41. try:
  42. with open(cache_filename) as f:
  43. cache = json.load(f)
  44. except:
  45. cache = {}
  46. # Iterate plugins
  47. for manifest_filename in glob.glob('manifests/*.json'):
  48. with open(manifest_filename) as f:
  49. plugin = json.load(f)
  50. plugin_slug = plugin['slug']
  51. cache_plugin = cache.get(plugin_slug, {})
  52. # Get plugin build
  53. if 'buildTimestamp' not in cache_plugin:
  54. try:
  55. cache_plugin['buildTimestamp'] = get_plugin_build(plugin)
  56. except:
  57. pass
  58. # Get plugin creation
  59. if 'creationTimestamp' not in cache_plugin:
  60. cache_plugin['creationTimestamp'] = get_plugin_creation(manifest_filename)
  61. # Iterate modules in plugin
  62. cache_modules = cache_plugin.get('modules', {})
  63. for module in plugin.get('modules', []):
  64. module_slug = module['slug']
  65. cache_module = cache_modules.get(module_slug, {})
  66. # Get module creation
  67. if 'creationTimestamp' not in cache_module:
  68. cache_module['creationTimestamp'] = get_module_creation(manifest_filename, module_slug)
  69. cache_modules[module_slug] = cache_module
  70. cache_plugin['modules'] = cache_modules
  71. cache[plugin_slug] = cache_plugin
  72. with open(cache_filename, 'w') as f:
  73. json.dump(cache, f, indent=2)
  74. if __name__ == "__main__":
  75. update()