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.

28 lines
832 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 PostProcessingError
  6. class ExecAfterDownloadPP(PostProcessor):
  7. def __init__(self, downloader, exec_cmd):
  8. super(ExecAfterDownloadPP, self).__init__(downloader)
  9. self.exec_cmd = exec_cmd
  10. def run(self, information):
  11. cmd = self.exec_cmd
  12. if '{}' not in cmd:
  13. cmd += ' {}'
  14. cmd = cmd.replace('{}', compat_shlex_quote(information['filepath']))
  15. self._downloader.to_screen('[exec] Executing command: %s' % cmd)
  16. retCode = subprocess.call(cmd, shell=True)
  17. if retCode != 0:
  18. raise PostProcessingError(
  19. 'Command returned error code %d' % retCode)
  20. return [], information