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.

117 lines
3.4KB

  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. # Get package mtime
  13. package_filename = f"{slug}-{version}-lin-x64.vcvplugin"
  14. package_path = os.path.join(PACKAGES_DIR, package_filename)
  15. mtime = os.path.getmtime(package_path)
  16. if mtime:
  17. return mtime
  18. # Alternative package filename
  19. package_filename = f"{slug}-{version}-lin.vcvplugin"
  20. package_path = os.path.join(PACKAGES_DIR, package_filename)
  21. mtime = os.path.getmtime(package_path)
  22. if mtime:
  23. return mtime
  24. return None
  25. # Get the timestamp of the earliest commit touching the manifest file
  26. def get_plugin_creation(manifest_filename):
  27. stdout = common.run(f"git log --format=%ct -- {manifest_filename} | tail -1")
  28. stdout = stdout.strip()
  29. # Use current time as a fallback because if there's no commit with the module, it was added just now.
  30. if not stdout:
  31. return time.time()
  32. return float(stdout)
  33. # Get the timestamp of the earliest commit having the module slug
  34. def get_module_creation(manifest_filename, module_slug):
  35. stdout = common.run(f"git log --format='%H %ct' -- {manifest_filename}")
  36. # Use current time as a fallback because if there's no commit with the module, it was added just now.
  37. earliestTime = time.time()
  38. for line in stdout.strip().split("\n"):
  39. # "".split("\n") == [""] which is dumb
  40. if not line:
  41. continue
  42. hash, timestamp = line.split(" ")
  43. try:
  44. stdout = common.run(f"git show {hash}:{manifest_filename}")
  45. manifest = json.loads(stdout)
  46. # If the module exists in this commit, keep iterating
  47. if not common.find(manifest.get('modules', []), lambda module: module['slug'] == module_slug):
  48. break
  49. except:
  50. # If git fails, then the commit didn't actually touch the manifest file, so we can skip it.
  51. continue
  52. earliestTime = float(timestamp)
  53. return earliestTime
  54. def update():
  55. # Load existing dataset
  56. cache_filename = "manifests-cache.json"
  57. try:
  58. with open(cache_filename) as f:
  59. cache = json.load(f)
  60. except:
  61. cache = {}
  62. # Iterate plugins
  63. for manifest_filename in glob.glob('manifests/*.json'):
  64. with open(manifest_filename) as f:
  65. plugin = json.load(f)
  66. plugin_slug = plugin['slug']
  67. cache_plugin = cache.get(plugin_slug, {})
  68. # Get plugin build
  69. print(f"Getting buildTimestamp for plugin {plugin_slug}")
  70. try:
  71. cache_plugin['buildTimestamp'] = get_plugin_build(plugin)
  72. except:
  73. pass
  74. # Get plugin creation
  75. if 'creationTimestamp' not in cache_plugin:
  76. print(f"Getting creationTimestamp for plugin {plugin_slug}")
  77. cache_plugin['creationTimestamp'] = get_plugin_creation(manifest_filename)
  78. # Iterate modules in plugin
  79. cache_modules = cache_plugin.get('modules', {})
  80. for module in plugin.get('modules', []):
  81. module_slug = module['slug']
  82. cache_module = cache_modules.get(module_slug, {})
  83. # Get module creation
  84. if 'creationTimestamp' not in cache_module:
  85. print(f"Getting creationTimestamp for plugin {plugin_slug} module {module_slug}")
  86. cache_module['creationTimestamp'] = get_module_creation(manifest_filename, module_slug)
  87. cache_modules[module_slug] = cache_module
  88. cache_plugin['modules'] = cache_modules
  89. cache[plugin_slug] = cache_plugin
  90. with open(cache_filename, 'w') as f:
  91. json.dump(cache, f, indent=2)
  92. if __name__ == "__main__":
  93. update()