Debian Codegraph @

ansible_collections/community/general/plugins/modules/django_command.py

raw
1 #!/usr/bin/python
2 # Copyright (c) 2024, Alexei Znamensky <[email protected]>
3 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
4 # SPDX-License-Identifier: GPL-3.0-or-later
5
6 from __future__ import annotations
7
8 DOCUMENTATION = r"""
9 module: django_command
10 author:
11 - Alexei Znamensky (@russoz)
12 short_description: Run Django admin commands
13 version_added: 9.0.0
14 description:
15 - This module allows the execution of arbitrary Django admin commands.
16 extends_documentation_fragment:
17 - community.general._attributes
18 - community.general._django
19 attributes:
20 check_mode:
21 support: none
22 diff_mode:
23 support: none
24 options:
25 command:
26 description:
27 - Django admin command. It must be a valid command accepted by C(python -m django) at the target system.
28 type: str
29 required: true
30 extra_args:
31 type: list
32 elements: str
33 description:
34 - List of extra arguments passed to the django admin command.
35 """
36
37 EXAMPLES = r"""
38 - name: Check the project
39 community.general.django_command:
40 command: check
41 settings: myproject.settings
42
43 - name: Check the project in specified python path, using virtual environment
44 community.general.django_command:
45 command: check
46 settings: fancysite.settings
47 pythonpath: /home/joedoe/project/fancysite
48 venv: /home/joedoe/project/fancysite/venv
49 """
50
51 RETURN = r"""
52 run_info:
53 description: Command-line execution information.
54 type: dict
55 returned: success and O(verbosity) >= 3
56 version:
57 description: Version of Django.
58 type: str
59 returned: always
60 sample: 5.1.2
61 version_added: 10.0.0
62 """
63
64 import shlex
65
66 from ansible_collections.community.general.plugins.module_utils._cmd_runner import cmd_runner_fmt
67 from ansible_collections.community.general.plugins.module_utils._django import DjangoModuleHelper
68
69
70 class DjangoCommand(DjangoModuleHelper):
71 module = dict(
72 argument_spec=dict(
73 command=dict(type="str", required=True),
74 extra_args=dict(type="list", elements="str"),
75 ),
76 supports_check_mode=False,
77 )
78 arg_formats = dict(
79 extra_args=cmd_runner_fmt.as_list(),
80 )
81 django_admin_arg_order = "extra_args"
82
83 def __init_module__(self):
84 self.vars.command = shlex.split(self.vars.command)
85
86
87 def main():
88 DjangoCommand.execute()
89
90
91 if __name__ == "__main__":
92 main()