3 @qhc@s ddlmZddlmZmZmZmZmZddlZddl m Z ddl m Z ddl m Z ddlmZmZddlmZmZmZmZd d d d d dddgZGdd d eZGdd d eZGdd d eZGdd d eeZGdd d eeZGdddeeeeZGdddeZGdddeeZdS))Path)AnyCallableOptional TYPE_CHECKINGUnionN)cli) exceptions)utils) RESTManager RESTObject) DeleteMixinGetMixin ListMixinObjectDeleteMixinGenericPackageGenericPackageManager GroupPackageGroupPackageManagerProjectPackageProjectPackageManagerProjectPackageFileProjectPackageFileManagerc@seZdZdZdS)r package_nameN)__name__ __module__ __qualname__Z_id_attrrrY/home/ec2-user/environment/venv/lib/python3.6/dist-packages/gitlab/v4/objects/packages.pyrsc @seZdZdZeZddiZejdde j e j e e e e e efedd d Zejdde j e jde e e eeeeeeedddZd S)rz)/projects/%(project_id)s/packages/generic project_ididrpackage_version file_namepath)rr!r"r#returnc Ksy"t|d}|j}WdQRXWn$tk rFtjd|YnX|jd|d|d|}|jj|f|dd|} |j|||||| ddd S) aUpload a file as a generic package. Args: package_name (str): The package name. Must follow generic package name regex rules package_version (str): The package version. Must follow semantic version regex rules file_name (str): The name of the file as uploaded in the registry path (str): The path to a local file to upload Raises: GitlabConnectionError: If the server cannot be reached GitlabUploadError: If the file upload fails GitlabUploadError: If ``filepath`` cannot be read Returns: GenericPackage: An object storing the metadata of the uploaded package. rbNzFailed to read package file /T)Z post_datarawmessage)rr!r"r#r()attrs) openreadOSErrorexcGitlabUploadError_computed_pathgitlabZhttp_put_obj_cls) selfrr!r"r#kwargsfZ file_dataurlZ server_datarrrupload!s  zGenericPackageManager.uploadFN)rr!r"streamedaction chunk_sizer3r$c KsZ|jd|d|d|}|jj|f|dd|} trJt| tjsJttj | |||S)aaDownload a generic package. Args: package_name (str): The package name. package_version (str): The package version. file_name (str): The name of the file in the registry streamed (bool): If True the data will be processed by chunks of `chunk_size` and each chunk is passed to `action` for reatment action (callable): Callable responsible of dealing with chunk of data chunk_size (int): Size of each chunk **kwargs: Extra options to send to the server (e.g. sudo) Raises: GitlabAuthenticationError: If authentication is not correct GitlabGetError: If the server failed to perform the request Returns: str: The package content if streamed is False, None otherwise r&T)r8r') r/r0Zhttp_getr isinstancerequestsResponseAssertionErrorr Zresponse_content) r2rr!r"r8r9r:r3r#resultrrrdownloadUs $zGenericPackageManager.download)rr!r"r#)rr!r")FNr7)rrr_pathrr1_from_parent_attrsrZregister_custom_actionr-Z on_http_errorr.strrrr6ZGitlabGetErrorboolrrintrbytesr@rrrrrs*  ( c@s eZdZdS)rN)rrrrrrrrsc@s eZdZdZeZddiZd Zd S) rz/groups/%(group_id)s/packagesZgroup_idr exclude_subgroupsorder_bysort package_typerN)rGrHrIrJr)rrrrArr1rB _list_filtersrrrrrsc@seZdZdZdS)r package_filesrNrLr)rM)rrrZ _managersrrrrrsc@s eZdZdZeZddiZd ZdS) rz!/projects/%(project_id)s/packagesrr rHrIrJrN)rHrIrJr)rrrrArr1rBrKrrrrrsc@s eZdZdS)rN)rrrrrrrrsc@seZdZdZeZdddZdS)rz>/projects/%(project_id)s/packages/%(package_id)s/package_filesrr )rZ package_idN)rrrrArr1rBrrrrrs)pathlibrtypingrrrrrr<r0rr r-r Z gitlab.baser r Z gitlab.mixinsr rrr__all__rrrrrrrrrrrrs.    d