%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python2.7/site-packages/salt/states/
Upload File :
Create Path :
Current File : //lib/python2.7/site-packages/salt/states/mysql_query.pyc

�
���^c@@s�dZddlmZmZmZddlZddlZddlZ	ddl
Z	ddlmZd�Z
d�Zddddeded�Zdddeed�ZdS(	u�
Execution of MySQL queries
==========================

.. versionadded:: 2014.7.0

:depends:   - MySQLdb Python module
:configuration: See :py:mod:`salt.modules.mysql` for setup instructions.

The mysql_query module is used to execute queries on MySQL databases.
Its output may be stored in a file or in a grain.

.. code-block:: yaml

    query_id:
      mysql_query.run
        - database: my_database
        - query:    "SELECT * FROM table;"
        - output:   "/tmp/query_id.txt"
i(tabsolute_importtprint_functiontunicode_literalsN(tsixcC@s
dtkS(u@
    Only load if the mysql module is available in __salt__
    umysql.query(t__salt__(((s;/usr/lib/python2.7/site-packages/salt/states/mysql_query.pyt__virtual__$scC@s!tjtdjjjdd�S(up
    Look in module context for a MySQL error. Eventually we should make a less
    ugly way of doing this.
    u	test.pingumysql.errorN(tsystmodulesRt
__module__t__context__tpoptNone(((s;/usr/lib/python2.7/site-packages/salt/states/mysql_query.pyt_get_mysql_error+sc	K@s6i|d6id6td6dj|�d6}
tgdddd	d
gD]}|j|�^qD�r�td|d|pxt�}ntjj|�s�d
j|�|
d<t	|
d<|
S|rtd||	�rt
�}|d'k	r�||
d<t	|
d<|
Sd'|
d<dj|�|
d<|
S|dkrZ|d'k	r�|d'kr�|rp|td�krpd|d|
d<|
StdrWd'|
d<dd||
d<|
Sq�|d'k	r;|td�kr�td|�}
ni}
|r||
krd|d|d|
d<|
StdrWd'|
d<dd|d||
d<|
Sq�t	|
d<dd|
d<|
Sn�|d'k	r�|r�tjj
|�r�d|d|
d<|
Stdr�d'|
d<dd||
d<|
Sn"tdr�d'|
d<d|
d<|
Std|||	�}|t	krt	|
d<|
Sg}d|kr�xT|dD]H}i}x,t|d �D]\}}||||<qNW|j|�q1W||d<ntj|�|
d<|dkrZ|d'k	r�|d'kr�td!||�d"||
dd#<q2|d'k	r2|td�krtd|�}
ni}
||
|<td!||
�d"|d||
dd#<q2n�|d'k	r$d$||
dd#<tjjj|d%���}d|kr�xy|dD]N}xEtj|�D]4\}}|jtjjj|d|d&��q�Wq�Wn|jtjjj|��Wd'QXnd(|
dd#<|
S()u�
    Execute an arbitrary query on the specified database

    .. versionadded:: 2017.7.0

    name
        Used only as an ID

    database
        The name of the database to execute the query_file on

    query_file
        The file of mysql commands to run

    output
        grain: output in a grain
        other: the file to store results
        None:  output to the result comment (default)

    grain:
        grain to store the output (need output=grain)

    key:
        the specified grain will be treated as a dictionary, the result
        of this state will be stored under the specified key.

    overwrite:
        The file or grain will be overwritten if it already exists (default)

    saltenv:
        The saltenv to pull the query_file from

    check_db_exists:
        The state run will check that the specified database exists (default=True)
        before running any queries

    unameuchangesuresultuDatabase {0} is already presentucommentuhttp://uhttps://usalt://us3://uswift://u
