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.

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