U
    M[^6$                     @   sd  d dl Z d dlZzd dlmZmZ W n ek
r8   Y nX G dd dZe jG dd de jZ	e jG dd de jZ
e jG d	d
 d
e jZe jG dd de jZe jG dd de jZdZdZdZejjejejj ej ejjejejj ej ejjejejj ej ejjejejj ej e
jjeje
jj ej e
jjeje
jj ej eeje ej eeje ej eeje ej i	ZdZdZdZdZ dZ!e!d Z"e!d Z#dZ$dZ%dZ&dZ'dZ(dZ)dZ*d Z+d!Z,d"Z-d#Z.d$Z/d%Z0d&Z1d'Z2d(Z3d)Z4d*Z5d+Z6d,Z7d-Z8d.Z9d/Z:d0Z;d1Z<d2Z=d3Z>d4Z?d5Z@d6ZAd7ZBd8ZCd9ZDd:ZEd;ZFeGeGd<d=d>ZHd?eGd@dAdBZIdS )C    N)AnyDictc                   @   s   e Zd ZdZdZdZdZdS )TxtColorz[92mz[37mz[91mz[0mN)__name__
__module____qualname__OKGREENDISABLEGREYFAILENDC r   r   1/usr/lib/python3/dist-packages/uaclient/status.pyr      s   r   c                   @   s   e Zd ZdZe Ze ZdS )ApplicationStatuszO
    An enum to represent the current application status of an entitlement
    N)r   r   r   __doc__objectZENABLEDZDISABLEDr   r   r   r   r      s   r   c                   @   s   e Zd ZdZdZdZdS )ContractStatusz
    An enum to represent whether a user is entitled to an entitlement

    (The value of each member is the string that will be used in status
    output.)
    yesnoN)r   r   r   r   ENTITLED
UNENTITLEDr   r   r   r   r      s   r   c                   @   s   e Zd ZdZe Ze ZdS )ApplicabilityStatuszQ
    An enum to represent whether an entitlement could apply to this machine
    N)r   r   r   r   r   Z
APPLICABLEINAPPLICABLEr   r   r   r   r   )   s   r   c                   @   s   e Zd ZdZdZdZdS )UserFacingAvailabilitya  
    An enum representing whether a service could be available for a machine.

    'Availability' means whether a service is available to machines with this
    architecture, series and kernel. Whether a contract is entitled to use
    the specific service is determined by the contract level.

    This enum should only be used in display code, it should not be used in
    business logic.
    r   r   N)r   r   r   r   	AVAILABLEUNAVAILABLEr   r   r   r   r   3   s   r   c                   @   s    e Zd ZdZdZdZdZdZdS )UserFacingStatusz
    An enum representing the states we will display in status output.

    This enum should only be used in display code, it should not be used in
    business logic.
    ZenabledZdisabledzn/au   —N)r   r   r   r   ACTIVEINACTIVEr   r   r   r   r   r   r   D   s
   r   Z	essentialZstandardZadvancedzAPT install failed.zAPT update failed.zFailure checking APT policy.zUpdating package listszWFailed to connect to authentication server
