
    Vh5                         d dl mZmZmZ eZdZdZd dlZd dl	Z	d dl
Z
d dlmZ d Zd Zd Zd	 Zd
 Zd Zd Zd Zedk(  r e        yy)    )absolute_importdivisionprint_functiona	  
module: django_manage
short_description: Manages a Django application
description:
  - Manages a Django application using the C(manage.py) application frontend to C(django-admin). With the O(virtualenv) parameter,
    all management commands will be executed by the given C(virtualenv) installation.
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: none
  diff_mode:
    support: none
options:
  command:
    description:
      - The name of the Django management command to run. The commands listed below are built in this module and have some
        basic parameter validation.
      - V(collectstatic) - Collects the static files into C(STATIC_ROOT).
      - V(createcachetable) - Creates the cache tables for use with the database cache backend.
      - V(flush) - Removes all data from the database.
      - V(loaddata) - Searches for and loads the contents of the named O(fixtures) into the database.
      - V(migrate) - Synchronizes the database state with models and migrations.
      - V(test) - Runs tests for all installed apps.
      - Other commands can be entered, but will fail if they are unknown to Django. Other commands that may prompt for user
        input should be run with the C(--noinput) flag.
      - Support for the values V(cleanup), V(syncdb), V(validate) was removed in community.general 9.0.0. See note about supported
        versions of Django.
    type: str
    required: true
  project_path:
    description:
      - The path to the root of the Django application where C(manage.py) lives.
    type: path
    required: true
    aliases: [app_path, chdir]
  settings:
    description:
      - The Python path to the application's settings module, such as V(myapp.settings).
    type: path
    required: false
  pythonpath:
    description:
      - A directory to add to the Python path. Typically used to include the settings module if it is located external to
        the application directory.
      - This would be equivalent to adding O(pythonpath)'s value to the E(PYTHONPATH) environment variable.
    type: path
    required: false
    aliases: [python_path]
  virtualenv:
    description:
      - An optional path to a C(virtualenv) installation to use while running the manage application.
      - The virtual environment must exist, otherwise the module will fail.
    type: path
    aliases: [virtual_env]
  apps:
    description:
      - A list of space-delimited apps to target. Used by the V(test) command.
    type: str
    required: false
  cache_table:
    description:
      - The name of the table used for database-backed caching. Used by the V(createcachetable) command.
    type: str
    required: false
  clear:
    description:
      - Clear the existing files before trying to copy or link the original file.
      - Used only with the V(collectstatic) command. The C(--noinput) argument will be added automatically.
    required: false
    default: false
    type: bool
  database:
    description:
      - The database to target. Used by the V(createcachetable), V(flush), V(loaddata), V(syncdb), and V(migrate) commands.
    type: str
    required: false
  failfast:
    description:
      - Fail the command immediately if a test fails. Used by the V(test) command.
    required: false
    default: false
    type: bool
    aliases: [fail_fast]
  fixtures:
    description:
      - A space-delimited list of fixture file names to load in the database. B(Required) by the V(loaddata) command.
    type: str
    required: false
  skip:
    description:
      - Will skip over out-of-order missing migrations, you can only use this parameter with V(migrate) command.
    required: false
    type: bool
  merge:
    description:
      - Will run out-of-order or missing migrations as they are not rollback migrations, you can only use this parameter with
        V(migrate) command.
    required: false
    type: bool
  link:
    description:
      - Will create links to the files instead of copying them, you can only use this parameter with V(collectstatic) command.
    required: false
    type: bool
  testrunner:
    description:
      - Controls the test runner class that is used to execute tests.
      - This parameter is passed as-is to C(manage.py).
    type: str
    required: false
    aliases: [test_runner]
  ack_venv_creation_deprecation:
    description:
      - This option no longer has any effect since community.general 9.0.0.
      - It will be removed from community.general 11.0.0.
    type: bool
    version_added: 5.8.0

