]>
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 | ||
a2360a4c | 23 | def run(self, information): |
8d31fa3c | 24 | cmd = self.exec_cmd |
83e865a3 | 25 | if '{}' not in cmd: |
8d31fa3c | 26 | cmd += ' {}' |
a7cacbca | 27 | |
702ccf2d | 28 | cmd = cmd.replace('{}', compat_shlex_quote(information['filepath'])) |
8d31fa3c | 29 | |
1b77b347 | 30 | self.to_screen('Executing command: %s' % cmd) |
8b6ac49e | 31 | retCode = subprocess.call(encodeArgument(cmd), shell=True) |
8d31fa3c PH |
32 | if retCode != 0: |
33 | raise PostProcessingError( | |
34 | 'Command returned error code %d' % retCode) | |
a7cacbca | 35 | |
592e97e8 | 36 | return [], information |