Check your Internet connection and try againz	. {error}z&. Failed to access URL: {url}. {error}z1This command must be run as root (try using sudo)z4{title} is not currently enabled
See: sudo ua statuszCould not enable {title}.z{title} enabledznThis machine is already attached to '{account_name}'
To use a different subscription first run: sudo ua detachz/{title} is already enabled.
See: sudo ua statuszY{title} is not available for platform {arch}.
Supported platforms are: {supported_arches}z-{title} is not available for Ubuntu {series}.zX{title} is not available for kernel {kernel}.
Supported flavors are: {supported_kernels}z[{title} is not available for kernel {kernel}.
Minimum kernel version required: {min_kernel}zdThis subscription is not entitled to {title}.
For more information see: https://ubuntu.com/advantagezgUnable to determine auto-attach platform support
For more information see: https://ubuntu.com/advantagez\Auto-attach image support is not available on {cloud_type}
See: https://ubuntu.com/advantagezZAuto-attach image support is not available on this image
See: https://ubuntu.com/advantagezSThis machine is not attached to a UA subscription.
See https://ubuntu.com/advantagezKUbuntu Advantage server provided no aptURL directive for {entitlement_name}z({name: <14}{available: <11}{description}z-SERVICE       ENTITLED  STATUS    DESCRIPTIONz4{name: <14}{entitled: <19}{status: <19}{description}z/Invalid token. See https://ubuntu.com/advantagezlAttach requires a token: sudo ua attach <TOKEN>
To obtain a token please visit: https://ubuntu.com/advantagez:Failed to attach machine. See https://ubuntu.com/advantagez8Failed to enable default services, check: sudo ua statusz2This machine is now attached to '{contract_name}'
zUSubscription has expired
To obtain a token please visit: https://ubuntu.com/advantagezFCannot {operation} '{name}'
For a list of services see: sudo ua statuszUnexpected error(s) occurred.
For more details, see the log: /var/log/ubuntu-advantage.log
To file a bug run: ubuntu-bug ubuntu-advantage-toolszTo use '{name}' you need an Ubuntu Advantage subscription
Personal and community subscriptions are available at no charge
See https://ubuntu.com/advantagezEnabling default service {name}zDService {name} is recommended by default. Run: sudo ua enable {name}zThis machine is now detachedz&Unable to automatically detach machinez,One moment, checking your subscription firstz(Successfully refreshed your subscriptionz#Unable to refresh your subscription)stringreturnc                 C   s   t j rt| | S | S )z=Return colorized string if using a tty, else original string.)sysstdoutisattySTATUS_COLORget)r   r   r   r   colorize   s    r%   zDict[str, Any])statusr   c                    sT  | d sRt jddddg}| d D ]}|t jf | q"|dtg d|S tg}| d D ]T}|d	 }|d
 }|r||n|d }|d t|t|d |d}|tjf | q`|d | d }d| d fd| d fg}	| d dkr|	dt	| d f |	dt|f t
dd |	D }
d|
 | fdd|	D  d|S )z&Format status dict for tabular output.ZattachedZSERVICEr   ZDESCRIPTION)nameZ	availabledescriptionZservices 
entitledZdescription_overrider(   r'   r&   )r'   r+   r&   r(   z+
Enable services with: ua enable <service>
ZtechSupportLevelZAccountZaccountZSubscriptionZsubscriptionoriginZfreezValid untilZexpireszTechnical support levelc                 S   s   g | ]}t |d  qS )r   )len.0Zpairr   r   r   
<listcomp>  s     z"format_tabular.<locals>.<listcomp>z{{:>{}}}: {{}}c                    s   g | ]} j | qS r   )formatr.   templater   r   r0     s     )STATUS_UNATTACHED_TMPLr1   appendextendMESSAGE_UNATTACHEDjoinSTATUS_HEADERr%   STATUS_TMPLstrmax)r&   ZcontentZserviceZservice_statusr+   Zdescr_overrider(   Zfmt_argsZtech_support_levelZpairsZtemplate_lengthr   r2   r   format_tabular   sF    





r=   )Jenumr    typingr   r   ImportErrorr   uniqueEnumr   r   r   r   r   Z	ESSENTIALZSTANDARDZADVANCEDr   valuer   r   r   r
   r   r	   r   r   r   r#   ZMESSAGE_APT_INSTALL_FAILEDZMESSAGE_APT_UPDATE_FAILEDZMESSAGE_APT_POLICY_FAILEDZMESSAGE_APT_UPDATING_LISTSZMESSAGE_CONNECTIVITY_ERRORZLOG_CONNECTIVITY_ERROR_TMPLZ$LOG_CONNECTIVITY_ERROR_WITH_URL_TMPLZMESSAGE_NONROOT_USERZMESSAGE_ALREADY_DISABLED_TMPLZMESSAGE_ENABLED_FAILED_TMPLZMESSAGE_ENABLED_TMPLZMESSAGE_ALREADY_ATTACHEDZMESSAGE_ALREADY_ENABLED_TMPLZMESSAGE_INAPPLICABLE_ARCH_TMPLZ MESSAGE_INAPPLICABLE_SERIES_TMPLZ MESSAGE_INAPPLICABLE_KERNEL_TMPLZ$MESSAGE_INAPPLICABLE_KERNEL_VER_TMPLZMESSAGE_UNENTITLED_TMPLZ&MESSAGE_UNABLE_TO_DETERMINE_CLOUD_TYPEZ*MESSAGE_UNSUPPORTED_AUTO_ATTACH_CLOUD_TYPEZMESSAGE_UNSUPPORTED_AUTO_ATTACHr7   Z!MESSAGE_MISSING_APT_URL_DIRECTIVEr4   r9   r:   ZMESSAGE_ATTACH_INVALID_TOKENZMESSAGE_ATTACH_REQUIRES_TOKENZMESSAGE_ATTACH_FAILUREZ'MESSAGE_ATTACH_FAILURE_DEFAULT_SERVICESZMESSAGE_ATTACH_SUCCESS_TMPLZMESSAGE_CONTRACT_EXPIRED_ERRORZ'MESSAGE_INVALID_SERVICE_OP_FAILURE_TMPLZMESSAGE_UNEXPECTED_ERRORZ&MESSAGE_ENABLE_FAILURE_UNATTACHED_TMPLZMESSAGE_ENABLE_BY_DEFAULT_TMPLZ%MESSAGE_ENABLE_BY_DEFAULT_MANUAL_TMPLZMESSAGE_DETACH_SUCCESSZ!MESSAGE_DETACH_AUTOMATION_FAILUREZMESSAGE_REFRESH_ENABLEZMESSAGE_REFRESH_SUCCESSZMESSAGE_REFRESH_FAILUREr;   r%   r=   r   r   r   r   <module>   s   		   