]>
Commit | Line | Data |
---|---|---|
1 | from __future__ import unicode_literals | |
2 | ||
3 | import subprocess | |
4 | ||
5 | from .common import PostProcessor | |
6 | from ..compat import compat_shlex_quote | |
7 | from ..utils import ( | |
8 | encodeArgument, | |
9 | PostProcessingError, | |
10 | ) | |
11 | ||
12 | ||
13 | class ExecAfterDownloadPP(PostProcessor): | |
14 | ||
15 | def __init__(self, downloader, exec_cmd): | |
16 | super(ExecAfterDownloadPP, self).__init__(downloader) | |
17 | self.exec_cmd = exec_cmd | |
18 | ||
19 | @classmethod | |
20 | def pp_key(cls): | |
21 | return 'Exec' | |
22 | ||
23 | def run(self, information): | |
24 | cmd = self.exec_cmd | |
25 | if '{}' not in cmd: | |
26 | cmd += ' {}' | |
27 | ||
28 | cmd = cmd.replace('{}', compat_shlex_quote(information['filepath'])) | |
29 | ||
30 | self.to_screen('Executing command: %s' % cmd) | |
31 | retCode = subprocess.call(encodeArgument(cmd), shell=True) | |
32 | if retCode != 0: | |
33 | raise PostProcessingError( | |
34 | 'Command returned error code %d' % retCode) | |
35 | ||
36 | return [], information |