django_command/django_check/django_createcachetable: add return value version (#9063)
* add return value version * add changelog frag * reformat yamlpull/9067/head
parent
39f3b151e8
commit
107df41d9c
|
@ -0,0 +1,5 @@
|
|||
minor_changes:
|
||||
- django module utils - always retrieve version (https://github.com/ansible-collections/community.general/pull/9063).
|
||||
- django_check - add return value ``version`` (https://github.com/ansible-collections/community.general/pull/9063).
|
||||
- django_command - add return value ``version`` (https://github.com/ansible-collections/community.general/pull/9063).
|
||||
- django_createcachetable - add return value ``version`` (https://github.com/ansible-collections/community.general/pull/9063).
|
|
@ -32,6 +32,7 @@ _django_std_arg_fmts = dict(
|
|||
verbosity=cmd_runner_fmt.as_opt_val("--verbosity"),
|
||||
no_color=cmd_runner_fmt.as_fixed("--no-color"),
|
||||
skip_checks=cmd_runner_fmt.as_bool("--skip-checks"),
|
||||
version=cmd_runner_fmt.as_fixed("--version"),
|
||||
)
|
||||
|
||||
_django_database_args = dict(
|
||||
|
@ -60,6 +61,9 @@ class _DjangoRunner(PythonRunner):
|
|||
)
|
||||
return super(_DjangoRunner, self).__call__(args_order, output_process, ignore_value_none, check_mode_skip, check_mode_return, **kwargs)
|
||||
|
||||
def bare_context(self, *args, **kwargs):
|
||||
return super(_DjangoRunner, self).__call__(*args, **kwargs)
|
||||
|
||||
|
||||
class DjangoModuleHelper(ModuleHelper):
|
||||
module = {}
|
||||
|
@ -98,16 +102,20 @@ class DjangoModuleHelper(ModuleHelper):
|
|||
arg_formats=self.arg_formats,
|
||||
venv=self.vars.venv,
|
||||
check_rc=True)
|
||||
with runner() as ctx:
|
||||
|
||||
run_params = self.vars.as_dict()
|
||||
if self._check_mode_arg:
|
||||
run_params.update({self._check_mode_arg: self.check_mode})
|
||||
|
||||
rc, out, err = runner.bare_context("version").run()
|
||||
self.vars.version = out.strip()
|
||||
|
||||
with runner() as ctx:
|
||||
results = ctx.run(**run_params)
|
||||
self.vars.stdout = ctx.results_out
|
||||
self.vars.stderr = ctx.results_err
|
||||
self.vars.cmd = ctx.cmd
|
||||
if self.verbosity >= 3:
|
||||
self.vars.run_info = ctx.run_info
|
||||
self.vars.set("run_info", ctx.run_info, verbosity=3)
|
||||
|
||||
return results
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ from __future__ import absolute_import, division, print_function
|
|||
__metaclass__ = type
|
||||
|
||||
DOCUMENTATION = """
|
||||
---
|
||||
module: django_check
|
||||
author:
|
||||
- Alexei Znamensky (@russoz)
|
||||
|
@ -58,6 +59,7 @@ attributes:
|
|||
"""
|
||||
|
||||
EXAMPLES = """
|
||||
---
|
||||
- name: Check the entire project
|
||||
community.general.django_check:
|
||||
settings: myproject.settings
|
||||
|
@ -73,10 +75,17 @@ EXAMPLES = """
|
|||
"""
|
||||
|
||||
RETURN = """
|
||||
---
|
||||
run_info:
|
||||
description: Command-line execution information.
|
||||
type: dict
|
||||
returned: success and C(verbosity) >= 3
|
||||
version:
|
||||
description: Version of Django.
|
||||
type: str
|
||||
returned: always
|
||||
sample: 5.1.2
|
||||
version_added: 10.0.0
|
||||
"""
|
||||
|
||||
from ansible_collections.community.general.plugins.module_utils.django import DjangoModuleHelper
|
||||
|
|
|
@ -8,6 +8,7 @@ from __future__ import absolute_import, division, print_function
|
|||
__metaclass__ = type
|
||||
|
||||
DOCUMENTATION = """
|
||||
---
|
||||
module: django_command
|
||||
author:
|
||||
- Alexei Znamensky (@russoz)
|
||||
|
@ -37,6 +38,7 @@ options:
|
|||
"""
|
||||
|
||||
EXAMPLES = """
|
||||
---
|
||||
- name: Check the project
|
||||
community.general.django_command:
|
||||
command: check
|
||||
|
@ -51,10 +53,17 @@ EXAMPLES = """
|
|||
"""
|
||||
|
||||
RETURN = """
|
||||
---
|
||||
run_info:
|
||||
description: Command-line execution information.
|
||||
type: dict
|
||||
returned: success and O(verbosity) >= 3
|
||||
version:
|
||||
description: Version of Django.
|
||||
type: str
|
||||
returned: always
|
||||
sample: 5.1.2
|
||||
version_added: 10.0.0
|
||||
"""
|
||||
|
||||
import shlex
|
||||
|
|
|
@ -8,6 +8,7 @@ from __future__ import absolute_import, division, print_function
|
|||
__metaclass__ = type
|
||||
|
||||
DOCUMENTATION = """
|
||||
---
|
||||
module: django_createcachetable
|
||||
author:
|
||||
- Alexei Znamensky (@russoz)
|
||||
|
@ -27,6 +28,7 @@ attributes:
|
|||
"""
|
||||
|
||||
EXAMPLES = """
|
||||
---
|
||||
- name: Create cache table in the default database
|
||||
community.general.django_createcachetable:
|
||||
settings: myproject.settings
|
||||
|
@ -40,10 +42,17 @@ EXAMPLES = """
|
|||
"""
|
||||
|
||||
RETURN = """
|
||||
---
|
||||
run_info:
|
||||
description: Command-line execution information.
|
||||
type: dict
|
||||
returned: success and O(verbosity) >= 3
|
||||
version:
|
||||
description: Version of Django.
|
||||
type: str
|
||||
returned: always
|
||||
sample: 5.1.2
|
||||
version_added: 10.0.0
|
||||
"""
|
||||
|
||||
from ansible_collections.community.general.plugins.module_utils.django import DjangoModuleHelper
|
||||
|
|
|
@ -7,11 +7,18 @@
|
|||
- id: success
|
||||
input:
|
||||
settings: whatever.settings
|
||||
output:
|
||||
version: "5.1.2"
|
||||
mocks:
|
||||
run_command:
|
||||
- command: [/testbin/python, -m, django, check, --no-color, --settings=whatever.settings]
|
||||
- command: [/testbin/python, -m, django, --version]
|
||||
environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true}
|
||||
rc: 0
|
||||
out: "5.1.2\n"
|
||||
err: ""
|
||||
- command: [/testbin/python, -m, django, check, --no-color, --settings=whatever.settings]
|
||||
environ: *env-def
|
||||
rc: 0
|
||||
out: "whatever\n"
|
||||
err: ""
|
||||
- id: multiple_databases
|
||||
|
@ -20,8 +27,15 @@
|
|||
database:
|
||||
- abc
|
||||
- def
|
||||
output:
|
||||
version: "5.1.2"
|
||||
mocks:
|
||||
run_command:
|
||||
- command: [/testbin/python, -m, django, --version]
|
||||
environ: *env-def
|
||||
rc: 0
|
||||
out: "5.1.2\n"
|
||||
err: ""
|
||||
- command: [/testbin/python, -m, django, check, --no-color, --settings=whatever.settings, --database, abc, --database, def]
|
||||
environ: *env-def
|
||||
rc: 0
|
||||
|
|
|
@ -15,9 +15,14 @@
|
|||
settings: whatever.settings
|
||||
mocks:
|
||||
run_command:
|
||||
- command: [/testbin/python, -m, django, check, --no-color, --settings=whatever.settings, babaloo, yaba, daba, doo]
|
||||
- command: [/testbin/python, -m, django, --version]
|
||||
environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true}
|
||||
rc: 0
|
||||
out: "5.1.2\n"
|
||||
err: ""
|
||||
- command: [/testbin/python, -m, django, check, --no-color, --settings=whatever.settings, babaloo, yaba, daba, doo]
|
||||
environ: *env-def
|
||||
rc: 0
|
||||
out: "whatever\n"
|
||||
err: ""
|
||||
- id: command_fail
|
||||
|
@ -33,6 +38,11 @@
|
|||
failed: true
|
||||
mocks:
|
||||
run_command:
|
||||
- command: [/testbin/python, -m, django, --version]
|
||||
environ: *env-def
|
||||
rc: 0
|
||||
out: "5.1.2\n"
|
||||
err: ""
|
||||
- command: [/testbin/python, -m, django, check, --no-color, --settings=whatever.settings, babaloo, yaba, daba, doo]
|
||||
environ: *env-def
|
||||
rc: 1
|
||||
|
|
|
@ -9,8 +9,13 @@
|
|||
settings: whatever.settings
|
||||
mocks:
|
||||
run_command:
|
||||
- command: [/testbin/python, -m, django, --version]
|
||||
environ: &env-def {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true}
|
||||
rc: 0
|
||||
out: "5.1.2\n"
|
||||
err: ""
|
||||
- command: [/testbin/python, -m, django, createcachetable, --no-color, --settings=whatever.settings, --noinput, --database=default]
|
||||
environ: {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: true}
|
||||
environ: *env-def
|
||||
rc: 0
|
||||
out: "whatever\n"
|
||||
err: ""
|
||||
|
|
Loading…
Reference in New Issue