audiogen_static.py 651 B

123456789101112131415161718192021222324
  1. import os
  2. import logging
  3. import shutil
  4. from tempfile import mkstemp
  5. def generate(spec):
  6. '''
  7. resolves audiospec-static
  8. Recognized argument is "paths" (list of static paths)
  9. '''
  10. if 'paths' not in spec:
  11. raise ValueError("Malformed audiospec: missing 'paths'")
  12. for path in spec['paths']:
  13. if not os.path.exists(path):
  14. logging.warn("Can't find requested path: %s" % path)
  15. continue
  16. tmp = mkstemp(suffix=os.path.splitext(path)[-1],
  17. prefix='audiogen-static-')
  18. os.close(tmp[0])
  19. shutil.copy(path, tmp[1])
  20. yield u'file://{}'.format(tmp[1])