509318396
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
3
•vh<8  ã               @   sÂ   d dl mZmZmZ d dlZd dlZd dlZd dlZd dlm	Z	 d dl
mZmZ d dlmZ d dlZedƒZedƒZdd	„ Zd
d„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zddd„Zdd„ ZdS )é    )Ú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}c                sÈ   d}xbˆ j D ]X}|jˆ j|ƒrDd}ttdƒjt|ƒtˆ jƒd�ƒ qttdƒjt|ƒtˆ jƒd�ƒ qW |dkrtdS tdƒjtˆ jƒd�}d	jˆ j ƒ}d
jˆ jd�| }t|‡ fdd„||ˆ jd� dS )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
    FTzAdded "{value}" to {prop_name}.)ÚvalueÚ	prop_namez=Not adding value "{value}" to {prop_name}; it already exists.Nz{attr} updated.)ÚattrÚ zsyspurpose add-{name} )Únamec                s   t ‡‡ fdd„ˆjD ƒƒS )Nc             3   s    | ]}|ˆj ˆ jg ƒkV  qd S )N)Úgetr
   )Ú.0Úx)ÚargsÚres© ú/usr/lib/python3.6/cli.pyú	<genexpr>=   s    z0add_command.<locals>.<lambda>.<locals>.<genexpr>)ÚallÚvalues)r   )r   )r   r   Ú<lambda>=   s    zadd_command.<locals>.<lambda>)ÚexpectationÚsuccess_msgÚcommandr   )	r   Úaddr
   ÚprintÚ_Úformatr   ÚjoinÚcheck_result)r   ÚsyspurposestoreZany_prop_addedr	   r   Zto_addr   r   )r   r   Úadd_command"   s&    	


r#   c                s¸   xbˆ j D ]X}|jˆ j|ƒr<ttdƒjt|ƒtˆ jƒd�ƒ qttdƒjt|ƒtˆ jƒd�ƒ dS qW tdƒjtˆ jƒd�}djˆ j ƒ}djˆ jd	�| }t|‡ fd
d„||ˆ jd� dS )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
    zRemoved "{val}" from {name}.)Úvalr   z9Not removing value "{val}" from {name}; it was not there.Nz{attr} updated.)r   r   zsyspurpose remove-{name} )r   c                s   t ‡ fdd„ˆjD ƒƒS )Nc             3   s   | ]}|ˆ j d g ƒkV  qdS )ÚaddonsN)r   )r   r   )r   r   r   r   Z   s    z3remove_command.<locals>.<lambda>.<locals>.<genexpr>)r   r   )r   )r   )r   r   r   Z   s    z remove_command.<locals>.<lambda>)r   r   r   r   )	r   Úremover
   r   r   r   r   r    r!   )r   r"   r	   r   Z	to_remover   r   )r   r   Úremove_commandD   s    	"

r'   c                s\   |j ˆ jˆ jƒ tdƒjtˆ jƒtˆ jƒd�}t|‡ fdd„|djˆ jˆ jd�ˆ jd� dS )	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}".)r   r$   c                s   | j ˆ jƒˆ jkS )N)r   r
   r	   )r   )r   r   r   r   o   s    zset_command.<locals>.<lambda>zsyspurpose set {name} "{val}")r   r$   )r   r   r   r   N)Úsetr
   r	   r   r   r   r!   )r   r"   r   r   )r   r   Úset_commanda   s    	
r)   c                sL   |j ˆ jƒ tdƒjtˆ jƒd�}t|‡ fdd„|djˆ jd�ˆ jd� dS )	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.)r   c                s   | j ˆ jƒdd g gkS )Nr   )r   r
   )r   )r   r   r   r   „   s    zunset_command.<locals>.<lambda>zsyspurpose unset {name})r   )r   r   r   r   N)Úunsetr
   r   r   r   r!   )r   r"   r   r   )r   r   Úunset_commandw   s    
r+   c                s:   |j ƒ }|j‰ ‡ fdd„ˆ D ƒ‰ ttjˆ dddd�ƒ |S )z?
    :param args:
    :param syspurposestore:
    :return:
    c                s   i | ]}ˆ | rˆ | |“qS r   r   )r   Úkey)Úcontentsr   r   ú
<dictcomp>“   s    z!show_contents.<locals>.<dictcomp>é   FT)ÚindentZensure_asciiZ	sort_keys)ÚsyncÚresultr   ÚjsonÚdumps)r   r"   Zsync_resultr   )r-   r   Úshow_contents‹   s
    r5   c              C   s,  t jdtdƒtdƒd�} | jdd�}t jdd�}|jd	td
