5
from flexget.plugin import *
7
log = logging.getLogger('exec')
12
Execute command for entries that reach output.
16
exec: echo 'found %(title)s at %(url)s > file
18
You can use all (available) entry fields in the command.
22
from flexget import validator
23
return validator.factory('text')
25
# Make sure we run after download so exec can use the output
27
def on_feed_output(self, feed):
28
for entry in feed.accepted:
30
cmd = feed.config['exec']
32
# shlex is documented to not work on unicode
33
for arg in shlex.split(cmd.encode('utf-8'), comments=True):
34
arg = unicode(arg, 'utf-8')
35
formatted = arg % entry
36
# shlex.split does not include the quotes, so we have to add them back if appropriate
37
arg = pipes.quote(formatted)
41
log.error('Entry %s does not have required field %s' % (entry['title'], e.message))
43
if feed.manager.options.test:
44
log.info('Would execute: %s' % cmd)
46
log.debug('executing cmd: %s' % cmd)
47
p = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=False)
48
(r, w) = (p.stdout, p.stdin)
53
log.info('Stdout: %s' % response)
55
register_plugin(OutputExec, 'exec')