cp.cache_filetsaltenvuFile {0} does not existumysql.db_existsuDatabase {0} is not presentugrainu	grains.lsuNo execution needed. Grain u already setutestu'Query would execute, storing result in ugrain: u
grains.getu:u+Error: output type 'grain' needs the grain u
parameter
uNo execution needed. File ufile: u'Query would execute, not storing resultumysql.file_queryuresultsucolumnsu
grains.setvaluExecuted. Output into grain: uqueryuExecuted. Output into uwu
NuExecuted(tTruetformattanyt
startswithRt__env__tostpathtexiststFalseRRt__opts__tisfilet	enumeratetappendRt	text_typetsalttutilstfilestfopent	iteritemstwritetstringutilstto_str(tnametdatabaset
query_filetoutputtgraintkeyt	overwriteR
tcheck_db_existstconnection_argstrettprototerrtgrain_valuetquery_resulttmapped_resultstrestmapped_linetidxtcoltoutput_filetval((s;/usr/lib/python2.7/site-packages/salt/states/mysql_query.pytrun_file5s�/
7
	
















 !c
K@s�i|d6id6td6dj|�d6}	|r�td||�r�t�}
|
d k	rr|
|	d<t|	d<|	Sd |	d<dj|�|	d<|	S|dkr�|d k	r|d kr|r�|td	�kr�d
|d|	d<|	Stdr�d |	d<d
d||	d<|	Sq[|d k	r�|td	�krFtd|�}ni}|r}||kr}d
|d|d|	d<|	Stdr�d |	d<d
d|d||	d<|	Sq[t|	d<dd|	d<|	Sn�|d k	r9|rtjj	|�rd|d|	d<|	Stdr[d |	d<d
d||	d<|	Sn"tdr[d |	d<d|	d<|	Std|||�}g}
d|kr�xT|dD]H}i}x,t
|d�D]\}}||||<q�W|
j|�q�W|
|d<ntj
|�|	d<|dkr�|d k	rD|d krDtd||�d||	dd<q�|d k	r�|td	�krvtd|�}ni}|||<td||�d|d||	dd<q�n5|d k	r�d||	dd<tjjj|d���}d|kr\x�|dD]N}xEtj|�D]4\}}|jtjjj|d|d��qWqWnyt|tj
�r�|jtjjj|��nHxEtj|�D]4\}}|jtjjjdj||���q�WWd QXnd!|	dd<|	S("u
    Execute an arbitrary query on the specified database

    name
        Used only as an ID

    database
        The name of the database to execute the query on

    query
        The query to execute

    output
        grain: output in a grain
        other: the file to store results
        None:  output to the result comment (default)

    grain:
        grain to store the output (need output=grain)

    key:
        the specified grain will be treated as a dictionary, the result
        of this state will be stored under the specified key.

    overwrite:
        The file or grain will be overwritten if it already exists (default)

    check_db_exists:
        The state run will check that the specified database exists (default=True)
        before running any queries
    unameuchangesuresultuDatabase {0} is already presentucommentumysql.db_existsuDatabase {0} is not presentugrainu	grains.lsuNo execution needed. Grain u already setutestu'Query would execute, storing result in ugrain: u
grains.getu:u+Error: output type 'grain' needs the grain u
parameter
uNo execution needed. File ufile: u'Query would execute, not storing resultumysql.queryuresultsucolumnsu
grains.setvaluExecuted. Output into grain: uqueryuExecuted. Output into uwu
u{0}:{1}
NuExecuted(RRRRRRRRRRRRRRRRRRR R!R"R#t
isinstance(R$R%tqueryR'R(R)R*R+R,R-R/R0R1R2R3R4R5R6R7R8((s;/usr/lib/python2.7/site-packages/salt/states/mysql_query.pytrun�s�(
	















 !#(t__doc__t
__future__RRRRtos.pathRtsalt.utils.filesRtsalt.utils.stringutilstsalt.extRRRRRR9R<(((s;/usr/lib/python2.7/site-packages/salt/states/mysql_query.pyt<module>s(		�

Zerion Mini Shell 1.0