ó ²7ÈOc@sáddlZddljjZddlZddlZddlj j Z ddl m Z m Z mZddgade jfd„ƒYZd„Zd„Zd „Zd „Zd „Zd „Zd „Zd„Zdd„ZdS(iÿÿÿÿN(t PD_LOCAL_PATHt PD_PROTO_DIRtPD_PROTO_DIR_LISTslib/svc/manifestsvar/svc/manifesttSMFManifestDependencycBs\eZdZdZdZd„Zd„Zed„ƒZ ee d„ƒZ ed„ƒZ RS(c CsÒ||_d}t|tƒrKtjj|ƒg}tjj|ƒg}n[t|tƒr—g}g}g|D]!}|j |dƒj dƒ^qm}nt j dƒ‚t j j||||||dd|ƒdS(s8 See __init__ for PublishingDependency. tt/s/A string or tuple must be specified for 'path'.t smf_manifestt full_pathsN(tmanifesttNonet isinstancet basestringtostpathtbasenametdirnamettupletreplacetlstriptbasetInvalidPublishingDependencytPublishingDependencyt__init__( tselftactionR tpkg_varst proto_dirRt base_namestpathstp((s=/usr/lib/python2.7/vendor-packages/pkg/flavor/smf_manifest.pyR1s .cCs d|j|j|j|jfS(NsSMFDep(%s, %s, %s, %s)(RRt run_pathsR(R((s=/usr/lib/python2.7/vendor-packages/pkg/flavor/smf_manifest.pyt__repr__Ls cCsdt_dt_dS(sUClear our manifest caches. This is primarily provided for test code.N(R Rt instance_mft instance_deps(((s=/usr/lib/python2.7/vendor-packages/pkg/flavor/smf_manifest.pyt _clear_cachePs cCsý|stjdkrdSnit_it_d„}g}x*tD]"}|jtjjd|ƒƒqDWxAt |ƒD]3}x*tD]"}|jtjj||ƒƒq„WqwWxH|D]@}g}tjj |||ƒx|D]}tj |ƒqÞWqµWdS(sËBuild our instance_mf and instance_deps dictionaries from the known SMF manifests installed on the current system and those that appear in the proto_dirs. NcSsLxE|D]=}tjj||ƒ}tjj|ƒr|j|ƒqqWdS(N(R R tjointisfiletappend(t manifestsRtfnamestfileR ((s=/usr/lib/python2.7/vendor-packages/pkg/flavor/smf_manifest.pytfindes R( RR R R!tmanifest_locationsR%R R R#treversedtwalkt)_SMFManifestDependency__populate_smf_dics(t proto_dirst force_updateR)tmanifest_pathstlocationRR&t manifest_file((s=/usr/lib/python2.7/vendor-packages/pkg/flavor/smf_manifest.pytpopulate_cacheWs&        cCsHt|ƒ\}}|r+tjj|ƒn|rDtjj|ƒndS(sªAdd a information information about the SMF instances and their dependencies from the given manifest_file to a global set of dictionaries.N(tparse_smf_manifestRR tupdateR!(R2R R!((s=/usr/lib/python2.7/vendor-packages/pkg/flavor/smf_manifest.pyt__populate_smf_dics~s   N( t__name__t __module__R R R!RRRt staticmethodR"tFalseR3R-(((s=/usr/lib/python2.7/vendor-packages/pkg/flavor/smf_manifest.pyR's  &cCs´d}d}d}|jdƒ}t|ƒdkrV|ddkrVd}|d}nQt|ƒdkr•|ddkr•d}|d}|d}nttdƒƒ‚|||fS( s~Split an SMF FMRI into constituent parts, returning the svc protocol, the service name, and the instance name, if any.t:iitsvciis FMRI does not appear to be validN(R tsplittlent ValueErrort_(tfmritprotocoltservicetinstancetarr((s=/usr/lib/python2.7/vendor-packages/pkg/flavor/smf_manifest.pytsplit_smf_fmri“s" "  cCsŽt|ƒ\}}}g}|dk rJ||krŠ|j||ƒqŠn@x=|D]5}|j|d|dƒrQ|j||ƒqQqQW|S(sVSearch a dictionary of SMF FMRI mappings, returning a list of results. If the FMRI points to an instance, we can return quickly. If the FMRI points to a service, we return all matching instances. Note if the dictionary contains service FMRIs, those won't appear in the results - we only ever return instances.R;N(RFR R%t startswith(RAt dictionaryRBRCRDtresultstitem((s=/usr/lib/python2.7/vendor-packages/pkg/flavor/smf_manifest.pytsearch_smf_dic§s   cCs¯t||ƒ}t|ƒdkr)|dSt|ƒdkrTttdƒ|ƒ‚nt|tjƒ}t|ƒdkr€|dSt|ƒdkr«ttdƒ|ƒ‚ngS(s{Given an instance FMRI, determine the FMRIs it depends on. If we match more than one fmri, we raise an exception. iis+more than one set of dependencies found: %s(RKR>R?R@RR!(RAR!RI((s=/usr/lib/python2.7/vendor-packages/pkg/flavor/smf_manifest.pytget_smf_dependenciesºscCsitƒ}|jt||ƒƒ|jt|tjƒƒt|ƒdkr_ttdƒƒ‚nt|ƒS(s Given an SMF FMRI that satisfies a given SMF dependency, determine which file(s) deliver that dependency using both the provided instance_mf dictionary and the global SmfManifestDependency dictionary. If multiple files match, we have a problem.is'cannot resolve FMRI to a delivered file( tsetR5RKRR R>R?R@tlist(RAR R&((s=/usr/lib/python2.7/vendor-packages/pkg/flavor/smf_manifest.pytresolve_smf_dependencyÐs  cKs×|jdkr,gtdƒ|jgifSt|jdƒsLggifS|jt}tj|jtƒg}g}tƒ}t |ƒ\}}|dkrºgtdƒ|gifSxÆ|D]¾} y+t | ƒ\} } } | dkrñwÁnWn0t k r$} |j tdƒtƒƒqÁnXtƒ}ytt| |ƒƒ}Wn-t k rv} |j tdƒtƒƒnXx|D]ý}yt||ƒ}Wn3t k rÌ} g}|j tdƒtƒƒnXt|ƒdkró|j|d ƒq~t|ƒdkr~t |ƒ\} } } | dk re|j td ƒi|d 6|d 6| d 6dj|ƒd6ƒn|jt|ƒƒq~q~WqÁWx1|D])}|j t||||jtƒƒqŠWi|jƒd6}|||fS(s‹Given an action and a place to find the file it references, if the file is an SMF manifest, we return a list of SmfManifestDependencies pointing to the SMF manifests in the proto area that would satisfy each dependency, a list of errors, and a dictionary containing the SMF FMRIs that were contained in the SMF manifest that this action delivers. Note that while we resolve SMF dependencies from SMF FMRIs to the files that deliver them, we don't attempt to further resolve those files to pkg(5) packages at this point. That stage is done using the normal "pkgdepend resolve" mechanism.R(s'%s actions cannot deliver SMF manifestsR sUnable to parse SMF manifest %ss#Problem resolving %(fmri)s: %(err)ss5Problem determining dependencies for %(fmri)s:%(err)ssaUnable to generate SMF dependency on %(dep_fmri)s declared in %(proto_file)s by %(fmri)s: %(err)siisÿUnable to generate SMF dependency on the service FMRI %(dep_fmri)s declared in %(proto_file)s by %(fmri)s. SMF dependencies should always resolve to SMF instances rather than SMF services and multiple files deliver instances of this service: %(manifests)stdep_fmrit proto_fileRAs, R&sorg.opensolaris.smf.fmriN(tnameR@thas_smf_manifest_dirtattrsRRR3RRMR4R RFR?R%tlocalsRLROR>taddR#RRtkeys(RRtkwargsRQtdepstelistt dep_manifestsR R!RARBRCRDterrt dep_fmrisRPR&Rt pkg_attrs((s=/usr/lib/python2.7/vendor-packages/pkg/flavor/smf_manifest.pytprocess_smf_manifest_depsãsv                   cCsºg}x­|D]¥}|jdƒ}|jdƒ}|jdƒ}|jdƒ}|r |dkr |dkr |dkr x6|D]+}|jdƒ}|r€|j|ƒq€q€Wq q W|S( sƒGiven a minidom Element deps, search for the elements inside it, and return the values as a list of strings.t service_fmrittypetgroupingtdeleteRCt require_allttruetvalue(tgetElementsByTagNamet getAttributeR%(RYt dependenciest dependencytfmristdep_typeRbRcR`((s=/usr/lib/python2.7/vendor-packages/pkg/flavor/smf_manifest.pyt__get_smf_dependenciesRs    cCs^ytj|ƒ}Wn!tjjjtfk r6tSX|jsDtS|jj dkrZtSt S(s6Quickly determine if smf_file is a valid SMF manifest.s+/usr/share/lib/xml/dtd/service_bundle.dtd.1( tminidomtparsetxmltparserstexpatt ExpatErrorR?R:tdoctypetsystemIdtTrue(tsmf_filetsmf_doc((s=/usr/lib/python2.7/vendor-packages/pkg/flavor/smf_manifest.pytis_smf_manifesths   cCs—i}i}ytj|ƒ}Wn!tjjjtfk rBd SX|jsPdS|jj dkrfdSd }t |t ƒr„|}n|j dƒ}x÷|D]ï}g}g}t } t } |jdƒ} | rš| jdƒ ršd| } |jd| ƒnqšg} xB|jD]7} t | tjƒr| jdkr| j| ƒqqW|jt| ƒƒ|j dƒrtt} n|j dƒ}x©|D]¡}g}|jdƒ}d }|r|d krÌ| rÌt} nd | |f}|j dƒ}|jt|ƒƒn|d k rŠ||||<|j|ƒqŠqŠW| r`| r`d | }|j|ƒ|||s    l     o   q