%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python2.7/site-packages/salt/pillar/
Upload File :
Create Path :
Current File : //usr/lib/python2.7/site-packages/salt/pillar/django_orm.pyc

�
���^c@@s�dZddlmZmZmZddlZddlZddlZddlZ	ddl
mZddlZ	e
ZyddlZeZWnek
r�nXeje�Zd�Zddd�ZdS(uk

Generate Pillar data from Django models through the Django ORM

:maintainer: Micah Hausler <micah.hausler@gmail.com>
:maturity: new


Configuring the django_orm ext_pillar
=====================================

To use this module, your Django project must be on the salt master server with
database access. This assumes you are using virtualenv with all the project's
requirements installed.

.. code-block:: yaml

    ext_pillar:
      - django_orm:
          pillar_name: my_application
          project_path: /path/to/project/
          settings_module: my_application.settings
          env_file: /path/to/env/file.sh
          # Optional: If your project is not using the system python,
          # add your virtualenv path below.
          env: /path/to/virtualenv/

          django_app:

            # Required: the app that is included in INSTALLED_APPS
            my_application.clients:

              # Required: the model name
              Client:

                # Required: model field to use as the key in the rendered
                # Pillar. Must be unique; must also be included in the
                # ``fields`` list below.
                name: shortname

                # Optional:
                # See Django's QuerySet documentation for how to use .filter()
                filter:  {'kw': 'args'}

                # Required: a list of field names
                # List items will be used as arguments to the .values() method.
                # See Django's QuerySet documentation for how to use .values()
                fields:
                  - field_1
                  - field_2


This would return pillar data that would look like

.. code-block:: yaml

    my_application:
      my_application.clients:
        Client:
          client_1:
            field_1: data_from_field_1
            field_2: data_from_field_2
          client_2:
            field_1: data_from_field_1
            field_2: data_from_field_2

As another example, data from multiple database tables can be fetched using
Django's regular lookup syntax. Note, using ManyToManyFields will not currently
work since the return from values() changes if a ManyToMany is present.

.. code-block:: yaml

    ext_pillar:
      - django_orm:
          pillar_name: djangotutorial
          project_path: /path/to/mysite
          settings_module: mysite.settings

          django_app:
            mysite.polls:
              Choices:
                name: poll__question
                fields:
                  - poll__question
                  - poll__id
                  - choice_text
                  - votes

Module Documentation
====================
i(tabsolute_importtprint_functiontunicode_literalsN(tsixcC@stS(u
    Always load
    (tTrue(((s:/usr/lib/python2.7/site-packages/salt/pillar/django_orm.pyt__virtual__qsc!	O@s$tjj|�s&tjd|�iStr�|dk	r�tjj|�r�x=tj|�D],}
tjj|
�sZtjd|
�iSqZWt	jj
dtjjtj|�dd��nt	jj|�|tj
d<|dk	rddl}i}|jdd	d
gd|j�}
xB|
jD]7}tjjj|�jd�\}}}|||<q"Wdd	d
j|�g}|j|d|j�}
x�|
jD]~}tjjj|�jd�\}}}||ks�|||kr�|jd�tj
|<tjd||jd��q�q�Wny�ddlm}i}xtj|�D]n\}}|jd�\}}}i||<x=tj|�D],\}}|||�}|dkr�tjj dj||���ni}|||j!<|d}|d}d|kr"|j"j#|d�j$|�}n|j"j$|�}xx|D]p}||krktjj dj|���n|||kr�tjj dj||���n||||<q;Wq�WqEWi||6SWnZt%k
r�} tjd| �iSt&k
r} tjd| �tjddt'�iSXdS(u8
    Connect to a Django database through the ORM and retrieve model fields

    :type pillar_name: str
    :param pillar_name: The name of the pillar to be returned

    :type project_path: str
    :param project_path: The full path to your Django project (the directory
        manage.py is in)

    :type settings_module: str
    :param settings_module: The settings module for your project. This can be
        found in your manage.py file

    :type django_app: str
    :param django_app: A dictionary containing your apps, models, and fields

    :type env: str
    :param env: The full path to the virtualenv for your Django project

    :type env_file: str
    :param env_file: An optional bash file that sets up your environment. The
        file is run in a subprocess and the changed variables are then added
    u)Django project dir: '%s' not a directory!uVirtualenv %s not a directory!iiu
site-packagesuDJANGO_SETTINGS_MODULENubashu-cuenvtstdoutu=usource {0} && envu
u$Adding %s = %s to Django environment(t	get_modelu.u*Django model '{0}' not found in app '{1}'.unameufieldsufilteru(Name '{0}' not found in returned fields.u"Value for '{0}' is not unique: {0}uFailed to import library: %suFailed on Error: %sudjango_orm tracebacktexc_info((tostpathtisdirtlogterrortHAS_VIRTUALENVtNonet
virtualenvtpath_locationstsystinserttjointappendtenviront
subprocesstPopentPIPERtsalttutilststringutilstto_strt	partitiontformattrstriptdebugtdjango.db.models.loadingRRt	iteritemst
rpartitiont
exceptionst
SaltExceptiont__name__tobjectstfiltertvaluestImportErrort	ExceptionR(!t	minion_idtpillartpillar_nametproject_pathtsettings_modulet
django_apptenvtenv_filetargstkwargsR
Rtbase_envtproctlinetkeyt_tvaluetcommandRt
django_pillartproj_apptmodelstappt
model_namet
model_metat	model_ormtpillar_for_modelt
name_fieldtfieldstqstmodelte((s:/usr/lib/python2.7/site-packages/salt/pillar/django_orm.pyt
ext_pillarxs�#$	

!''&
	

	

		(t__doc__t
__future__RRRtloggingR	Rtsalt.exceptionsRtsalt.extRtsalt.utils.stringutilstFalseRRRR+t	getLoggerR'RRRRK(((s:/usr/lib/python2.7/site-packages/salt/pillar/django_orm.pyt<module>[s"

	


Zerion Mini Shell 1.0