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