AlkantarClanX12

Your IP : 3.15.145.50


Current Path : /lib/python3.6/site-packages/syspurpose/__pycache__/
Upload File :
Current File : //lib/python3.6/site-packages/syspurpose/__pycache__/cli.cpython-36.pyc

3

i�f<8�@s�ddlmZmZmZddlZddlZddlZddlZddlm	Z	ddl
mZmZddl
mZddlZed�Zed�Zdd	�Zd
d�Zdd
�Zdd�Zdd�Zdd�Zdd�Zddd�Zdd�ZdS)�)�print_function�division�absolute_importN)�SyncedStore)�in_container�	make_utf8)�ugettextzzWarning: A {attr} of "{download_value}" was recently set for this system by the entitlement server administrator.
{advice}zGIf you'd like to overwrite the server side change please run: {command}cs�d}xb�jD]X}|j�j|�rDd}ttd�jt|�t�j�d��qttd�jt|�t�j�d��qW|dkrtdStd�jt�j�d�}d	j�j�}d
j�jd�|}t|�fdd
�||�jd�dS)a�
    Uses the syspurposestore to add one or more values to a particular property.
    :param args: The parsed args from argparse, expected attributes are:
        prop_name: the string name of the property to add to
        values: A list of the values to add to the given property (could be anything json-serializable)
    :param syspurposestore: An SyspurposeStore object to manipulate
    :return: None
    FTzAdded "{value}" to {prop_name}.)�value�	prop_namez=Not adding value "{value}" to {prop_name}; it already exists.Nz{attr} updated.)�attr�zsyspurpose add-{name} )�namecst��fdd��jD��S)Nc3s |]}|�j�jg�kVqdS)N)�getr
)�.0�x)�args�res��/usr/lib/python3.6/cli.py�	<genexpr>=sz0add_command.<locals>.<lambda>.<locals>.<genexpr>)�all�values)r)r)rr�<lambda>=szadd_command.<locals>.<lambda>)�expectation�success_msg�commandr)	r�addr
�print�_�formatr�join�check_result)r�syspurposestoreZany_prop_addedr	rZto_addrr)rr�add_command"s&	


r#cs�xb�jD]X}|j�j|�r<ttd�jt|�t�j�d��qttd�jt|�t�j�d��dSqWtd�jt�j�d�}dj�j�}dj�jd	�|}t|�fd
d�||�jd�dS)
a�
    Uses the syspurposestore to remove one or more values from a particular property.
    :param args: The parsed args from argparse, expected attributes are:
        prop_name: the string name of the property to add to
        values: A list of the values to remove from the given property (could be anything json-serializable)
    :param syspurposestore: An SyspurposeStore object to manipulate
    :return: None
    zRemoved "{val}" from {name}.)�valr
z9Not removing value "{val}" from {name}; it was not there.Nz{attr} updated.)rrzsyspurpose remove-{name} )r
cst�fdd��jD��S)Nc3s|]}|�jdg�kVqdS)�addonsN)r)rr)rrrrZsz3remove_command.<locals>.<lambda>.<locals>.<genexpr>)rr)r)r)rrrZsz remove_command.<locals>.<lambda>)rrrr)	r�remover
rrrrr r!)rr"r	rZ	to_removerr)rr�remove_commandDs	"

r'cs\|j�j�j�td�jt�j�t�j�d�}t|�fdd�|dj�j�jd��jd�dS)	ap
    Uses the syspurposestore to set the prop_name to value.
    :param args: The parsed args from argparse, expected attributes are:
        prop_name: the string name of the property to set
        value: An object to set the property to (could be anything json-serializable)
    :param syspurposestore: An SyspurposeStore object to manipulate
    :return: None
    z{attr} set to "{val}".)rr$cs|j�j��jkS)N)rr
r	)r)rrrroszset_command.<locals>.<lambda>zsyspurpose set {name} "{val}")r
r$)rrrrN)�setr
r	rrrr!)rr"rr)rr�set_commandas	
r)csL|j�j�td�jt�j�d�}t|�fdd�|dj�jd��jd�dS)	a.
    Uses the syspurposestore to unset (clear entirely) the prop_name.
    :param args: The parsed args from argparse, expected attributes are:
        prop_name: the string name of the property to unset (clear)
    :param syspurposestore: An SyspurposeStore object to manipulate
    :return: None
    z
{attr} unset.)rcs|j�j�ddggkS)Nr)rr
)r)rrrr�szunset_command.<locals>.<lambda>zsyspurpose unset {name})r
)rrrrN)�unsetr
rrrr!)rr"rr)rr�
unset_commandws
r+cs:|j�}|j��fdd��D��ttj�dddd��|S)z?
    :param args:
    :param syspurposestore:
    :return:
    csi|]}�|r�||�qSrr)r�key)�contentsrr�
