audiogen_static.py 868 B

123456789101112131415161718192021222324252627282930313233
  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(
  19. suffix=os.path.splitext(path)[-1], prefix="static-%s-" % shortname(path)
  20. )
  21. os.close(tmp[0])
  22. log.info("copying %s -> %s", path, os.path.basename(tmp[1]))
  23. shutil.copy(path, tmp[1])
  24. yield "file://{}".format(tmp[1])
  25. generate.description = "Picks always the same specified file"