ƒdd� |jtdd� t jdd�}|jd	tdƒdd� |jtdd� t jdd�}|jdtdƒdd� |jtdd� t jdd�}|jt	dd� |j
dtdƒd�}|jddtdƒdd� |jdtdƒdd� |jtdd� |j
dtdƒ|gd�}|jddtdƒdd� |j
dtdƒd�}|jddtdƒdd� |jd	td
ƒddd � |jtdd� |j
d!td"ƒd�}	|	jddtdƒdd� |	jd	tdƒddd � |	jtdd� |j
d#td$ƒ|gd�}
|
jd%d&� |j
d'td(ƒ|gd�}|jd%d&� |j
d)td*ƒ|gd�}|jd+d&� |j
d,td-ƒ|gd�}|jd+d&� |j
d.td/ƒ|gd�}|jd+d&� |j
d0td1ƒ|gd�}|jd2d&� |j
d3td4ƒ|gd�}|jd2d&� |j
d5td6ƒ|gd�}|jd7d&� |j
d8td9ƒ|gd�}|jd7d&� |j
d:td;ƒd�}|jtdd� | 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ÚdescriptionZepilogzsub-command help)ÚhelpF)Zadd_helpr   zThe value(s) to addú+)r8   ÚnargsT)ÚfuncZrequires_synczThe value(s) to remover	   zThe value to setZstore)r8   Úactionr(   z%Sets the value for the given propertyr
   Úpropertyz&The name of the property to set/update)Úmetavarr8   r<   r*   z0Unsets (clears) the value for the given property)r8   Úparentsr   z'Adds the value(s) to the given propertyz"The name of the property to update)r8   r<   r:   r&   z,Removes the value(s) from the given propertyzset-rolez,Set the system role to the system syspurposeZrole)r
   z
unset-rolezClear set rolez
add-addonsz#Add addons to the system syspurposer%   zremove-addonsz(Remove addons from the system syspurposezunset-addonszClear set addonszset-slazSet the system slaZservice_level_agreementz	unset-slazClear set slaz	set-usagezSet the system usageZusagezunset-usagezClear set usageZshowz"Show the current system syspurpose)ÚargparseÚArgumentParserr   Zadd_subparsersÚadd_argumentZset_defaultsr#   r'   r)   r+   Z
add_parserr5   )ÚparserZ
subparsersZadd_optionsZremove_optionsZset_optionsZunset_optionsZgeneric_set_parserZgeneric_unset_parserZgeneric_add_parserZgeneric_remove_parserZset_role_parserZunset_role_parserZadd_addons_parserZremove_addons_parserZset_sla_parserZunset_sla_parserZset_usage_parserZunset_usage_parserZshow_parserr   r   r   Úsetup_arg_parser˜   sä    









rD   c              C   sÊ   t ƒ } | jƒ }tƒ r ttdƒƒ ttdƒtjd� y2ddlm} ddl	m
} |ƒ }|j}|ƒ jƒ }W n( tk
rŒ   d}d}ttdƒƒ Y nX t||d	d
�}t|ddƒdk	rº|j||ƒ n| jƒ  dS dS )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_uuidZuse_valid_fieldsr;   )rD   Ú
parse_argsr   r   r   ÚsysÚstderrZsubscription_manager.identityrF   Z subscription_manager.cp_providerrG   ÚuuidZget_consumer_auth_cpÚImportErrorr   Úgetattrr;   Z
print_help)rC   r   rF   rG   ZidentityrL   rH   r"   r   r   r   ÚmainS  s,    
rO   c             C   sÈ   |rŒt |ƒt g ƒt f ƒgkr"|f}xh|D ]`}t|tƒr>d| }t|tjƒrptjrptjj|j	dƒƒ tjjdƒ q(tjj|ƒ tjjdƒ q(W ytj
jƒ  tjjƒ  W n tk
r¸   Y nX tj| ƒ dS )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_typeZPY2rJ   rK   ÚwriteÚencodeÚstdoutÚflushÚIOErrorÚexit)ÚcodeÚmsgsÚmsgr   r   r   Úsystem_exity  s"    


r_   c             C   sh   | r| j ƒ  | jƒ }ni }|r\||ƒ r\tj|d�}|| }ttjttj|||d�ƒd� nt	|ƒ d S )N)r   )r   Zdownload_valueÚadvice)r]   )
r1   Zget_cached_contentsÚ	SP_ADVICEr   r_   ÚosÚEX_SOFTWAREr   ÚSP_CONFLICT_MESSAGEr   )r"   r   r   r   r   r2   r`   r	   r   r   r   r!   —  s    
r!   )N)Z
__future__r   r   r   r@   rb   rJ   rU   Zsyspurpose.filesr   Zsyspurpose.utilsr   r   Zsyspurpose.i18nr   r   r3   rd   ra   r#   r'   r)   r+   r5   rD   rO   r_   r!   r   r   r   r   Ú<module>   s(   " <&
