execafterdownload.py 766 B

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