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.

67 lines
1.6KB

  1. import sys
  2. import os
  3. import glob
  4. import json
  5. import re
  6. import requests
  7. import common
  8. # Get the timestamp of the earliest commit touching the manifest file
  9. def get_plugin_creation(manifest_filename):
  10. stdout = common.system(f"git log --format=%ct -- {manifest_filename} | tail -1")
  11. return float(stdout.strip())
  12. # Get the timestamp of the earliest commit having the module slug
  13. def get_module_creation(manifest_filename, module_slug):
  14. stdout = common.system(f"git log --format='%H %ct' -- {manifest_filename}")
  15. for line in stdout.strip().split("\n"):
  16. hash, time = line.split(" ")
  17. stdout = common.system(f"git show {hash}:{manifest_filename}")
  18. print(stdout)
  19. def update():
  20. # Load existing dataset
  21. cache_filename = "manifest-cache.json"
  22. with open(cache_filename) as f:
  23. cache = json.load(f)
  24. # Iterate plugins
  25. for manifest_filename in glob.glob('manifests/*.json'):
  26. with open(manifest_filename) as f:
  27. plugin = json.load(f)
  28. plugin_slug = plugin['slug']
  29. cache_plugin = cache.get(plugin_slug, {})
  30. # Get plugin creation
  31. if 'creationTimestamp' not in cache_plugin:
  32. cache_plugin['creationTimestamp'] = get_plugin_creation(manifest_filename)
  33. # Iterate modules in plugin
  34. cache_modules = cache.get('modules', {})
  35. for module in plugin.get('modules', []):
  36. module_slug = module['slug']
  37. cache_module = cache_modules.get(module_slug, {})
  38. # TODO
  39. # Get module creation
  40. # get_module_creation()
  41. # exit()
  42. cache_modules[module_slug] = cache_module
  43. cache_plugin['modules'] = cache_modules
  44. cache[plugin_slug] = cache_plugin
  45. with open(cache_filename, 'w') as f:
  46. json.dump(cache, f, indent=2)
  47. if __name__ == "__main__":
  48. update()