
    Jh                         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e	      Z G d	 d
e	      Z G d de	e      ZdefdZdedefdZ edded      Zdddeg dddZy)    )List)APIEndpoint)AdditionalInfo)UAConfig)
DataObjectFieldIntDataValueStringDataValue	data_list)create_updates_listfilter_updates get_installed_packages_by_originget_ua_infoc            
           e Zd Z eded       eded       eded       eded	       ed
ed      gZdedededed
ef
dZy)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                 J    || _         || _        || _        || _        || _        y Nr   r   r   r   r   )selfr   r   r   r   r   s         H/usr/lib/python3/dist-packages/uaclient/api/u/pro/packages/updates/v1.py__init__zUpdateSummary.__init__0   s,     '$8!%:"-J*$8!    N)__name__
__module____qualname__r   r	   fieldsintr    r   r   r   r      s    <-O	
 	">	

 	#?	

 	+J	

 	"I	
'F499 "9  #	9
 (+9 "9r   r   c                       e Zd Z eded       eded       eded       eded	       ed
ed       eded      gZdedededed
edefdZ	y)
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                 X    || _         || _        || _        || _        || _        || _        y r   r(   r)   r*   r+   r,   r-   )r   r(   r)   r*   r+   r,   r-   s          r   r   zUpdateInfo.__init__[   s0     +&r   N)
r    r!   r"   r   r	   r
   r#   r$   strr   r%   r   r   r'   r'   ?   s    7	

 	5	

 	,O	
 	3	

 	B	

 	i.EF1F6  	
   r   r'   c                   Z    e Zd Z eded       ed ee      d      gZdedee   fdZ	y)PackageUpdatesResultsummaryz Summary of all available updatesr   updatesz&Detailed list of all available updatesc                      || _         || _        y r   r3   r4   )r   r3   r4   s      r   r   zPackageUpdatesResult.__init__x   s    r   N)
r    r!   r"   r   r   r   r'   r#   r   r   r%   r   r   r2   r2   l   sI    }*L	
 	j!8	
		F Z8H r   r2   returnc                  (    t        t                     S r   )_updatesr   r%   r   r   r4   r4   }   s    HJr   cfgc                    t        |       }t               }t        |d         }t        ||      }t	        |d         }t	        |d         }t	        |d         }t	        |d         }t        ||z   |z   |z   ||||      }	|D 
cg c]%  }
t        |
d   |
d   |
d	   |
d
   |
d   |
d         ' }}
t        |	|      S c c}
w )zx
    This endpoint shows available updates for packages in a system, categorised
    by where they can be obtained.
    allzesm-appsz	esm-infrazstandard-securityzstandard-updatesr   r(   r)   r*   service_namer,   r-   r/   r6   )r   r   r   r   lenr   r'   r2   )r:   ua_infopackagesupgradable_versionsupdate_listr   r   r   r   r3   updater4   s               r   r9   r9      s   
 #G/1H(%9%&97CK2:>? 3K @A$'/0%! 23EFG(
 
'(  23&C1	G& "
  	 1(#9%~.(#9%	

G 
  AA
s   *B>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'   r2   r4   r9   endpoint_docr%   r   r   <module>rX      s     ( 2 $  '9J '9T* *Z:~ " %  'B( 'B3 'BT 		 
 )6 r   