Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # Copyright (c) 2025, 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_loaddata
10 author:
11 - Alexei Znamensky (@russoz)
12 short_description: Wrapper for C(django-admin loaddata)
13 version_added: 11.3.0
14 description:
15 - This module is a wrapper for the execution of C(django-admin loaddata).
16 extends_documentation_fragment:
17 - community.general._attributes
18 - community.general._django
19 - community.general._django.database
20 - community.general._django.data
21 attributes:
22 check_mode:
23 support: none
24 diff_mode:
25 support: none
26 options:
27 app:
28 description: Specifies a single app to look for fixtures in rather than looking in all apps.
29 type: str
30 ignore_non_existent:
31 description: Ignores fields and models that may have been removed since the fixture was originally generated.
32 type: bool
33 fixtures:
34 description:
35 - List of paths to the fixture files.
36 type: list
37 elements: path
38 """
39
40 EXAMPLES = r"""
41 - name: Dump all data
42 community.general.django_dumpdata:
43 settings: myproject.settings
44
45 - name: Create cache table in the other database
46 community.general.django_createcachetable:
47 database: myotherdb
48 settings: fancysite.settings
49 pythonpath: /home/joedoe/project/fancysite
50 venv: /home/joedoe/project/fancysite/venv
51 """
52
53 RETURN = r"""
54 run_info:
55 description: Command-line execution information.
56 type: dict
57 returned: success and O(verbosity) >= 3
58 version:
59 description: Version of Django.
60 type: str
61 returned: always
62 sample: 5.1.2
63 """
64
65 from ansible_collections.community.general.plugins.module_utils._django import DjangoModuleHelper
66
67
68 class DjangoLoadData(DjangoModuleHelper):
69 module = dict(
70 argument_spec=dict(
71 app=dict(type="str"),
72 ignore_non_existent=dict(type="bool"),
73 fixtures=dict(type="list", elements="path"),
74 ),
75 supports_check_mode=False,
76 )
77 django_admin_cmd = "loaddata"
78 django_admin_arg_order = "database_dash ignore_non_existent app format excludes fixtures"
79 _django_args = ["data", "database_dash"]
80
81 def __init_module__(self):
82 self.vars.set("database_dash", self.vars.database, output=False)
83
84
85 def main():
86 DjangoLoadData.execute()
87
88
89 if __name__ == "__main__":
90 main()