<dictcomp>�sz!show_contents.<locals>.<dictcomp>�FT)�indentZensure_asciiZ	sort_keys)�sync�resultr�json�dumps)rr"Zsync_resultr)r-r�
show_contents�s
r5cCs,tjdtd�td�d�}|jdd�}tjdd�}|jd	td
�dd�|jtd
d�tjdd�}|jd	td�dd�|jtd
d�tjdd�}|jdtd�dd�|jtd
d�tjdd�}|jt	d
d�|j
dtd�d�}|jddtd�dd�|jdtd�dd�|jtd
d�|j
dtd�|gd�}|jddtd�dd�|j
dtd�d�}|jddtd�dd�|jd	td
�ddd �|jtd
d�|j
d!td"�d�}	|	jddtd�dd�|	jd	td�ddd �|	jtd
d�|j
d#td$�|gd�}
|
jd%d&�|j
d'td(�|gd�}|jd%d&�|j
d)td*�|gd�}|jd+d&�|j
d,td-�|gd�}
|
jd+d&�|j
d.td/�|gd�}|jd+d&�|j
d0td1�|gd�}|jd2d&�|j
d3td4�|gd�}|jd2d&�|j
d5td6�|gd�}|jd7d&�|j
d8td9�|gd�}|jd7d&�|j
d:td;�d�}|jtdd�|S)<z~
    Sets up argument parsing for the syspurpose tool.
    :return: An argparse.ArgumentParser ready to use to parse_args
    Z
syspurposez!System Syspurpose Management Toolz�The 'syspurpose' command is deprecated and will be removed in a future major release. Please use the 'subscription-manager syspurpose' command going forward.)�prog�descriptionZepilogzsub-command help)�helpF)Zadd_helprzThe value(s) to add�+)r8�nargsT)�funcZ
requires_synczThe value(s) to remover	zThe value to setZstore)r8�actionr(z%Sets the value for the given propertyr
�propertyz&The name of the property to set/update)�metavarr8r<r*z0Unsets (clears) the value for the given property)r8�parentsrz'Adds the value(s) to the given propertyz"The name of the property to update)r8r<r:r&z,Removes the value(s) from the given propertyzset-rolez,Set the system role to the system syspurposeZrole)r
z
unset-rolezClear set rolez
add-addonsz#Add addons to the system syspurposer%z
remove-addonsz(Remove addons from the system syspurposezunset-addonszClear set addonszset-slazSet the system slaZservice_level_agreementz	unset-slaz
Clear set slaz	set-usagezSet the system usageZusagezunset-usagezClear set usageZshowz"Show the current system syspurpose)�argparse�ArgumentParserrZadd_subparsers�add_argumentZset_defaultsr#r'r)r+Z
add_parserr5)�parserZ
subparsersZadd_optionsZremove_optionsZset_optionsZ
unset_optionsZgeneric_set_parserZgeneric_unset_parserZgeneric_add_parserZgeneric_remove_parserZset_role_parserZunset_role_parserZadd_addons_parserZremove_addons_parserZset_sla_parserZunset_sla_parserZset_usage_parserZunset_usage_parserZshow_parserrrr�setup_arg_parser�s�









rDc
Cs�t�}|j�}t�r ttd��ttd�tjd�y2ddlm}ddl	m
}|�}|j}|�j�}Wn(t
k
r�d}d}ttd��YnXt||d	d
�}t|dd�dk	r�|j||�n|j�dSdS)zE
    Run the cli (Do the syspurpose tool thing!!)
    :return: 0
    z\WARNING: Setting syspurpose in containers has no effect.
Please run syspurpose on the host.
z�The 'syspurpose' command is deprecated and will be removed in a future major release. Please use the 'subscription-manager syspurpose' command going forward.)�filer)�Identity)�
CPProviderNzyWarning: Unable to sync system purpose with subscription management server: subscription_manager module is not available.T)�uepZ
consumer_uuidZuse_valid_fieldsr;)rD�
parse_argsrrr�sys�stderrZsubscription_manager.identityrFZ subscription_manager.cp_providerrG�uuidZget_consumer_auth_cp�ImportErrorr�getattrr;Z
print_help)rCrrFrGZidentityrLrHr"rrr�mainSs,
rOcCs�|r�t|�tg�tf�gkr"|f}xh|D]`}t|t�r>d|}t|tj�rptjrptjj|j	d��tjjd�q(tjj|�tjjd�q(Wytj
j�tjj�Wntk
r�YnXtj
|�dS)z�
    Exit with a code and optional message(s). Saved a few lines of code.
    Note: this method was copied from subscription_manager, because syspurpose should be independent
    on subscription_manager module as much as possible.
    z%s�utf8�
N)�type�
isinstance�	Exception�sixZ	text_typeZPY2rJrK�write�encode�stdout�flush�IOError�exit)�code�msgs�msgrrr�system_exitys"


r_cCsh|r|j�|j�}ni}|r\||�r\tj|d�}||}ttjttj|||d��d�nt	|�dS)N)r)rZdownload_value�advice)r])
r1Zget_cached_contents�	SP_ADVICErr_�os�EX_SOFTWAREr�SP_CONFLICT_MESSAGEr)r"rrrrr2r`r	rrrr!�s
r!)N)Z
__future__rrrr@rbrJrUZsyspurpose.filesrZsyspurpose.utilsrrZsyspurpose.i18nrrr3rdrar#r'r)r+r5rDrOr_r!rrrr�<module>s("
<&