list.py 911 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import glob
  2. import os
  3. from pathlib import Path
  4. import subprocess
  5. from ...utils.deps import CACHE_DIR
  6. from ...utils.log import log
  7. __all__ = ['execute']
  8. def _unpack_args(args):
  9. '''Unpack command line arguments
  10. '''
  11. return tuple()
  12. def execute():
  13. '''List cached image(s)
  14. '''
  15. cache = Path(CACHE_DIR)
  16. images = sorted(os.listdir(cache / 'share/images'))
  17. for image in images:
  18. tags = ', '.join((
  19. tag[:-5] for tag in \
  20. sorted(os.listdir(cache / f'share/images/{image}/tags'))
  21. ))
  22. if not tags:
  23. continue
  24. path = cache / f'share/images/{image}'
  25. memory = _getsize(path)
  26. log('LIST', f'{image} ({tags}) [{memory}]')
  27. def _getsize(path: Path):
  28. r = subprocess.run(f'du -sh {path}', capture_output=True, check=True,
  29. shell=True)
  30. return r.stdout.decode().split(None, 1)[0]