notes:
  - 'B(ATTENTION): Support for Django releases older than 4.1 has been removed in community.general version 9.0.0. While the
    module allows for free-form commands, not verifying the version of Django being used, it is B(strongly recommended) to
    use a more recent version of the framework.'
  - Please notice that Django 4.1 requires Python 3.8 or greater.
  - This module will not create a virtualenv if the O(virtualenv) parameter is specified and a virtual environment does not
    already exist at the given location. This behavior changed in community.general version 9.0.0.
  - The recommended way to create a virtual environment in Ansible is by using M(ansible.builtin.pip).
  - This module assumes English error messages for the V(createcachetable) command to detect table existence, unfortunately.
  - To be able to use the V(collectstatic) command, you must have enabled C(staticfiles) in your settings.
  - Your C(manage.py) application must be executable (C(rwxr-xr-x)), and must have a valid shebang, for example C(#!/usr/bin/env
    python), for invoking the appropriate Python interpreter.
seealso:
  - name: django-admin and manage.py Reference
    description: Reference for C(django-admin) or C(manage.py) commands.
    link: https://docs.djangoproject.com/en/4.1/ref/django-admin/
  - name: Django Download page
    description: The page showing how to get Django and the timeline of supported releases.
    link: https://www.djangoproject.com/download/
  - name: What Python version can I use with Django?
    description: From the Django FAQ, the response to Python requirements for the framework.
    link: https://docs.djangoproject.com/en/dev/faq/install/#what-python-version-can-i-use-with-django
requirements: ["django >= 4.1"]
author:
  - Alexei Znamensky (@russoz)
  - Scott Anderson (@tastychutney)
a  
- name: Run cleanup on the application installed in django_dir
  community.general.django_manage:
    command: clearsessions
    project_path: "{{ django_dir }}"

- name: Load the initial_data fixture into the application
  community.general.django_manage:
    command: loaddata
    project_path: "{{ django_dir }}"
    fixtures: "{{ initial_data }}"

- name: Run syncdb on the application
  community.general.django_manage:
    command: migrate
    project_path: "{{ django_dir }}"
    settings: "{{ settings_app_name }}"
    pythonpath: "{{ settings_dir }}"
    virtualenv: "{{ virtualenv_dir }}"

- name: Run the SmokeTest test case from the main app. Useful for testing deploys
  community.general.django_manage:
    command: test
    project_path: "{{ django_dir }}"
    apps: main.SmokeTest

- name: Create an initial superuser
  community.general.django_manage:
    command: "createsuperuser --noinput --username=admin --email=admin@example.com"
    project_path: "{{ django_dir }}"
N)AnsibleModulec                 Z    d}|r|d|z  }|r|d|z  } | j                   d||d| y )N zstdout: z

:stderr: )cmdmsg )	fail_json)moduler	   outerrkwargsr
   s         s/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/django_manage.py_failr      sA    
C
s%%
#((F0#00    c                    | j                   d   }|y t        j                  j                  |d      }t        j                  j                  |d      }t        j                  j	                  |      s| j                  d|z         |dt        j                  d   t        j                  d<   |t        j                  d<   y )	N
virtualenvbinactivatez0%s does not point to a valid virtual environmentr
   :PATHVIRTUAL_ENV)paramsospathjoinexistsr   environ)r   
