Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow variables plugin to replace arbitrary sections of config #2222

Merged
merged 2 commits into from Oct 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion flexget/_version.py
Expand Up @@ -7,4 +7,4 @@
The jenkins release job will automatically strip the .dev for release,
and update the version again for continued development.
"""
__version__ = '2.15.2.dev'
__version__ = '2.16.0.dev'
10 changes: 7 additions & 3 deletions flexget/plugins/modify/variables.py
Expand Up @@ -8,7 +8,8 @@

import yaml

from jinja2 import Environment, TemplateError
from jinja2 import TemplateError
from jinja2.nativetypes import NativeEnvironment

from sqlalchemy import Column
from sqlalchemy.sql.sqltypes import Unicode, DateTime, Integer
Expand Down Expand Up @@ -76,10 +77,13 @@ def process_variables(config, manager):
}
if 'variables' not in config or config.get('variables') is False:
return
env = Environment(**env_params)
env = NativeEnvironment(**env_params)
if isinstance(config['variables'], bool):
log.debug('trying to load variables from DB')
variables = variables_from_db()
elif isinstance(config['variables'], dict):
log.debug('loading variables from config')
variables = config['variables']
else:
log.debug('trying to load variables from file')
variables = variables_from_file(manager.config_base, config['variables'])
Expand Down Expand Up @@ -113,7 +117,7 @@ def _process(element, environment):
return None


variables_config_schema = {'type': ['string', 'boolean']}
variables_config_schema = {'type': ['string', 'boolean', 'object']}


@event('config.register')
Expand Down
30 changes: 30 additions & 0 deletions flexget/tests/test_variables.py
Expand Up @@ -40,6 +40,36 @@ def test_variables_alongside_jinja(self, execute_task):
assert task.accepted[0]['a_field'] == 'first bar then foo end'


class TestVariablesFromConfig():
config = """
variables:
mock_entry_list:
- title: a
- title: b
integer: 2
tasks:
test_int_var:
mock:
- title: a
- title: b
- title: c
accept_all: yes
limit_new: "{? integer ?}"
test_var_mock:
mock: "{? mock_entry_list ?}"
"""

def test_complex_var(self, execute_task):
task = execute_task('test_var_mock')
assert len(task.all_entries) == 2
assert task.all_entries[1]['title'] == 'b'

def test_int_var(self, execute_task):
task = execute_task('test_int_var')
assert len(task.all_entries) == 3
assert len(task.accepted) == 2


class TestVariablesFromDB(object):
config = """
variables: yes
Expand Down
2 changes: 1 addition & 1 deletion flexget/tests/variables.yml
@@ -1,2 +1,2 @@
test_variable: yes
bar_var: bar
bar_var: bar
2 changes: 1 addition & 1 deletion requirements.in
Expand Up @@ -8,7 +8,7 @@ PyRSS2Gen
pynzb
#PY3 progressbar
rpyc==3.3.0
jinja2
jinja2~=2.10
# There is a bug in requests 2.4.0 where it leaks urllib3 exceptions
requests~=2.16.3
#Guessit requires python-dateutil<=2.5.2
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Expand Up @@ -26,7 +26,7 @@ guessit==2.1.4
html5lib==0.999999999
idna==2.5 # via requests
itsdangerous==0.24 # via flask
jinja2==2.9.6
jinja2==2.10
jsonschema==2.6.0
markupsafe==1.0 # via jinja2
path.py==10.3.1
Expand Down