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

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