#Tc@sdZddlmZddlZddlZy ejWn/ek rjed\e_e_e_ nXddl Z ddl Z ddl Z ddl ZddljjZddljZddljZddljZddlmZededdd d d d d ddddddf DZeZdZ de!fdYZ"de#fdYZ$e j%e j&e'e$e$_(dS(smodule describing a generic packaging object This module contains the Action class, which represents a generic packaging object.i(tStringIONi(t EmptyDictccs!|]\}}||fVqdS(N((t.0titk((s9/usr/lib/python2.7/vendor-packages/pkg/actions/generic.pys :stsettdependtgrouptusertdirtfilethardlinktlinktdrivertunknowntlicensetlegacyt signaturecCspd|ks0d|ks0d|ks0|dkrld|krDd|Sd|krXd|Sd|jddS|S(sReturns a properly quoted version of the provided string suitable for use as an attribute value for actions in string form.t t's"ts"%s"s'%s's\"(treplace(ts((s9/usr/lib/python2.7/vendor-packages/pkg/actions/generic.pytquote_attr_valueMs0  tNSGcBsAeZdZdZdZeddZeddZRS(sThis metaclass automatically assigns a subclass of Action a namespace_group member if it hasn't already been specified. This is a convenience for classes which are the sole members of their group and don't want to hardcode something arbitrary and unique.icCsd}|dkrt|dtrxG|djD]8}|tkrIPnt|dd}|dk r3Pq3q3Wd|kr|stj}tjd7_n||dsicsS(N(((R7(s9/usr/lib/python2.7/vendor-packages/pkg/actions/generic.pyR=s(RR7t isinstancet basestringtosR9texistsR,R-tActionDataErrort_tisdirR6tstatR(tst_sizetEnvironmentErrortcallabletsizetAttributeErrortfstattfilenot TypeErrortseektSEEK_ENDttelltreadtlenR(tselfR7R<tfstetsztd((R7s9/usr/lib/python2.7/vendor-packages/pkg/actions/generic.pytset_datasf                c Cs|jj}|j}yX|j}|rod|kr_d|kr_d|kr_|d|7}qo|jdnWntk rnX|jxN|D]F}y|j|}Wntk r|}nXt|t kr|ddj g|D]!}dj |t |f^q7}qd|ksJd|ksJd|ksJ|dkrd|krs|d|d|d7}qd|kr|d|d|d7}q|d|d|j dd d7}q|d|d|7}qW|S( s5Serialize the action into manifest form. The form is the name, followed by the SHA1 hash, if it exists, (this use of a positional SHA1 hash is deprecated, with pkg.*hash.* attributes being preferred over positional hashes) followed by attributes in the form 'key=value'. All fields are space-separated; fields with spaces in the values are quoted. Note that an object with a datastream may have been created in such a way that the hash field is not populated, or not populated with real data. The action classes do not guarantee that at the time that __str__() is called, the hash is properly computed. This may need to be done externally. t=Rt"thashRRs="s='s\"( R6tkeysR#R[tappendRJtsorttKeyErrorR tlisttjoinRR(RStsattrstoutthRtvtlmt((s9/usr/lib/python2.7/vendor-packages/pkg/actions/generic.pyt__str__s<         30  &cCsd|jt||fS(Ns<%s object at %#x: %s>(t __class__tid(RS((s9/usr/lib/python2.7/vendor-packages/pkg/actions/generic.pyt__repr__=sc Cs|tjkr'tj|d|n|j}t|drb|jd k rb|d|j7}nd}x@t|j j D])}|j |}t |t kr|ddj gt|D]}d|||f^q7}qd|ksd|ksd|ks|dkrd|krB|d|d |d7}qd|krk|d|d |d7}q|d|d |jdd d7}q|d|d |7}qW|S(sCreate a stable string representation of an action that is deterministic in its creation. If creating a string from an action is non-deterministic, then manifest signing cannot work. The parameter "a" is the signature action that's going to use the string produced. It's needed for the signature string action, and is here to keep the method signature the same. tsigR[RcSswd|ks0d|ks0d|ks0|dkrod|krDd|Sd|krXd|Sd|jddSn|SdS(NRRs"Rs"%s"s'%s's\"(R(R((s9/usr/lib/python2.7/vendor-packages/pkg/actions/generic.pytqUs0  s%s=%sRs"Rs="s='s\"RYN(Rt sig_versiontapxtUnsupportedSignatureVersionR#thasattrR[RtsortedR6R\R R`RaR(RStatverRcRlRReRf((s9/usr/lib/python2.7/vendor-packages/pkg/actions/generic.pytsig_strAs(     70  &cCsP|j|jkrLt|ddt|ddkrL|j|jkrLtStS(NR[(R#RRR6tTruetFalse(RStother((s9/usr/lib/python2.7/vendor-packages/pkg/actions/generic.pyt__eq__us cCsP|j|jkrLt|ddt|ddkrL|j|jkrLtStS(NR[(R#RRR6RvRu(RSRw((s9/usr/lib/python2.7/vendor-packages/pkg/actions/generic.pyt__ne__}s cCs2t|j|j}|dkr.|j|S|S(sCompare actions for ordering. The ordinality of a given action is computed and stored at action initialization.i(tcmpt ordinalitytcompare(RSRwtres((s9/usr/lib/python2.7/vendor-packages/pkg/actions/generic.pyt__cmp__s  cCstt|t|S(N(RzRi(RSRw((s9/usr/lib/python2.7/vendor-packages/pkg/actions/generic.pyR|scCs|j}|j}t|j}t|j}|j|rItSx|jD]\}}||} || krVt|t| krt|tkrt| tkrt |t | krtSqtSqVqVW|r~d} } yNt j ||\} } } } | | krtS| dkr;| dkr;tSWq~t k rz| sX| r{td|j|jfq{q~XntS(s+Returns True if other represents a non-ignorable change from self. By default, this means two actions are different if any of their attributes are different. Subclasses should override this behavior when appropriate. s-attempt to compare a %s action to a %s actionN(R6Rtiterkeystsymmetric_differenceRut iteritemsRRR R`RqRtdigesttget_common_preferred_hashRJtAssertionErrorR#Rv(RSRwtcmp_hashRbtoattrstssettosetRrtxtytshashtohashtattrthfunc((s9/usr/lib/python2.7/vendor-packages/pkg/actions/generic.pyt differents8    $      cCst|jj}t|jj}|j|}x||@D]}t|j|tkrt|j|tkrt|j|t|j|kr|j|qqD|j||j|krD|j|qDqDW|S(sYReturns the attributes that have different values between other and self.(RR6R\RR R`Rqtadd(RSRwRRtlR((s9/usr/lib/python2.7/vendor-packages/pkg/actions/generic.pyt differencess&cCsWxP|jjD]?}t|j|trtt|j||j|R`R(RSR((s9/usr/lib/python2.7/vendor-packages/pkg/actions/generic.pytconsolidate_attrsscCs/t|dr+|jd|j|jfgSgS(sGenerate the information needed to index this action. This method, and the overriding methods in subclasses, produce a list of four-tuples. The tuples are of the form (action_name, key, token, full value). action_name is the string representation of the kind of action generating the tuple. 'file' and 'depend' are two examples. It is required to not be None. Key is the string representation of the name of the attribute being indexed. Examples include 'basename' and 'path'. Token is the token to be searched against. Full value is the value to display to the user in the event this token matches their query. This is useful for things like categories where what matched the query may be a substring of what the desired user output is. R[tcontent(RpR#R[(RS((s9/usr/lib/python2.7/vendor-packages/pkg/actions/generic.pytgenerate_indicesscCsCy*tjjtjj||jdSWntk r>dSXdS(sGiven an image root, return the installed path of the action if it has a installable payload (i.e. 'path' attribute).R9N(R@R9tnormpathRaR6R_(RStimg_root((s9/usr/lib/python2.7/vendor-packages/pkg/actions/generic.pytget_installed_paths  cCs<|jdkrt|Sd|j|jj|jdfS(sA Return the distinguishing name for this action, preceded by the type of the distinguishing name. For example, for a file action, 'path' might be the key_attr. So, the distinguished name might be "path: usr/lib/libc.so.1". s%s: %ss???N(tkey_attrRR(R#R6tget(RS((s9/usr/lib/python2.7/vendor-packages/pkg/actions/generic.pytdistinguished_names c Kstj|}tj||dsi(tvarianttVariantCombinationTemplateR%R(RS((RSs9/usr/lib/python2.7/vendor-packages/pkg/actions/generic.pytget_variant_template~s cCsx|jjD]}|d dks6|d dkrF|j|=qn|j s||jkreqn|jdkr|dkrqn||j|jgkrqn|jdks|jdkr|d d krqn|j|=qWd S( s.Strip actions of attributes which are unnecessary once those actions have been installed in an image. Stripped actions are saved in an images stripped action cache and used for conflicting actions checks during image planning operations.isvariant.isfacet.R toverlayR R tmediatorN(R6R\t unique_attrsR#R(RStpreservetkey((s9/usr/lib/python2.7/vendor-packages/pkg/actions/generic.pytstrips  cCs:x3|jjD]"}|jdr|j|=qqWdS(s2Remove all variant tags from the attrs dictionary.svariant.N(R6R\t startswith(RSR((s9/usr/lib/python2.7/vendor-packages/pkg/actions/generic.pytstrip_variantsscKs gggfS(sReturns a tuple of lists of the form (errors, warnings, info). The error list will be empty if the action has been correctly installed in the given image.((RStimgtargs((s9/usr/lib/python2.7/vendor-packages/pkg/actions/generic.pytverifyscCsg}t}|jjd}| s4t|tr=t}n^t|}|dkpj|dkpj|dksvt}n%|dkr|ddkrt}n|sytt|d}Wnt t fk rt}qX|dk}n|rY|s|j dt d fqYt|tr9|j dt d qY|j dt d |fny|jjd dj }Wn*tk r|j d t d fnXy|jjddj }Wn*tk r|j dt dfnX|S(sPrivate, common validation logic for filesystem objects that returns a list of tuples of the form (attr_name, error_message). Riiiit0iRsFmode is required; value must be of the form '644', '0644', or '04755'.smode may only be specified oncesN'%s' is not a valid mode; value must be of the form '644', '0644', or '04755'.towners owner may only be specified onceRs group may only be specified once(RvR6RR>R`RuRRR(tintRMt ValueErrorR]RCtrstripRJ(RSterrorstbad_modetraw_modetmlenRRR((s9/usr/lib/python2.7/vendor-packages/pkg/actions/generic.pyt_validate_fsobj_commons@  $     cCsk|j|jj}|jjddj}y|jj|}Wntk r7|sr|jd|n|jj j }||j kr|j |}t j j|dtdi|d6|d6|d6fgd|n||jkrnt j j|dtdi|d6|d6fgd|nX|jjddj}y|jj|}Wntk r`|s|jd|jn|jj j }||jkr |j|}t j j|dtd i|d6|d6|d6fgd|jn||jkrnt j j|dtd i|d6|d6fgd|jnX||fS( sReturns a tuple of the form (owner, group) containing the uid and gid of the filesystem object. If the attributes are missing or invalid, an InvalidActionAttributesError exception will be raised.RRRsT'%(path)s' cannot be installed; the owner '%(owner)s' was removed by '%(src_fmri)s'.R9tsrc_fmrisJ'%(path)s' cannot be installed; '%(owner)s' is an unknown or invalid user.RsT'%(path)s' cannot be installed; the group '%(group)s' was removed by '%(src_fmri)s'.sK'%(path)s' cannot be installed; '%(group)s' is an unknown or invalid group.(RtimageRR6RRtget_user_by_nameR_tvalidatet imageplantpdt removed_usersR,R-tInvalidActionAttributesErrorRCt added_userstget_group_by_nametdestination_fmritremoved_groupst added_groups(RStpkgplanRR9RRRR((s9/usr/lib/python2.7/vendor-packages/pkg/actions/generic.pytget_fsobj_uid_gids\            cCsg}g}g}t}d}d}} } d|jkrWt|jdd}nd|jkr|jd} y|j| } Wqtk r|jtd| d} qXnd|jkr|jd} y|j| } Wqtk r|jtd| d} qXn|j |j } d} yt j | } Wnt k r} | jtjkr|jjdd d kr| ||||fS|jtd ||n?| jtjkr|jtd n|jtd | t}nX|r| ||||fS|dk r|tj| jkr|jtdi|tj| jd6||d6t}n| dk r| j| kr|jtdi|j| jtd6| jd6|jdd6| d6n| dk r]| j| kr]|jtdi|j| jtd6| jd6|jdd6| d6n|dk rtj| j|kr|jtditj| jd6|d6n| ||||fS(s+Common verify logic for filesystem objects.cSs~|dk stidtj6dtj6dtj6dtj6dtj6dtj6dtj 6}||krr||Sd|SdS( Ntfifoscharacter devicet directorys block devices regular files symbolic linktsocketsUnknown (0x%x)( RRREtS_IFIFOtS_IFCHRtS_IFDIRtS_IFBLKtS_IFREGtS_IFLNKtS_IFSOCK(tftypettmap((s9/usr/lib/python2.7/vendor-packages/pkg/actions/generic.pyt ftype_to_nameRs        RiRsOwner: %s is unknownRsGroup: %s is unknown RRRsMissing: %s does not existsSkipping: Permission deniedsUnexpected Error: %ss/File Type: '%(found)s' should be '%(expected)s'tfoundtexpectedsVOwner: '%(found_name)s (%(found_id)d)' should be '%(expected_name)s (%(expected_id)d)'t found_nametfound_idt expected_namet expected_idsVGroup: '%(found_name)s (%(found_id)s)' should be '%(expected_name)s (%(expected_id)s)'s,Mode: 0%(found).3o should be 0%(expected).3oN(RvRR6RRR_R]RCRRRR@RRRRRtEACCESRuREtS_IFMTRRtget_name_by_uidRtget_name_by_gidtS_IMODE(RSRRRtwarningstinfotabortRRRRR9RRU((s9/usr/lib/python2.7/vendor-packages/pkg/actions/generic.pytverify_fsobj_commonJs         $   $cCstS(sLReturns True if the action transition requires a datastream.(Rv(RStorigR((s9/usr/lib/python2.7/vendor-packages/pkg/actions/generic.pyt needsdatascCst|jjddS(Nspkg.sizeR(RR6R(RS((s9/usr/lib/python2.7/vendor-packages/pkg/actions/generic.pytget_sizescCsCy|j|}Wntk r%gSXt|tk r?|gS|S(s0return list containing value of named attribute.(R6R_R R`(RSR#tvalue((s9/usr/lib/python2.7/vendor-packages/pkg/actions/generic.pytattrlists cCs9d|jkr5tjjtjj|jdgSgS(s&Returns references to paths in action.R9(R6R@R9tdirnameR(RS((s9/usr/lib/python2.7/vendor-packages/pkg/actions/generic.pytdirectory_referencesscCsdS(s5Client-side method that performs pre-install actions.N((RSRR((s9/usr/lib/python2.7/vendor-packages/pkg/actions/generic.pyt preinstallscCsdS(s,Client-side method that installs the object.N((RSRR((s9/usr/lib/python2.7/vendor-packages/pkg/actions/generic.pytinstallscCsdS(s6Client-side method that performs post-install actions.N((RSRR((s9/usr/lib/python2.7/vendor-packages/pkg/actions/generic.pyt postinstallscCsdS(s4Client-side method that performs pre-remove actions.N((RSR((s9/usr/lib/python2.7/vendor-packages/pkg/actions/generic.pyt preremovescCsdS(s+Client-side method that removes the object.N((RSR((s9/usr/lib/python2.7/vendor-packages/pkg/actions/generic.pytremovescCs |j}|s|j}nytj|Wntk r}|jtjkrTdS|jtjkrtj j |rt d|}t j |d|d|d|n|jtjkrt d|}t j |d|d|d|n|jtjkr&tjtj|j r&nQ|jtjtjfkrGn0|jtjkrwt j |d|d|nytj|Wq tk r}|jtjtjfkrn9|jtjtjfkrt j |d|d|n|j|q XnXdS(s0Shared logic for removing file and link objects.NsUnable to remove %s; it is in use as a mountpoint. To continue, please unmount the filesystem at the target location and try again.RRRsUUnable to remove %s; it is in use by the system, another process, or as a mountpoint.(Rt origin_fmriRR RGRRtEBUSYR@R9tismountRCRnRRRERRRRtEROFStrmdirRtEEXISTt ENOTEMPTYtsalvage(RSRR9RRUR((s9/usr/lib/python2.7/vendor-packages/pkg/actions/generic.pyt remove_fsobjsH  $       cCsdS(s5Client-side method that performs post-remove actions.N((RSR((s9/usr/lib/python2.7/vendor-packages/pkg/actions/generic.pyt postremovescCs+x$|D]}||d|stSqWtS(sqCallables in excludes list returns True if action is to be included, False if nott publisher(RvRu(RStexcludesRR'((s9/usr/lib/python2.7/vendor-packages/pkg/actions/generic.pyt include_thiss cCs|jd|dS(sJPerforms additional validation of action attributes that for performance or other reasons cannot or should not be done during Action object creation. An ActionError exception (or subclass of) will be raised if any attributes are not valid. This is primarily intended for use during publication or during error handling to provide additional diagonostics. 'fmri' is an optional package FMRI (object or string) indicating what package contained this action. RN(t _validate(RSR((s9/usr/lib/python2.7/vendor-packages/pkg/actions/generic.pyR%s c Csig}x|jD]}|jds=|dks=||krvt|j|tkrv|j|td|fq||kryt|j|Wqttfk r|j|td|fqXqqWxc|D][}|jj |}| st |t r|j r|j|td|fqqW|re|ret jj||d|n|S(sjCommon validation logic for all action types. 'fmri' is an optional package FMRI (object or string) indicating what package contained this action. 'numeric_attrs' is a list of attributes that must have an integer value. 'raise_errors' is a boolean indicating whether errors should be raised as an exception or returned as a list of tuples of the form (attr_name, error_message). 'single_attrs' is a list of attributes that should only be specified once. sfacet.s reboot-neededs%s may only be specified onces%s must be an integers%s is requiredR(R6RR R`R]RCRRMRRR>R?RR,R-R( RSRt numeric_attrst raise_errorstrequired_attrst single_attrsRRtval((s9/usr/lib/python2.7/vendor-packages/pkg/actions/generic.pyR3s.    c Cs#|jjj}tjj|}||kr1dStjj|}||kr`|j|dS|j}|}|jj j tjj }xL||kr|j|dStjj |rPntjj |d}q|} tjj| } tdt} tj|d| d|dS(sVerifies that the specified path doesn't contain one or more symlinks relative to the image root. Raises an ActionExecutionError exception if path check fails.NisCannot install '%(final_path)s'; parent directory %(parent_dir)s is a link to %(parent_target)s. To continue, move the directory to its original location and try again.RR(RRtvalid_directoriesR@R9RtrealpathRRtrootRtseptislinktsplitRCRRnR( RSRt final_patht valid_dirst parent_pathtreal_parent_pathRttmpRt parent_dirt parent_targetR((s9/usr/lib/python2.7/vendor-packages/pkg/actions/generic.pytfsobj_checkpath_s0        N((;R2R3R4t __slots__R#RRRvtglobally_identicalt refcountableRt _orderdictR{RRmt has_payloadRt __metaclass__RXRgRjRtRxRyR~R|RuRRRRRRRRRRRRRRRRRRRRRR R R R RRRRtEmptyIRR-(((s9/usr/lib/python2.7/vendor-packages/pkg/actions/generic.pyRsf   G =  4    0    m     = _ c         >  +()R4t cStringIORRR@tSEEK_SETRJtrangetSEEK_CURROREttypest_commont pkg.actionsR,tpkg.client.api_errorstclientt api_errorsRnt pkg.digestRt pkg.portableRt pkg.variantRtpkg.miscRR%RR1ttupleR4RR RtobjectRt MethodTypet _generic_initRt__init__(((s9/usr/lib/python2.7/vendor-packages/pkg/actions/generic.pytsN    "       0