a r´£h*_ã@sŠddlmmZddlmZddlZddlmZddl Z ddl Z ddl Z ddl ZddlZddlZGdd„dejƒZGdd„dejƒZdS)éN)Úlint_fmri_successorcs’eZdZdZdZ‡fdd„Zdd„Zddd „Zd d „Zd d „Z dd„Z dd„Z ddd„Z e dƒe _d dd„Ze dƒe_d!dd„Ze dƒe_‡ZS)"ÚUserlandActionCheckerz3An opensolaris.org-specific class to check actions.zuserland.actioncsºtdƒ|_t d¡}|dkr(| ¡|_nd|_gd¢|_gd¢|_t  d¡t  d¡t  d¡g|_ t  d¡t  d ¡t  d ¡t  d ¡t  d ¡g|_ t  d ¡|_ i|_ i|_tt|ƒ |¡dS)Nz2checks Userland packages for common content errorsZ PROTO_PATH)Zi86Zsparcv7Z32zi86pc-solaris-64intzsun4-solaris-64int)Úamd64Zsparcv9Ú64zi86pc-solaris-thread-multi-64zsun4-solaris-thread-multi-64z ^/lib(/.*)?$z^/usr/z ^\$ORIGIN/z ^.*/64(/.*)?$z^.*/amd64(/.*)?$z^.*/sparcv9(/.*)?$z(^.*/i86pc-solaris-thread-multi-64(/.*)?$z'^.*/sun4-solaris-thread-multi-64(/.*)?$z^etc/(rc.|init)\.d)Ú_Ú descriptionÚosÚgetenvÚsplitÚ proto_pathÚ pathlist32Ú pathlist64ÚreÚcompileÚ runpath_reÚ runpath_64_reÚ initscript_reÚ lint_pathsÚ ref_pathsÚsuperrÚ__init__)ÚselfÚconfigÚpath©Ú __class__©úD/jenkins/jobs/oi-userland/workspace/tools/python/pkglint/userland.pyr-s.ÿ    ýû zUserlandActionChecker.__init__csDddd„}i}|j|j|j|jd�D]}| |j ¡g¡ |j¡q$|jD]}| |j ¡g¡ |j¡qJ|j   t dƒ¡|j|j |jd�D]6‰t ‡fdd „| ˆj ¡g¡DƒƒsŒ|ˆd |jƒqŒ|j   t d ƒ¡|j|j|j|jd�D]‰|ˆd |jƒqê|j   t d ƒ¡|jD]‰|ˆd |jƒ�q|j|j|j|jd �dS)zèInitialize the checker with a dictionary of paths, so that we can do link resolution. This is copied from the core pkglint code, but should eventually be made common. NFc Ssž| ¡}|r"dd„| |¡Dƒ}ndd„| ¡Dƒ}|D]`}|rL|j|krLq8||jvrXq8| ¡}| |¡|j |¡|j|} | | g¡  |j |f¡q8dS)zâUpdates a dictionary of { attr: [(fmri, action), ..]} where attr is the value of that attribute from actions of a given type atype, in the given manifest.css|] }|VqdS©Nr©Ú.0ÚarrrÚ kózCUserlandActionChecker.startup..seed_dict..css|] }|VqdSrrrrrrr"mr#N) Úget_all_variantsÚgen_actions_by_typeÚ gen_actionsÚnameÚattrsÚget_variant_templateÚ merge_unknownÚupdateÚ setdefaultÚappendÚfmri) ÚmfÚattrÚdicÚatypeÚverboseÚpkg_varsZmfgÚactionÚvariantsÚprrrÚ seed_dictbs    z0UserlandActionChecker.startup..seed_dict)ÚreleaseÚpatternz+Seeding reference action path dictionaries.)r9c3s|]}t|ˆjƒVqdSr)rr.)r r.©Úmanifestrrr"�sÿz0UserlandActionChecker.startup..rz&Seeding lint action path dictionaries.z'Seeding local action path dictionaries.©Ú ignore_pubs)NF)Ú gen_manifestsÚ lint_api_instr9r:r,r.Úget_namer-Úlint_manifestsÚloggerÚdebugrÚ ref_api_instÚanyÚgetrrÚ"_UserlandActionChecker__merge_dictr>)rÚenginer8Ú lint_fmrisÚmrr;rÚstartupZsB ÿ  ÿÿ  ýÿÿ ÿ  ÿzUserlandActionChecker.startupTcCsÀ|D]¶}||vr||||<qdd„}|||ƒ}|||ƒ}|D]:}| ¡D],} | ¡} |  ¡} t|| |d�rN| | ¡qNqB| |¡g} |D] } || D]}|  | |f¡qœq�| ||<qdS)aPMerges the given src dictionary into the target dictionary, giving us the target content as it would appear, were the packages in src to get published to the repositories that made up target. We need to only merge packages at the same or successive version from the src dictionary into the target dictionary. If the src dictionary contains a package with no version information, it is assumed to be more recent than the same package with no version in the target.cSs8i}|D]*\}}||vr(|| |¡q|g||<q|S)z*Builds a dictionary of fmri:action entries)r-)Úarrr1Úpfmrir5rrrÚ build_dic·s   z5UserlandActionChecker.__merge_dict..build_dicr=N)ÚcopyrArÚpopr+r-)rÚsrcÚtargetr>r7rOÚsrc_dicÚtarg_dicÚ src_pfmriÚ targ_pfmriÚsnameÚtnameÚlrNr5rrrZ __merge_dict¦s,     þ  z"UserlandActionChecker.__merge_dictcCsPtj |¡}| tj¡D]2}|dkr2tj |¡}q|dkrd}q>d} |jD]}||vrZd} qZ|dkr�|dkr�| dkr�|dkr�|S|dkr¦|r¦t d ƒ}n|dkrº|sºt d ƒ}|S) Nruraú/FTrbé@rxz!32-bit object '%s' in 64-bit pathz!64-bit object '%s' in 32-bit path) rirjrGrrr\r r r r) rrr_rsruraZelemsZpath64r7Zpath32rrrZ__elf_wrong_location_check7s(         z0UserlandActionChecker.__elf_wrong_location_checkrfc Csâ|jdvrdS|j}|dks$|dkr.|jd}d|jvr†|jd}t|dƒd@dkr„d |jvr„|jtd ƒ||d œd |j|fd �n€d |jv�rd|jvrà|jd}t|dƒd@dkrÞ|jtdƒ||d œd|j|fd �n&|jtdƒ||d œd|j|fd �|jdu�rÞ|jD]&}|d|}tj  |¡�r�q@�qtj  |¡�sp|j tdƒ|d|j|fd �nnt   |¡�rÞ|  |¡} | dk�r¬|j| |d|j|fd �| ||¡} | dk�rÞ|j| |d|j|fd �dS)z'Checks for existence in the proto area.)ÚfileNÚNOHASHrÚmodeéé’rÚpreservezA%(path)s is writable (%(mode)s), but missing a preserve attribute)rr„ú%s%s.0rgz>%(path)s has a preserve action, but is not writable (%(mode)s)z%s%s.4z+%(path)s has a preserve action, but no moderyr€z3%s missing from proto area, skipping content checksú%s%s.1ú%s%s.2)r'Úhashr(Úintrprr rrÚexistsÚinforiÚ is_elf_objectÚ0_UserlandActionChecker__elf_wrong_location_checkÚ)_UserlandActionChecker__elf_runpath_check) rr5r<rIÚ pkglint_idrr„Ú directoryÚfullpathr_rrrÚ file_actionTsb    ÿ ý    þ þ    ÿ ý     ÿ    ÿz!UserlandActionChecker.file_actionz%Paths should exist in the proto area.Ú002c Cs�|jdvrdS|jd}|jd}| ||¡}|j |d¡r@dS|d7}|jD]}| |¡rNdSqN|jtdƒ|j||fd|j|fd�dS) zChecks for link resolution.)ÚlinkÚhardlinkNrrSr€z"%s %s has unresolvable target '%s'rˆrg)r'r(Ú _UserlandActionChecker__realpathrrGÚ startswithrpr) rr5r<rIr’rrSZ realtargetÚkeyrrrÚ link_resolves�s         ÿ þz#UserlandActionChecker.link_resolveszlinks should resolve.Ú003cCsH|jdvrdS|jd}|j |¡rD|jtdƒ|d|j|fd�dS)z Checks for SVR4 startup scripts.)r‚r~r—r˜Nrz.SVR4 startup '%s', deliver SMF service insteadrˆrg)r'r(rr{rrr)rr5r<rIr’rrrrÚ init_script²s   ÿ ýz!UserlandActionChecker.init_scriptz-SVR4 startup scripts should not be delivered.)T)rf)r–)r�)Ú__name__Ú __module__Ú __qualname__Ú__doc__r'rrLrHr™Z&_UserlandActionChecker__elf_aslr_checkr‘r�r•rÚ pkglint_descrœržÚ __classcell__rrrrr(s" -L /!2 9  !  ÿrcs`eZdZdZdZ‡fdd„Zddd„Zedƒe_dd d „Z ed ƒe _ddd„Z edƒe _‡Z S)ÚUserlandManifestCheckerz5An opensolaris.org-specific class to check manifests.zuserland.manifestcstt|ƒ |¡dSr)rr¥r)rrrrrrÇsz UserlandManifestChecker.__init__Ú1001c Cs$tj d¡�s | d¡D�]}| d¡D]ô}tj |¡j}tj j j j tj j j j ttj j j jgƒB}tj j ¡}tj j  dtj j j|dd„dd¡} |  |gd|¡} | tj j jjr(| d|j¡ d ¡d d g} | tj j jjD]:} | j| vrà|jtd ƒ|j|| jd œd|j|fd�qàq(qdS)NZ ENCUMBEREDÚdependr.r€cSsdS)NFr)ÚxrrrÚÓr#z=UserlandManifestChecker.forbidden_publisher..Tú%s.allowed_pubsú zopenindiana.orgz on-nightlyzWpackage %(pkg)s depends on %(name)s, which comes from forbidden publisher %(publisher)s)Úpkgr'Ú publisherr‰rg)rÚenvironrGr%Úattrlistr¬r.ÚPkgFmriÚpkg_nameÚclientÚapiÚ PackageInfoÚ ALL_OPTIONSÚACTION_OPTIONSÚ frozensetÚLICENSESÚprogressÚNullProgressTrackerÚImageInterfaceÚCURRENT_API_VERSIONrŽÚ INFO_FOUNDÚ get_paramr'r r­rpr) rr<rIr’r5Úfr±Ú info_neededZ progtrackerZ interfaceÚretÚ allowed_pubsÚirrrÚforbidden_publisherÊs*  ÿÿ "  ÿ ÿz+UserlandManifestChecker.forbidden_publisherz1Dependencies should come from standard publishersrfcCs˜g}d}d}| d¡D] }d}q$q|dkr0dS| d¡D]4}|jdsf|jtdƒd|j|fd�q:d}qpq:|dkr”|jtdƒd|j|fd�dS) NFr‚TÚlicensezNmissing vaue for action license attribute 'license' like 'CDDL','MIT','GPL'...rˆrgzmissing license action)r%r(rprr')rr<rIr’Zmanifest_pathsÚfilesrÅr5rrrÚcomponent_checkßs&   ÿ  ÿz'UserlandManifestChecker.component_checkzFlicense actions and ARC information are required if you deliver files.r–cCsR| d|j¡ d¡}|j}|jrN|j|vrN|jtdƒ|jd|j|fd�dS)Nrªr«zpackage %s has a publisher set!rŠrg)r¾r'r r.r­rpr)rr<rIr’rÂr.rrrÚpublisher_in_fmriþsÿÿ ÿ þz)UserlandManifestChecker.publisher_in_fmrizextra publisher set)r¦)rf)r–) rŸr r¡r¢r'rrÄrr£rÇrÈr¤rrrrr¥Âs  ÿ ÿ ÿr¥)Ú pkg.lint.baseÚlintÚbaseÚpkg.lint.enginerÚpkg.fmrir¬Úpkg.elfrirZos.pathrrkÚpkg.client.apiÚpkg.client.api_errorsÚpkg.client.progressÚ ActionCheckerrÚManifestCheckerr¥rrrrÚs