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
871 B

  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, verboseOutput=None, exec_cmd=None):
  8. self.verboseOutput = verboseOutput
  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('{}', 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 None, information # by default, keep file and do nothing