o ¶žâcôã@s²ddlmZmZddlmZddlZdZdZdZdZ dZ d eBZ d eBZ d eBZ d eBZd eBZde BZde BZGdd„deƒZGdd„deƒZdd„Z ddd„Zddd„ZdS)é)ÚunicodeÚ_PY3)Úsha1Néééééiiiiiiic@seZdZdZdS)ÚPackageTypeErrorzDRaised when an unsupported package type is passed to build_skeleton.N)Ú__name__Ú __module__Ú __qualname__Ú__doc__©rrúD/usr/lib/python3/dist-packages/landscape/lib/apt/package/skeleton.pyr sr c@sDeZdZdZdZdZdZdZdZdd„Z dd„Z dd„Z dd „Z dS) ÚPackageSkeletonNcCs||_||_||_g|_dS©N)ÚtypeÚnameÚversionÚ relations)ÚselfrrrrrrÚ__init__#s zPackageSkeleton.__init__cCs|j ||f¡dSr)rÚappend)rrÚinforrrÚ add_relation)szPackageSkeleton.add_relationcCsp|jdur|jSd|j|j|jf d¡}t|ƒ}|j ¡|jD]}| d|d|df d¡¡q!|  ¡S)zšCalculate the package hash. If C{set_hash} has been used, that hash will be returned and the hash won't be the calculated value. Nz [%d %s %s]Úasciiz[%d %s]rr) Ú_hashrrrÚencoderrÚsortÚupdateÚdigest)rÚ package_infor!ÚpairrrrÚget_hash,s ÿ  ÿzPackageSkeleton.get_hashcCs ||_dS)aZSet the hash to an explicit value. This should be used when the hash is previously known and can't be calculated from the relations anymore. The only use case for this is package resurrection. We're planning on getting rid of package resurrection, and this code can be removed when that is done. N)r)rÚ package_hashrrrÚset_hash?s zPackageSkeleton.set_hash) r r r ÚsectionÚsummaryÚ descriptionÚsizeÚinstalled_sizerrrr$r&rrrrrs rcCs&|\}}}|}|r|d||f7}|S)aConvert an apt relation to a string representation. @param relation_tuple: A tuple, (name, version, relation). version and relation can be the empty string, if the relation is on a name only. Returns something like "name > 1.0" z %s %sr)Úrelation_tuplerrÚ relation_typeÚrelation_stringrrrÚrelation_to_stringLs r/c Cs`tƒ}t | |d¡¡}|D]}dd„|Dƒ}|}t|ƒdkr!|}d |¡} | || f¡q|S)a¬Parse an apt C{Record} field and return skeleton relations @param record: An C{apt.package.Record} instance with package information. @param record_field: The name of the record field to parse. @param relation_type: The deb relation that can be passed to C{skeleton.add_relation()} @param or_relation_type: The deb relation that should be used if there is more than one value in a relation. ÚcSsg|]}t|ƒ‘qSr)r/)Ú.0ÚrelationrrrÚ jsz&parse_record_field..rz | )ÚsetÚapt_pkgÚ parse_dependsÚgetÚlenÚjoinÚadd) ÚrecordÚ record_fieldr-Úor_relation_typerÚvaluesÚvalueÚ value_stringsÚvalue_relation_typer.rrrÚparse_record_field\s   rBFcCsZ|jj|j}}|rt|ƒt|ƒ}}tt||ƒ}tƒ}| t|j dt ƒ¡|  t d|jj|jff¡| t|j dt tƒ¡| t|j dt tƒ¡|  td|jj|jff¡| t|j dtƒ¡| t|j dtƒ¡t|ƒ|_|r«|j|_|j|_|j|_|j|_|jdkrŒ|j|_|r«ts«|j d ¡|_|j d ¡|_t|jtƒs«|j d ¡|_|S) aSBuild a package skeleton from an apt package. @param version: An instance of C{apt.package.Version} @param with_info: Whether to extract extra information about the package, like description, summary, size. @param with_unicode: Whether the C{name} and C{version} of the skeleton should be unicode strings. ÚProvidesz%s = %sz Pre-DependsÚDependsz%s < %sÚ ConflictsÚBreaksrzutf-8)ÚpackagerrrrÚ DEB_PACKAGEr4r rBr;Ú DEB_PROVIDESr:ÚDEB_NAME_PROVIDESÚ DEB_REQUIRESÚDEB_OR_REQUIRESÚ DEB_UPGRADESÚ DEB_CONFLICTSÚsortedrr'r(r)r*r+rÚdecodeÚ isinstance)rÚ with_infoÚ with_unicoderÚversion_stringÚskeletonrrrrÚbuild_skeleton_aptssR  ÿþ ÿ ÿÿÿÿ   rVr)FF)Úlandscape.lib.compatrrÚlandscape.lib.hashlibrr5ÚPACKAGEÚPROVIDESÚREQUIRESÚUPGRADESÚ CONFLICTSrHrIrJrKrLrMrNÚ Exceptionr Úobjectrr/rBrVrrrrÚs* 2 ÿ