]>
Commit | Line | Data |
---|---|---|
a2360a4c | 1 | from __future__ import unicode_literals |
8d31fa3c | 2 | |
a2360a4c | 3 | import subprocess |
8d31fa3c PH |
4 | |
5 | from .common import PostProcessor | |
702ccf2d | 6 | from ..compat import compat_shlex_quote |
8b6ac49e S |
7 | from ..utils import ( |
8 | encodeArgument, | |
9 | PostProcessingError, | |
10 | ) | |
a7cacbca | 11 | |
a7cacbca | 12 | |
a2360a4c | 13 | class ExecAfterDownloadPP(PostProcessor): |
1b77b347 | 14 | |
69b46b3d JMF |
15 | def __init__(self, downloader, exec_cmd): |
16 | super(ExecAfterDownloadPP, self).__init__(downloader) | |
8d31fa3c | 17 | self.exec_cmd = exec_cmd |
a7cacbca | 18 | |
43820c03 | 19 | @classmethod |
20 | def pp_key(cls): | |
21 | return 'Exec' | |
22 | ||
9de3ea31 | 23 | def run(self, info): |
24 | tmpl, info_copy = self._downloader.prepare_outtmpl(self.exec_cmd, info) | |
25 | cmd = tmpl % info_copy | |
26 | if cmd == self.exec_cmd: # No replacements were made | |
27 | if '{}' not in self.exec_cmd: | |
28 | self.exec_cmd += ' {}' | |
29 | cmd = self.exec_cmd.replace('{}', compat_shlex_quote(info['filepath'])) | |
8d31fa3c | 30 | |
1b77b347 | 31 | self.to_screen('Executing command: %s' % cmd) |
8b6ac49e | 32 | retCode = subprocess.call(encodeArgument(cmd), shell=True) |
8d31fa3c PH |
33 | if retCode != 0: |
34 | raise PostProcessingError( | |
35 | 'Command returned error code %d' % retCode) | |
a7cacbca | 36 | |
9de3ea31 | 37 | return [], info |