You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
877 B

  1. from __future__ import unicode_literals
  2. import subprocess
  3. from .common import PostProcessor
  4. from ..compat import compat_shlex_quote
  5. from ..utils import (
  6. encodeArgument,
  7. PostProcessingError,
  8. )
  9. class ExecAfterDownloadPP(PostProcessor):
  10. def __init__(self, downloader, exec_cmd):
  11. super(ExecAfterDownloadPP, self).__init__(downloader)
  12. self.exec_cmd = exec_cmd
  13. def run(self, information):
  14. cmd = self.exec_cmd
  15. if '{}' not in cmd:
  16. cmd += ' {}'
  17. cmd = cmd.replace('{}', compat_shlex_quote(information['filepath']))
  18. self._downloader.to_screen('[exec] Executing command: %s' % cmd)
  19. retCode = subprocess.call(encodeArgument(cmd), shell=True)
  20. if retCode != 0:
  21. raise PostProcessingError(
  22. 'Command returned error code %d' % retCode)
  23. return [], information