%PDF- %PDF-
Mini Shell

Mini Shell

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

�
���^c@@s�dZddlmZmZmZddlmZddlZddlZddl	Z	ddl
Z
ddlZddlm
Z
ddlmZddlmZddlmZddlZddlZeje�ZyddlZeZWnek
rZeZnXd	Z d
�Z!d�Z"d�Z#d
�Z$d�Z%d�Z&d�Z'ddddedd�Z)edkr}e)�ndS(u*
SaltStack Extend
~~~~~~~~~~~~~~~~

A templating tool for extending SaltStack.

Takes a template directory and merges it into a SaltStack source code
directory. This tool uses Jinja2 for templating.

This tool is accessed using `salt-extend`

    :codeauthor: Anthony Shaw <anthonyshaw@apache.org>
i(tabsolute_importtunicode_literalstprint_function(tdateN(tTemplate(tdeserialize(tzip(tOrderedDictutemplate.ymlcC@sLtjjj|d��.}t|�}||jdd�|f}WdQX|S(u-
    Get the contents of a template file and provide it as a module type

    :param path: path to the template.yml file
    :type  path: ``str``

    :param option_key: The unique key of this template
    :type  option_key: ``str``

    :returns: Details about the template
    :rtype: ``tuple``
    urudescriptionuN(tsalttutilstfilestfopenRtget(tpatht
option_keyt
template_fttemplatetinfo((s5/usr/lib/python2.7/site-packages/salt/utils/extend.pyt
_get_template-s
!cC@s�g}tjd|�x�tj|�D]�}tjj||�}tjj|�r&tjj|t�}tjj|�r�|j	t
||��q�tjd|t�q&q&W|S(u�
    Fetch all of the templates in the src directory

    :param src: The source path
    :type  src: ``str``

    :rtype: ``list`` of ``tuple``
    :returns: ``list`` of ('key', 'description')
    uListing contents of %su Directory does not contain %s %s(tlogtdebugtostlistdirR
tjointisdirtTEMPLATE_FILE_NAMEtisfiletappendR(tsrct	templatestitemtst
template_path((s5/usr/lib/python2.7/site-packages/salt/utils/extend.pyt_fetch_templates@s
cC@s�x�tj|�D]�}tjj||�}tjj||�}tjj|�r�tjd||�tjj|�r�t||�q�t	j
||�qtjd||�t	j||�qWdS(u�
    Akin to shutils.copytree but over existing directories, does a recursive merge copy.

    :param src: The source path
    :type  src: ``str``

    :param dst: The destination path
    :type  dst: ``str``
    uCopying folder %s to %suCopying file %s to %sN(RRR
RRRRtexistst
_mergetreetshutiltcopytreetcopy2(RtdstRRtd((s5/usr/lib/python2.7/site-packages/salt/utils/extend.pyR#Xs
c
	C@swxptj|�D]_}tjj||�}tjj||�}tjj|�r�tjd||�tjj|�r�t|||�qotj	|�t|||�q|t
krt|�j|�}tjd||�t
jjj|d��7}t
jjj|j��}t|�j|�}WdQXt
jjj|d��#}	|	jt
jjj|��WdQXqqWdS(uk
    Merge directory A to directory B, apply Jinja2 templating to both
    the file/folder names AND to the contents of the files

    :param src: The source path
    :type  src: ``str``

    :param dst: The destination path
    :type  dst: ``str``

    :param context: The dictionary to inject into the Jinja template as context
    :type  context: ``dict``
    uCopying folder %s to %suCopying file %s to %surNuw(RRR
RRRRR"t_mergetreejinjatmkdirRRtrenderRR	R
Rtstringutilst
to_unicodetreadtwritetto_str(
RR'tcontextRRR(tsource_filetsrc_contentst
dest_contentst	dest_file((s5/usr/lib/python2.7/site-packages/salt/utils/extend.pyR)ps"
cC@stj|d|�S(u
    Prompt the user to enter the value of a variable

    :param var_name: The question to ask the user
    :type  var_name: ``str``

    :param default_value: The default value
    :type  default_value: ``str``

    :rtype: ``str``
    :returns: the value from the user
    tdefault(tclicktprompt(tvar_namet
default_value((s5/usr/lib/python2.7/site-packages/salt/utils/extend.pyt_prompt_user_variable�s
c	C@s�td�t|d�D��}|j�}d}g|j�D]/}dj|d|dd|dd�^q>}djdj|�dj|�djd	j|��f�}tj|d
tj|�d|�}||S(u�
    Prompt the user to choose between a list of options, index each one by adding an enumerator
    based on https://github.com/audreyr/cookiecutter/blob/master/cookiecutter/prompt.py#L51

    :param var_name: The question to ask the user
    :type  var_name: ``str``

    :param options: A list of options
    :type  options: ``list`` of ``tupple``

    :rtype: ``tuple``
    :returns: The selected user
    cs@s:|]0\}}|ddkrdj|�|fVqdS(iutestu{0}N(tformat(t.0titvalue((s5/usr/lib/python2.7/site-packages/salt/utils/extend.pys	<genexpr>�siu1u{0} - {1} - {2}iu
uSelect {0}:uChoose from {0}u, ttypeR6(	Rt	enumeratetkeystitemsR<RR7R8tChoice(	R9toptionst
choice_maptchoicesR6tctchoice_linesR8tuser_choice((s5/usr/lib/python2.7/site-packages/salt/utils/extend.pyt_prompt_choice�sBcC@st|||�dS(uP
    Apply the template from the template directory to the output
    using the supplied context dict.

    :param src: The source path
    :type  src: ``str``

    :param dst: The destination path
    :type  dst: ``str``

    :param context: The dictionary to inject into the Jinja template as context
    :type  context: ``dict``
    N(R)(ttemplate_dirt
output_dirR1((s5/usr/lib/python2.7/site-packages/salt/utils/extend.pytapply_template�scC@s�ts td�tjd�n|dkr5d}nttjj|d��}|dkr~td�d}t	||�}nc|t
t|��dkr�td�tjd�ng|D]}	|	d|kr�|	^q�d}|d}|d	}
|dkrtd
�tdd�}n|dkr;td
d�}ndj
|�}|}itjjj�jd6|d6|d6tj�jd�d6tj�jd�d6}
i}xd|
jdi�j�D]J\}}t|jdd��j|
�}t|d|�}|||<q�W|
j�}|j|
�|j|�|dkrTtj�}nt|||�|ss|}nt||�|}t j!d|�|S(u�
    A template factory for extending the salt ecosystem

    :param extension: The extension type, e.g. 'module', 'state', if omitted, user will be prompted
    :type  extension: ``str``

    :param name: Python-friendly name for the module, if omitted, user will be prompted
    :type  name: ``str``

    :param description: A description of the extension, if omitted, user will be prompted
    :type  description: ``str``

    :param salt_dir: The targeted Salt source directory
    :type  salt_dir: ``str``

    :param merge: Merge with salt directory, `False` to keep separate, `True` to merge trees.
    :type  merge: ``bool``

    :param temp_dir: The directory for generated code, if omitted, system temp will be used
    :type  temp_dir: ``str``
    u0click is not installed, please install using pipiu.u	templatesu?Choose which type of extension you are developing for SaltStackuExtension typeiu!Module extension option not validiu3Enter the short name for the module (e.g. mymodule)uModule nameuuShort description of the moduleu
templates/{0}uversionumodule_nameushort_descriptionu%Y-%m-%durelease_dateu%Yuyearu	questionsudefaultuquestionuNew module stored in %sN("t	HAS_CLICKtprinttsystexittNoneR!RR
RRKtlistRR;R<RtversiontSaltStackVersiontnext_releasetnameRttodaytstrftimeRRCRR+tcopytupdatettempfiletmkdtempRNR#RR(t	extensionRXtdescriptiontsalt_dirtmergettemp_dirtMODULE_OPTIONStextension_typetchosen_extensiontmtextension_contextRLtmodule_namet
param_dicttadditional_contexttkeytvalR6t
prompt_varR1R
((s5/usr/lib/python2.7/site-packages/salt/utils/extend.pytrun�sb
	

-


%!

	
u__main__(*t__doc__t
__future__RRRtdatetimeRtloggingR]RRQR$tjinja2Rtsalt.serializers.yamlRtsalt.ext.six.movesRtsalt.utils.odictRtsalt.utils.filesRtsalt.versiont	getLoggert__name__RR7tTrueROtImportErrortietFalseRRR!R#R)R;RKRNRSRo(((s5/usr/lib/python2.7/site-packages/salt/utils/extend.pyt<module>s<

				#		!	^

Zerion Mini Shell 1.0