audiogen_static.py 867 B

12345678910111213141516171819202122232425262728293031
  1. import os
  2. import logging
  3. import shutil
  4. from tempfile import mkstemp
  5. from larigira.fsutils import shortname
  6. log = logging.getLogger(__name__)
  7. def generate(spec):
  8. '''
  9. resolves audiospec-static
  10. Recognized argument is "paths" (list of static paths)
  11. '''
  12. if 'paths' not in spec:
  13. raise ValueError("Malformed audiospec: missing 'paths'")
  14. for path in spec['paths']:
  15. if not os.path.exists(path):
  16. log.warning("Can't find requested path: %s", path)
  17. continue
  18. tmp = mkstemp(suffix=os.path.splitext(path)[-1],
  19. prefix='static-%s-' % shortname(path))
  20. os.close(tmp[0])
  21. log.info("copying %s -> %s", path, os.path.basename(tmp[1]))
  22. shutil.copy(path, tmp[1])
  23. yield 'file://{}'.format(tmp[1])
  24. generate.description = 'Picks always the same specified file'