o
    ÙKÕiè  ã                   @   sÞ   d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	m
Z
mZmZmZ d dlmZmZmZmZ G dd„ de	ƒZG d	d
„ d
e	ƒZG dd„ de	eƒZdefdd„Zdedefdd„Zeddedd�Zdddeg dddœZdS )é    )ÚList)ÚAPIEndpoint)ÚAdditionalInfo)ÚUAConfig)Ú
DataObjectÚFieldÚIntDataValueÚStringDataValueÚ	data_list)Úcreate_updates_listÚfilter_updatesÚ get_installed_packages_by_originÚget_ua_infoc                
   @   sj   e Zd Zededd�ededd�ededd�eded	d�ed
edd�gZdedededed
ef
dd„ZdS )ÚUpdateSummaryÚnum_updatesz Total count of available updates©ÚdocÚnum_esm_apps_updatesz,Count of available updates from ``esm-apps``Únum_esm_infra_updatesz-Count of available updates from ``esm-infra``Únum_standard_security_updatesz8Count of available updates from the ``-security`` pocketÚnum_standard_updatesz7Count of available updates from the ``-updates`` pocketc                 C   s"   || _ || _|| _|| _|| _d S ©N©r   r   r   r   r   )Úselfr   r   r   r   r   © r   úH/usr/lib/python3/dist-packages/uaclient/api/u/pro/packages/updates/v1.pyÚ__init__0   s
   
zUpdateSummary.__init__N)Ú__name__Ú
__module__Ú__qualname__r   r   ÚfieldsÚintr   r   r   r   r   r      sH    ÿýýýýíþýüûúr   c                   @   sz   e Zd Zededd�ededd�ededd�eded	d�ed
edd�ededd�gZdedededed
edefdd„Z	dS )Ú
UpdateInfoÚdownload_sizez%Download size for the update in bytesr   Úoriginz#Where the update is downloaded fromÚpackagez!Name of the package to be updatedÚprovided_byz!Service which provides the updateÚstatusz0Whether this update is ready for download or notÚversionzVersion of the updatec                 C   s(   || _ || _|| _|| _|| _|| _d S r   ©r#   r$   r%   r&   r'   r(   )r   r#   r$   r%   r&   r'   r(   r   r   r   r   [   s   	
zUpdateInfo.__init__N)
r   r   r   r   r   r	   r    r!   Ústrr   r   r   r   r   r"   ?   sN    ýýÿýýèþýüûúùr"   c                   @   sB   e Zd Zededd�edeeƒdd�gZdedee fdd„Z	dS )	ÚPackageUpdatesResultÚsummaryz Summary of all available updatesr   Úupdatesz&Detailed list of all available updatesc                 C   s   || _ || _d S r   ©r,   r-   )r   r,   r-   r   r   r   r   x   s   
zPackageUpdatesResult.__init__N)
r   r   r   r   r   r
   r"   r    r   r   r   r   r   r   r+   l   s    ÿýür+   Úreturnc                   C   s
   t tƒ ƒS r   )Ú_updatesr   r   r   r   r   r-   }   s   
r-   Úcfgc                 C   sŒ   t | ƒ}tƒ }t|d ƒ}t||ƒ}t|d ƒ}t|d ƒ}t|d ƒ}t|d ƒ}t|| | | ||||d�}	dd„ |D ƒ}
t|	|
d	�S )
zx
    This endpoint shows available updates for packages in a system, categorized
    by where they can be obtained.
    Úallzesm-appsz	esm-infrazstandard-securityzstandard-updatesr   c              
   S   s8   g | ]}t |d  |d |d |d |d |d d�‘qS )r#   r$   r%   Úservice_namer'   r(   r)   )r"   )Ú.0Úupdater   r   r   Ú
<listcomp>œ   s    	øúÿz_updates.<locals>.<listcomp>r.   )r   r   r   r   Úlenr   r+   )r1   Úua_infoÚpackagesÚupgradable_versionsÚupdate_listr   r   r   r   r,   r-   r   r   r   r0   �   s6   
ÿÿþýø
	÷r0   Úv1ÚPackageUpdatesN)r(   ÚnameÚfnÚoptions_clsz27.12FzP
from uaclient.api.u.pro.packages.updates.v1 import updates

result = updates()
z!pro api u.pro.packages.updates.v1aé  
{
    "summary": {
        "num_updates": 1,
        "num_esm_apps_updates": 2,
        "num_esm_infra_updates": 3,
        "num_standard_security_updates": 4,
        "num_standard_updates": 5,
    },
    "updates": [
        {
            "download_size": 6,
            "origin": "<some site>",
            "package": "<package name>",
            "provided_by": "<service name>",
            "status": "<update status>",
            "version": "<updated version>",
        },
    ]
}
)Úintroduced_inÚrequires_networkÚexample_pythonÚresult_classÚ
exceptionsÚexample_cliÚexample_json)Útypingr   Úuaclient.api.apir   Úuaclient.api.data_typesr   Úuaclient.configr   Úuaclient.data_typesr   r   r   r	   r
   Úuaclient.security_statusr   r   r   r   r   r"   r+   r-   r0   ÚendpointÚ_docr   r   r   r   Ú<module>   s2    *-*ü
õ