release-zip 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/usr/bin/env python3
  2. import os
  3. import zipfile
  4. import common
  5. class Main(common.LkmcCliFunction):
  6. def __init__(self):
  7. super().__init__(
  8. description='''\
  9. https://cirosantilli.com/linux-kernel-module-cheat#release-zip
  10. ''',
  11. defaults = {
  12. 'show_time': False,
  13. }
  14. )
  15. self.zip_files = []
  16. def timed_main(self):
  17. self.zip_files.append(self.env['qcow2_file'])
  18. self.zip_files.append(self.env['linux_image'])
  19. for root, dirnames, filenames in os.walk(self.env['baremetal_build_dir']):
  20. for filename in sorted(filenames):
  21. path = os.path.join(root, filename)
  22. if os.path.splitext(path)[1] == self.env['baremetal_executable_ext']:
  23. self.zip_files.append(path)
  24. def teardown(self):
  25. os.makedirs(self.env['release_dir'], exist_ok=True)
  26. self.sh.rmrf(self.env['release_zip_file'])
  27. self.log_info('Creating zip: ' + self.env['release_zip_file'])
  28. with zipfile.ZipFile(self.env['release_zip_file'], 'w', zipfile.ZIP_DEFLATED) as zipf:
  29. for zip_file in self.zip_files:
  30. self.log_info('Adding file: ' + zip_file)
  31. zipf.write(zip_file, arcname=os.path.relpath(zip_file, self.env['root_dir']))
  32. if __name__ == '__main__':
  33. Main().cli()