%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python2.7/site-packages/salt/modules/
Upload File :
Create Path :
Current File : //lib/python2.7/site-packages/salt/modules/ini_manage.pyo

�
���^c@@sudZddlmZmZmZddlZddlZddlZddl	Zddl
ZddlZddlm
Z
ddlmZddlmZddlZeje�ZdZd�Zejd	d
ej�Zejd�Zejd�Zdd
d�Zd
d�Zd
d�Z d
d�Z!d
d�Z"d
d�Z#defd��YZ$de$fd��YZ%dS(u�
Edit ini files

:maintainer: <akilesh1597@gmail.com>
:maturity: new
:depends: re
:platform: all

(for example /etc/sysctl.conf)
i(tabsolute_importtprint_functiontunicode_literalsN(tCommandExecutionError(tOrderedDict(tsixuinicC@stS(u
    Rename to ini
    (t__virtualname__(((s;/usr/lib/python2.7/site-packages/salt/modules/ini_manage.pyt__virtual__"su^\s*\[(.+?)\]\s*$tflagsu^\s*(#|;)\s*(.*)u	(\s+)(.*)u=cC@sD|p	i}i}tj|d|�}|j|�}|j�|S(u�
    Edit an ini file, replacing one or more sections. Returns a dictionary
    containing the changes made.

    file_name
        path of ini_file

    sections : None
        A dictionary representing the sections to be edited ini file
        The keys are the section names and the values are the dictionary
        containing the options
        If the ini file does not contain sections the keys and values represent
        the options

    separator : =
        A character used to separate keys and values. Standard ini files use
        the "=" character.

        .. versionadded:: 2016.11.0

    API Example:

    .. code-block:: python

        import salt
        sc = salt.client.get_local_client()
        sc.cmd('target', 'ini.set_option',
               ['path_to_ini_file', '{"section_to_change": {"key": "value"}}'])

    CLI Example:

    .. code-block:: bash

        salt '*' ini.set_option /path/to/ini '{section_foo: {key: value}}'
    t	separator(t_Initget_ini_filetupdatetflush(t	file_nametsectionsR	tchangestinifile((s;/usr/lib/python2.7/site-packages/salt/modules/ini_manage.pyt
set_option.s$
cC@sgtj|d|�}|rSy |j|i�j|d�SWqctk
rOdSXn|j|d�SdS(u�
    Get value of a key from a section in an ini file. Returns ``None`` if
    no matching key was found.

    API Example:

    .. code-block:: python

        import salt
        sc = salt.client.get_local_client()
        sc.cmd('target', 'ini.get_option',
               [path_to_ini_file, section_name, option])

    CLI Example:

    .. code-block:: bash

        salt '*' ini.get_option /path/to/ini section_name option_name
    R	N(R
RtgettNonetAttributeError(RtsectiontoptionR	R((s;/usr/lib/python2.7/site-packages/salt/modules/ini_manage.pyt
get_optionZs 
cC@sttj|d|�}t|j|�ttf�rT|j|i�j|d�}n|j|d�}|j�|S(u�
    Remove a key/value pair from a section in an ini file. Returns the value of
    the removed key, or ``None`` if nothing was removed.

    API Example:

    .. code-block:: python

        import salt
        sc = salt.client.get_local_client()
        sc.cmd('target', 'ini.remove_option',
               [path_to_ini_file, section_name, option])

    CLI Example:

    .. code-block:: bash

        salt '*' ini.remove_option /path/to/ini section_name option_name
    R	N(	R
Rt
isinstanceRtdictRtpopRR
(RRRR	Rtvalue((s;/usr/lib/python2.7/site-packages/salt/modules/ini_manage.pyt
remove_optionxs!
cC@srtj|d|�}i}xPtj|j|i��D]3\}}|ddkr7|ji||6�q7q7W|S(u�
    Retrieve a section from an ini file. Returns the section as dictionary. If
    the section is not found, an empty dictionary is returned.

    API Example:

    .. code-block:: python

        import salt
        sc = salt.client.get_local_client()
        sc.cmd('target', 'ini.get_section',
               [path_to_ini_file, section_name])

    CLI Example:

    .. code-block:: bash

        salt '*' ini.get_section /path/to/ini section_name
    R	iu#(R
RRt	iteritemsRR(RRR	RtrettkeyR((s;/usr/lib/python2.7/site-packages/salt/modules/ini_manage.pytget_section�s(cC@s�tj|d|�}||kr�|j|�}|j�i}xDtj|�D]3\}}|ddkrP|ji||6�qPqPW|SdS(u�
    Remove a section in an ini file. Returns the removed section as dictionary,
    or ``None`` if nothing was removed.

    API Example:

    .. code-block:: python

        import salt
        sc = salt.client.get_local_client()
        sc.cmd('target', 'ini.remove_section',
               [path_to_ini_file, section_name])

    CLI Example:

    .. code-block:: bash

        salt '*' ini.remove_section /path/to/ini section_name
    R	iu#N(R
RRR
RRR(RRR	RRR R((s;/usr/lib/python2.7/site-packages/salt/modules/ini_manage.pytremove_section�s
c@s.�fd��tj|d|�}�|�S(ua
    Retrieve whole structure from an ini file and return it as dictionary.

    API Example:

    .. code-block:: python

        import salt
        sc = salt.client.get_local_client()
        sc.cmd('target', 'ini.get_ini',
               [path_to_ini_file])

    CLI Example:

    .. code-block:: bash

        salt '*' ini.get_ini /path/to/ini
    c@s�i}xvtj|�D]e\}}|ddkrt|ttf�rd|ji�|�|6�q{|ji||6�qqW|S(u�
        Transform OrderedDict to regular dict recursively
        :param odict: OrderedDict
        :return: regular dict
        iu#(RRRRRR(todictRR tval(tini_odict2dict(s;/usr/lib/python2.7/site-packages/salt/modules/ini_manage.pyR%�sR	(R
R(RR	R((R%s;/usr/lib/python2.7/site-packages/salt/modules/ini_manage.pytget_ini�st_SectioncB@s�eZdddd�Zdd�Zd�Zd�Zd�Zd�Zd	�Z	d
�Z
dd�Zd�Zd
�Z
d�ZRS(uu=u#cC@sztt|�j|�||_||_||_||_d}d}dj||j|�|_t	j
|j�|_dS(Nu
(\s*)(.+?)\s*u
\s*(.*)\s*u{0}(\{1}){2}(tsuperR't__init__tnametinicontentstseptcomtformattopt_regx_strtretcompiletopt_regx(tselfR*R+R	t	commentertopt_regx_prefixtopt_regx_suffix((s;/usr/lib/python2.7/site-packages/salt/modules/ini_manage.pyR)�s				cC@s�d}d}d}|p|j}|jtj�}|s=dSx|D]}|j|�qDWx�|jtj�D]�}tj|�}|r�dj|�}|j	d�|_
|d7}|ji||6�qnntj|�}	|	rg|	j	d�j
dd�}
|
|krgt|�}|rn|d}|j|�}
|jitjj|
|f�|6�qnqnqgn|jj|�}|r�|j�\}}|_}
|j
dd�}|ji|
|6�qnndj|�}|ji||6�|d7}qnWdS(Niuu#comment{0}u	u    i����u#unknown{0}(R+tstriptostlinesepRtsplittCOM_REGXtmatchR.tgroupR-Rt
INDENTED_REGXtreplacetlistRtjoinR2tgroupsR,(R3R+t
comment_countt
unknown_counttcurr_indenttopttopt_strt	com_matchR*tindented_matchtindenttoptionstprev_optRt	opt_match((s;/usr/lib/python2.7/site-packages/salt/modules/ini_manage.pytrefreshsH


)	cC@s2t�}d}x�tj|�D]�\}}|dk	rQ|ji||6�qnd|krcqn|jj|jd��}|r|jd�|kr|}qqWx|D]}|j	|�q�W|j	|d�t
t|�jid|6�x:tj|�D])\}}t
t|�ji||6�qWdS(Nu#commentu#i(RRRRRR2R<tlstripR=RR(R'(R3topt_keytoptions_backupt
comment_indexR RRM((s;/usr/lib/python2.7/site-packages/salt/modules/ini_manage.pyt_uncomment_if_commented0s"	

c	
C@s�i}x�tj|�D]�\}}t|ttf�r�td|ddd|jd|j�}|j|�|}|j	�}ntj
|�}|}||kr|jiidd6|d6|6�t|t�s�|j|�nt
t|�ji||6�q|j|d�}t|t�rR|j|�}|r�|ji||6�q�q||kr|jii|d6|d6|6�t
t|�ji||6�qqW|S(NR*R+uR	R4ubeforeuafter(RRRRRR'R,R-Rtas_dictt	text_typeRRSR(R(	R3tupdate_dictRR Rtsecttvalue_plaint
curr_valuetsub_changes((s;/usr/lib/python2.7/site-packages/salt/modules/ini_manage.pyRHs6
 $cc@s
djtj|j�Vt�}x�tj|�D]�\}}tj|�rbdj|tj�Vq0t	|t
�r�|ji||6�q0dj||jdkr�dj|j�n|j|tj�Vq0Wx9tj|�D](\}}x|j
�D]}|Vq�Wq�WdS(Nu{0}[{1}]{0}u{0}{1}u{0}{1}{2}{3}u u {0} (R.R8R9R*RRRR;R<RR'RR,tgen_ini(R3t
sections_dictR*Rtline((s;/usr/lib/python2.7/site-packages/salt/modules/ini_manage.pyR[ns	'cC@sdj|j��S(Nu(RAR[(R3((s;/usr/lib/python2.7/site-packages/salt/modules/ini_manage.pytas_ini�scC@s
t|�S(N(R(R3((s;/usr/lib/python2.7/site-packages/salt/modules/ini_manage.pyRT�scC@sttj|��dS(N(tprintRRU(R3((s;/usr/lib/python2.7/site-packages/salt/modules/ini_manage.pytdump�scC@sO|p	i}tt|�j|�}tjj|tjjj	|dd�f�S(NRJi(
R(R't__repr__R8R9RAtsalttutilstjsontdumps(R3t
_repr_runningt
super_repr((s;/usr/lib/python2.7/site-packages/salt/modules/ini_manage.pyRa�scC@stjjj|dd�S(NRJi(RbRcRdRe(R3((s;/usr/lib/python2.7/site-packages/salt/modules/ini_manage.pyt__str__�scC@s"t||j�o!|j|jkS(N(Rt	__class__R*(R3titem((s;/usr/lib/python2.7/site-packages/salt/modules/ini_manage.pyt__eq__�scC@s#t||j�o!|j|jkS(N(RRiR*(R3Rj((s;/usr/lib/python2.7/site-packages/salt/modules/ini_manage.pyt__ne__�sN(t__name__t
__module__R)RRNRSRR[R^RTR`RaRhRkRl(((s;/usr/lib/python2.7/site-packages/salt/modules/ini_manage.pyR'�s+		&						R
cB@s>eZdd�Zd�Zedd��Zed��ZRS(cC@sW|dkr�y@tjjj|j��"}tjjj|j��}WdQXWq�t	t
fk
r�}tdtkr�t
dj|j|���q�q�Xn|s�dS|j�tj|�}|j�tt|�j|j��xn|j|�D]]\}}y=t||d|j�}|j�|ji||j6�Wq�tk
rNq�Xq�WdS(Nutestu)Unable to open file '{0}'. Exception: {1}R	(RRbRctfilestfopenR*tstringutilst
to_unicodetreadtOSErrortIOErrort__opts__tFalseRR.tcleartINI_REGXR:treverseR(R
RNRt_gen_tuplesR'R,Rt
StopIteration(R3R+trfhtexctsection_nametsect_initsect_obj((s;/usr/lib/python2.7/site-packages/salt/modules/ini_manage.pyRN�s.%



cC@s�y`tjjj|jd��?}|j�}t|�|jtjjj	t
|���WdQXWn4ttfk
r�}t
dj|j|���nXdS(Nuwbu*Unable to write file '{0}'. Exception: {1}(RbRcRoRpR*R[tnextt
writelinestdatatencodeR@RtRuRR.(R3toutfiletini_genR~((s;/usr/lib/python2.7/site-packages/salt/modules/ini_manage.pyR
�s
,u=cC@s t|d|�}|j�|S(NR	(R
RN(RR	R((s;/usr/lib/python2.7/site-packages/salt/modules/ini_manage.pyR�s
cc@sMxFtrHy|j�}|j�}Wntk
r9dSX||fVqWdS(N(tTrueRt
IndexError(tlist_objectR R((s;/usr/lib/python2.7/site-packages/salt/modules/ini_manage.pyR{�s	
N(RmRnRRNR
tstaticmethodRR{(((s;/usr/lib/python2.7/site-packages/salt/modules/ini_manage.pyR
�s
	(&t__doc__t
__future__RRRR8R0tsalt.utils.dataRbtsalt.utils.filestsalt.utils.jsontsalt.utils.stringutilstsalt.exceptionsRtsalt.utils.odictRtsalt.extRtloggingt	getLoggerRmtlogRRR1tMRyR;R>RRRRR!R"R&R'R
(((s;/usr/lib/python2.7/site-packages/salt/modules/ini_manage.pyt<module>s2	,&�

Zerion Mini Shell 1.0