venv_paramvbinr   s       r   _ensure_virtualenvr$      s    |,J77<<
E*Dww||D*-H77>>(#OR\\]$("**V*<=BJJv *BJJ}r   c                 
    d| vS )Nalready existsr   )outputs    r   createcachetable_check_changedr(      s    6))r   c                     d| v xr d| vS N	InstalledInstalled 0 objectr   lines    r   flush_filter_outputr/          $C#7t#CCr   c                     d| v xr d| vS r*   r   r-   s    r   loaddata_filter_outputr2      r0   r   c                 .    d| v xs d| v xr d| vxs d| v S )NzMigrating forwards r+   r,   Applyingr   r-   s    r   migrate_filter_outputr5      s4    !T)  4D$8$D $ r   c                     | xr d| vS )Nz0 static filesr   r-   s    r   collectstatic_filter_outputr7      s    0$D00r   c                     t        dddddd      } t        d	      }d
}d}d}d}d}t        t        d7i dt        dd      dt        ddddg      dt        d      dt        ddg      dt        ddg      dt               d t        d      d!t        d"d#$      d%t        d      d&t        d"d#d'g(      d)t        d      d*t        dd+g      d,t        d#      d-t        d#      d.t        d#      d/t        d#d0d12      3      }t        j                  |j                  d         }|d4   }	|j                  d   }
|j                  d   }|D ]3  }|j                  |   }|s|| |	   vs|j                  |d5|	6       5 |j                  |	d7      D ])  }|j                  |   r|j                  |d8|	6       + t        |       d9g|z   }|	|v rd:|vr|j                  d:       |D ]6  }|j                  |   s|j                  d;|d<|j                  |          8 |D ]&  }|j                  |   s|j                  d=|z         ( |D ]f  }|j                  |   s|d>v r2|j                  t        j                  |j                  |                I|j                  |j                  |          h |j                  ||
?      \  }}}|d4k7  rU|	d@k(  rdA|v rdB|v rdC}nEdD|v rt        |||dE|	z         t        ||||t        j                  dF   t        j                  G       d"}|j                  dH      }t!               j                  |	dIz   d       }|r"t#        t%        ||            }t'        |      rd}t!               j                  dJj)                  |	      d       }|r ||      }|j+                  ||||
|
||j                  d   |j                  d   K       y )LN)cache_tabledatabase)r:   )r:   fixtures)failfast
testrunnerapps)r>   skipmerger:   )clearlink)createcachetableflushloaddatatestmigratecollectstatic)r;   )rE   )rD   rG   rF   rH   )r>   rA   r:   r<   r;   r=   )settings
pythonpathr:   )rA   r<   r?   r@   rB   )r>   r9   r;   commandTstr)requiredtypeproject_pathr   app_pathchdir)rM   rN   aliasesrI   )rN   rJ   python_path)rN   rR   r   virtual_envr>   r9   rA   Fbool)defaultrN   r:   r<   	fail_fast)rV   rN   rR   r;   r=   test_runnerr?   r@   rB   ack_venv_creation_deprecationz11.0.0zcommunity.general)rN   removed_in_versionremoved_from_collection)argument_specr   z$ param is incompatible with command=r   r   z param is required for command=z./manage.pyz	--noinputz--=z--%s)r;   r>   )cwdrC   tabler&   zalready exists.zUnknown command:zUnknown django command: %sr   )r   syspath
_filter_outputz{0}_check_changed)changedr   r	   rP   rO   r   rI   rJ   )dictr   shlexsplitr   r   getr$   appendextendrun_commandr   r   r!   sysr   globalslistfilterlenformat	exit_json)command_allowed_param_mapcommand_required_param_mapnoinput_commandsspecific_paramsgeneral_paramsspecific_boolean_paramsend_of_command_paramsr   command_splitcommand_binrO   r   paramvaluerun_cmd_argsrcr   r   rc   linesfiltfiltered_outputcheck_changeds                          r   mainr      sk    $6+16)! "&"
 ZO =NL? 
$U3
t&:wBWX
 v&
 -A	

 -A
 
 %(
 u62
 u%
 %f{mL
 u%
 @
 6"
 F#
  6"!
" +/Fx  rE  +F#
F, KKi 89M"K==0L|,J  de$U";K"HHuVa!bcd
 ,//R@ _}}U#%Q\!]^_ v!?]2L&&;m+KK( K==UFMM%4H IJK ) 0==/0
 ' :==,,##EKKe0D$EF##FMM%$89: %%l%ELBS	Qw,,CDTX[D[#C!S(flC1MP[1[\&,Srzz&7ISVS[S[\GIIdOE9=='77>DvdE23GIMM"5"<"<["I4PM$
W#<,eq *V]]:5N[a[h[hiu[v  xr   __main__)
__future__r   r   r   rN   __metaclass__DOCUMENTATIONEXAMPLESr   rk   re   ansible.module_utils.basicr   r   r$   r(   r/   r2   r5   r7   r   __name__r   r   r   <module>r      ss    A @Qf@ 
 
  41+ *DD 1oxd zF r   