XRc@sgddlZddlZddlZddlZddlZddljjZddl Zddl j Z ddl j Z ddljjZddljjZddljjZddljZddlmZmZmZmZddlmZdZ de!fdYZ"de!fdYZ#d e#fd YZ$d e#fd YZ%d e#fdYZ&dS(iN(t PackageInfot LicenseInfotPackageCategoryt_get_pkg_cat_data(t itemgetteri t BaseInterfacecBseZdZdZRS(sfThis class represents a base API object that is provided by the server to clients. A base API object is required when creating objects for any other interface provided by the API. This allows the server to provide a set of private object references that are needed by interfaces to provide functionality to clients. cCs||_||_||_dS(N(t_depott_requestt_pub(tselftrequesttdepottpub((s4/usr/lib/python2.7/vendor-packages/pkg/server/api.pyt__init__7s  (t__name__t __module__t__doc__R (((s4/usr/lib/python2.7/vendor-packages/pkg/server/api.pyR/st _InterfacecBseZdZdZRS(s;Private base class used for api interface objects. cCsXttg}||kr0tjt|n|j|_|j|_|j|_dS(N(tsettCURRENT_API_VERSIONt api_errorstVersionExceptionRRR(R t version_idtbasetcompatible_versions((s4/usr/lib/python2.7/vendor-packages/pkg/server/api.pyR Es     (RRRR (((s4/usr/lib/python2.7/vendor-packages/pkg/server/api.pyRBstCatalogInterfacecBs eZdZdZdZdZejZejZe dZ de j dZ de j e j dZe de j e j de dZe j d Zed Zed Zed Ze ejjddde d ZedZdZedZRS(saThis class presents an interface to server catalog objects that clients may use. iiicCsJy|jjj|j}Wntjk r9tdSX|jd|S(sA generator function that produces FMRIs as it iterates over the contents of the server's catalog. 'ordered' is an optional boolean value that indicates that results should sorted by stem and then by publisher and be in descending version order. If False, results will be in a ascending version order on a per-publisher, per-stem basis.tordered((Rtrepot get_catalogRtsrepotRepositoryMirrorErrortitertfmris(R Rtc((s4/usr/lib/python2.7/vendor-packages/pkg/server/api.pyR ^s  s5.11c s&y|jjj|j}Wntjk r3dSXtg|D]}|j^q>}td|D|j ||d|d|d|t|j g}t |j d|t j }x/|D]'} x|j| d|D]\} } j| t } x| D]} t }x|j| |d|D]}|jdkrYq>n|j}|d}|d}|d kr|d kr|jtjnPn|d kr>|d kr|jtjnPq>q>W| j| t|fqWqWqWtd fd tDS(sA generator function that produces a list of tuples of the form (fmri, states) in the catalog incorporated by the named package and its dependencies and any packages that are not incorporated by the named packages or their dependencies. FMRIs are returned ordered by stem and descending version. State is a set of PKG_STATES applicable to the 'fmri'.Ncss0|]&}|jt|tfgfVqdS(N(tpkg_nameRt frozenset(t.0tpfmri((s4/usr/lib/python2.7/vendor-packages/pkg/server/api.pys st build_releasetexcludestpubsRtnametvalues pkg.renamedttrues pkg.obsoleteic3s8|].}t|ddtD] }|Vq#qdS(tkeytreverseN(tsortedtTrue(R$R)tentry(tallowedtsort_ver(s4/usr/lib/python2.7/vendor-packages/pkg/server/api.pys s(RRRRRRR#t publishertdictt'_CatalogInterface__get_allowed_packagest DEPENDENCYRtnamestiterkeystfmris_by_versiont setdefaulttget_entry_actionsR)tattrstaddtpkgdefstPKG_STATE_RENAMEDtPKG_STATE_OBSOLETERR.(R tpfmrisR&R'tcatR%R(tcat_infot remainingR"tvertflisttasettftstatestfaR<tanametavalue((R1R2s4/usr/lib/python2.7/vendor-packages/pkg/server/api.pytgen_allowed_packagesnsR "               % c Cst|jg}x|j||d|D]}|jdkrFq+n|jddkr_q+ntjj|jddd} | j} | sq+nt } xd|j | j d|D]J\} } | j | tjj sqn|j| j t}x| D]}t}x|j||d|D]}|jd kr>q#n|j}|d }|d }|d kr|d kr|jtjnPn|dkr#|d kr|jtjnPq#q#W|j|t|f|j||d|d|d|qWqWq+WdS(NR'tdependttypet incorporatetfmriR&s5.11R(RR)R*s pkg.renamedR+s pkg.obsoleteR1(R#R6R;R)R<tpkgRQtPkgFmritversiontFalseR9R"t is_successortCONSTRAINT_AUTOR:RR=R>R?R@R5(R RBR%R1R&R'R(RCtatifmritivertrecurseRERFRGRHRIRJR<RKRL((s4/usr/lib/python2.7/vendor-packages/pkg/server/api.pyt__get_allowed_packagessT                 c Cshy|jjj|j}Wntjk r9tdSX|jd|d|d|d|d|d|S(sA generator function that produces tuples of the form: ( ( pub, - (string) the publisher of the package stem, - (string) the name of the package version - (string) the version of the package ), states, - (list) states attributes - (dict) package attributes ) Results are always sorted by stem, publisher, and then in descending version order. 'collect_attrs' is an optional boolean that indicates whether all package attributes should be collected and returned in the fifth element of the return tuple. If False, that element will be an empty dictionary. 'matched' is an optional set to add matched patterns to. 'patterns' is an optional list of FMRI wildcard strings to filter results by. 'pubs' is an optional list of publisher prefixes to restrict the results to. 'unmatched' is an optional set to add unmatched patterns to. 'return_fmris' is an optional boolean value that indicates that an FMRI object should be returned in place of the (pub, stem, ver) tuple that is normally returned.t collect_attrstmatchedtpatternsR(t unmatchedt return_fmris((RRRRRRRt gen_packages(R R]R^R_R(R`RaRB((s4/usr/lib/python2.7/vendor-packages/pkg/server/api.pyRbs% c')Cs|tj}|r%tj|ng}g}g}xz|D]r}yd} |j|} Wn)tjjk r} |j |q>q>X|j | d| s>|j |q>q>W|j j j |j} ttjtjtjtjg} tjttjg} g}xQ|D]I}d}}}}d}}}tj|kr|j\}}}|j}|j}|j}|jjd}nd}d}}}}}d}}}} }!}"| |@r4t| |d|d|\}}"}!}|!dk r4g|!D]\}#}$t|#|$^q }!q4nttjtjg| B|@rt j!|}%y|j j j |}&Wn&t"j#k r} |j |qnXt$j%j&|&s|j |qn|%j'd|&tj|kr|j(|%} ntj|kr%|%j)d|\}}n| |@rtj*|krYt+|%j,d|}ntj-|krt+|%j,d|}ntj.|krt+|%j,d|}ntj/|krt+|%j,d |}qqn|j td |d |d |!d |d|d|d|d|d|d|d|d|d| d|d|d|d|d|d|"qWi||j06||j16||j26S(sUGathers information about fmris. fmri_strings is a list of fmri_names for which information is desired. It returns a dictionary of lists. The keys for the dictionary are the constants specified in the class definition. The values are lists of PackageInfo objects or strings.is%cR'R%tpathnametlinkthardlinktfiletdirtpkg_stemtsummarytcategory_info_listRIR3RTR&tbranchtpackaging_datetsizetcsizetlicensestlinkst hardlinkstfilestdirst dependenciest descriptionN(3Rt ALL_OPTIONSRtUnrecognizedOptionsToInfotNonetget_matching_pattern_fmrisRRRQt IllegalFmritappendtextendRRRRR#tSUMMARYt CATEGORIESt DESCRIPTIONt DEPENDENCIEStACTION_OPTIONStIDENTITYttupletreleaseR&Rkt get_timestamptstrftimeRRtSIZEtLICENSEStmanifesttManifestRtRepositoryErrortostpathtexistst set_contentt_CatalogInterface__licensestget_sizetLINKStlisttgen_key_attribute_value_by_typet HARDLINKStFILEStDIRSt INFO_FOUNDt INFO_MISSINGt INFO_ILLEGALS('R t fmri_stringst info_neededR'tbad_optsR tnotfoundtillegalstpatternR%tetrepo_cattcat_optstact_optstpisRHR R)RTRR&RkRlRIRpRqRrRsRtRiRnRmRoRCRutschemeRBtmfsttmpath((s4/usr/lib/python2.7/vendor-packages/pkg/server/api.pytinfos            +            cCs;y|jjj|j}Wntjk r3dSX|jS(sReturns a datetime object representing the date and time at which the catalog was last modified. Returns None if not available. N(RRRRRRRxt last_modified(R R!((s4/usr/lib/python2.7/vendor-packages/pkg/server/api.pyRs cCs;y|jjj|j}Wntjk r3dSX|jS(s|The total number of packages in the catalog. Returns None if the catalog is not available. N(RRRRRRRxt package_count(R R!((s4/usr/lib/python2.7/vendor-packages/pkg/server/api.pyRs cCs;y|jjj|j}Wntjk r3dSX|jS(sThe total number of package versions in the catalog. Returns None if the catalog is not available. N(RRRRRRRxtpackage_version_count(R R!((s4/usr/lib/python2.7/vendor-packages/pkg/server/api.pyRs c sO|s gS|j}|js#gSdkr8dnfdfd}|skrd} |rtj|d} ntjdj|||dd} |jj j t | gd|j } | sdS|| d| Stjdj|||} |jj j t | gd|j } | sGdS| dS(sSearches the catalog for actions or packages (as determined by 'return_type') matching the specified 'tokens'. 'tokens' is a string using pkg(5) query syntax. 'case_sensitive' is an optional, boolean value indicating whether matching entries must have the same case as that of the provided tokens. 'return_type' is an optional, constant value indicating the type of results to be returned. This constant value should be one provided by the pkg.server.query_parser.Query class. 'start_point' is an optional, integer value indicating how many search results should be discarded before returning any results. None is interpreted to mean 0. 'num_to_return' is an optional, integer value indicating how many search results should be returned. None means return all results. 'matching_version' is a string in the format expected by the pkg.version.MatchingVersion class that will be used to further filter the search results as they are retrieved. 'return_latest' is an optional, boolean value that will cause only the latest versions of packages to be returned. Ignored if 'return_type' is not qp.Query.RETURN_PACKAGES. ic3s d}d}x|D]}|r3|kr3Pn|dtjjkrV|d}n'|dtjjkr}|dd}n|dk r||jkrqqnr|dtjjkr|dj}||krqq|}n|d7}|kr|VqqWdS(Niii(RxtqptQuerytRETURN_PACKAGEStRETURN_ACTIONSRTR"(tresultstmvertfoundt last_stemtresultR%tstem(t num_to_returnt return_latestt start_point(s4/usr/lib/python2.7/vendor-packages/pkg/server/api.pytfilter_resultss,         csy|j}Wntk r$dSX|d}tj|g|}r~|tjjkr~d}t|d||S||S(NicSsJ|d}|d}|j|jkr=t|j|jdSt||S(Nii(R"tcmpRT(tresatresbRXtb((s4/usr/lib/python2.7/vendor-packages/pkg/server/api.pyt cmp_fmriss    R(tnextt StopIterationt itertoolstchainRRRR.(RRRt return_typeR(RR(s4/usr/lib/python2.7/vendor-packages/pkg/server/api.pytfiltered_searchs    t R N( tsplittsearch_availableRxRTtMatchingVersionRRtjoinRRtsearchtstrR( R ttokenstcase_sensitiveRRRtmatching_versionRRRtquerytres_list((RRRRs4/usr/lib/python2.7/vendor-packages/pkg/server/api.pyRs8!          cCs;y|jjj|j}Wntjk r3tSX|jS(s~Returns a Boolean value indicating whether search functionality is available for the catalog. (RRtget_pub_rstoreRRtRepositoryUnknownPublisherRUR(R trstore((s4/usr/lib/python2.7/vendor-packages/pkg/server/api.pyR/s cCsg}x|jdD]}tj}|jjj|jd|j}t|d}tj||dt |j }|j |j t |j|d|qW|S(sRPrivate function. Returns the license info from the manifest mfst.tlicenseR trbt ignore_hashttext(tgen_actions_by_typetStringIORRRfthashRtmisctgunzip_from_streamR/tgetvaluetcloseR{RRQ(R Rt license_lsttlictstlpathtlfileR((s4/usr/lib/python2.7/vendor-packages/pkg/server/api.pyt __licenses:s !  cCsNy|jjj|j}Wntjk r3dSXt|drJ|jSdS(sgReturns the version of the catalog or None if no catalog is available. RTiN( RRRRRRRxthasattrRT(R R!((s4/usr/lib/python2.7/vendor-packages/pkg/server/api.pyRTIsN(RRRRRRR>R@R?RUR RtEmptyIRMR5RxRbRtpropertyRRRRRRRRRRT(((s4/usr/lib/python2.7/vendor-packages/pkg/server/api.pyROs.   E3 ,y    } tConfigInterfacecBseZdZedZedZedZedZedZedZ edZ edZ ed Z ed Z d Zd Zd ZdZRS(sThis class presents a read-only interface to configuration information and statistics about the depot that clients may use. cCs |jjjS(sThe number of /catalog operation requests that have occurred during the current server session. (RRtcatalog_requests(R ((s4/usr/lib/python2.7/vendor-packages/pkg/server/api.pyR^scCs |jjS(sqThe file system path where the server's content and web directories are located. (Rt content_root(R ((s4/usr/lib/python2.7/vendor-packages/pkg/server/api.pyRescCs |jjjS(s}The number of /file operation requests that have occurred during the current server session. (RRt file_requests(R ((s4/usr/lib/python2.7/vendor-packages/pkg/server/api.pyRlscCs |jjS(sThe number of /filelist operation requests that have occurred during the current server session. (Rtflist_requests(R ((s4/usr/lib/python2.7/vendor-packages/pkg/server/api.pytfilelist_requestssscCs |jjS(sThe number of files served by /filelist operations requested during the current server session. (Rtflist_file_requests(R ((s4/usr/lib/python2.7/vendor-packages/pkg/server/api.pytfilelist_file_requestszscCs |jjjS(sHThe number of package transactions awaiting completion. (RRtin_flight_transactions(R ((s4/usr/lib/python2.7/vendor-packages/pkg/server/api.pyRscCs |jjjS(sThe number of /manifest operation requests that have occurred during the current server session. (RRtmanifest_requests(R ((s4/usr/lib/python2.7/vendor-packages/pkg/server/api.pyRscCs |jjjS(suA Boolean value indicating whether the server is currently operating in mirror mode. (RRtmirror(R ((s4/usr/lib/python2.7/vendor-packages/pkg/server/api.pyRscCs |jjjS(swA Boolean value indicating whether the server is currently operating in readonly mode. (RRt read_only(R ((s4/usr/lib/python2.7/vendor-packages/pkg/server/api.pytreadonlyscCs |jjS(s`The file system path where the server's web content is located. (Rtweb_root(R ((s4/usr/lib/python2.7/vendor-packages/pkg/server/api.pyRscCsPi}xC|jjjjD])\}}g|D] }|^q2||tpkg.fmrit pkg.manifestRtpkg.miscRtpkg.server.api_errorstserverRtpkg.server.repositoryt repositoryRtpkg.server.query_parsert query_parserRt pkg.versionRTtpkg.api_commonRRRRtoperatorRRtobjectRRRRR(((s4/usr/lib/python2.7/vendor-packages/pkg/server/api.pyts,      "  y