find_kernels.py 900 B

123456789101112131415161718192021222324252627282930
  1. #!/usr/bin/env python3
  2. import os
  3. import glob
  4. import sys
  5. from typing import List
  6. def find_kernels(directory: str) -> List[str]:
  7. return glob.glob(f"{directory}/**/vmlinuz-*", recursive=True)
  8. def find_modules_directory(directory: str, kernel: str) -> str:
  9. matches = glob.glob(f"{directory}/**/modules/{kernel}", recursive=True)
  10. if len(matches) != 1:
  11. raise RuntimeError(f"Expected to find exactly one modules directory. Found {len(matches)}.")
  12. return matches[0]
  13. def main() -> None:
  14. images = find_kernels('test/.tmp')
  15. modules = []
  16. for image in images:
  17. image_name = os.path.basename(image).replace('vmlinuz-', '')
  18. module_dir = find_modules_directory('test/.tmp', image_name)
  19. modules.append(module_dir)
  20. args = ' '.join(f"{image}:{module}" for image, module in zip(images, modules))
  21. print(args)
  22. if __name__ == "__main__":
  23. main()