QTc@sdZdZdZddlZddlZddlZddlmZddl m Z edfkZ dZ e rze ZneZd Zd Zd Zd efd YZdefdYZdS(sPure python bindings for the augeas library Augeas is a library for programmatically editing configuration files. Augeas parses configuration files into a tree structure, which it exposes through its public API. Changes made through the API are written back to the initially read files. The transformation works very hard to preserve comments and formatting details. It is controlled by ``lens'' definitions that describe the file format and the transformation into a tree. s/Nathaniel McCallum sJeff Schroeder Harald Hoyer - initial python bindings, packaging Nils Philippsen iN(t version_info(treduceitutf8cCs|r|jtSdS(N(tencodetAUGENC(tst((s*/usr/lib/python2.7/site-packages/augeas.pytenc:scCs|r|jtSdS(N(tdecodeR(R((s*/usr/lib/python2.7/site-packages/augeas.pytdec?scGstgg|D]}tjj|^q D]}|r&|^q&}td|d}|sptd|dn|S(s]Search for one of the libraries given as arguments and load it. Returns the library. cSs|ptjj|S(N(tctypestcdllt LoadLibrary(txty((s*/usr/lib/python2.7/site-packages/augeas.pytIssUnable to import lib%s!iN(R tutilt find_libraryRtNonet ImportError(targstatltlibstlib((s*/usr/lib/python2.7/site-packages/augeas.pyt_dlopenDs >tAugeascBs:eZdZedZejej_dZ d Z d!Z d"Z d#Z d$Zd%Zd&Zd'Zd(d(e d Zd Zd Zd ZdZdZdZdZdZdZdZdZedZ dZ!dZ"dZ#dZ$dZ%dZ&d(d)dZ'e(dZ)dZ*RS(*s$Class wrapper for the augeas librarytaugeasiiiiiiiicCst|t r+|dkr+tdnt|t rV|dkrVtdnt|tsttdntjjt|t|||_ |j st dnt j |j |_ dS(sInitialize the library. Use 'root' as the filesystem root. If 'root' is None, use the value of the environment variable AUGEAS_ROOT. If that doesn't exist either, use "/". 'loadpath' is a colon-spearated list of directories that modules should be searched in. This is in addition to the standard load path and the directories in AUGEAS_LENS_LIB. 'flags' is a bitmask made up of values from AUG_FLAGS.sroot MUST be a string or None!s"loadpath MUST be a string or None!sflag MUST be a flag!sUnable to create Augeas object!N( t isinstancet string_typesRt TypeErrortintRt _libaugeastaug_initRt_Augeas__handlet RuntimeErrorR tc_void_p(tselftroottloadpathtflags((s*/usr/lib/python2.7/site-packages/augeas.pyt__init__`s' cCs|jdS(N(tclose(R$((s*/usr/lib/python2.7/site-packages/augeas.pyt__del__|scCst|tstdn|js6tdntj}tjj |jt |tj |}|dkrt dnt |jS(sLookup the value associated with 'path'. Returns the value at the path specified. It is an error if more than one node matches 'path'.spath MUST be a string!s*The Augeas object has already been closed!is$path specified had too many matches!(RRRR!R"R tc_char_pRRtaug_getRtbyreft ValueErrorRtvalue(R$tpathR/tret((s*/usr/lib/python2.7/site-packages/augeas.pytgets   cCst|tstdn|js6tdntj}tjj |jt |tj |}|dkrt dnt |jS(sLookup the label associated with 'path'. Returns the label of the path specified. It is an error if more than one node matches 'path'.spath MUST be a string!s*The Augeas object has already been closed!is$path specified had too many matches!(RRRR!R"R R+RRt aug_labelRR-R.RR/(R$R0tlabelR1((s*/usr/lib/python2.7/site-packages/augeas.pyR4s   cCst|tstdnt|t rUt|tdkrUtdn|jsmtdntjj |jt |t |}|dkrt dndS(sSet the value associated with 'path' to 'value'. Intermediate entries are created if they don't exist. It is an error if more than one node matches 'path'.spath MUST be a string!svalue MUST be a string or None!s*The Augeas object has already been closed!isUnable to set value to path!N( RRRttypeRR!R"RRtaug_setRR.(R$R0R/R1((s*/usr/lib/python2.7/site-packages/augeas.pytsets( ' cCst|tkr!tdnt|tkrN|dkrNtdnt|tkrotdn|jstdntjj|jt |t |t |}|dkrt dn|S(sSet the value of multiple nodes in one operation. Find or create a node matching 'sub' by interpreting 'sub' as a path expression relative to each node matching 'base'. 'sub' may be None, in which case all the nodes matching 'base' will be modified.sbase MUST be a string!ssub MUST be a string or None!svalue MUST be a string!s*The Augeas object has already been closed!isUnable to set value to path!N( R5tstrRRR!R"RRtaug_setmRR.(R$tbasetsubR/R1((s*/usr/lib/python2.7/site-packages/augeas.pytsetms  ' cCst|tstdnt|ts<tdnt|tsZtdn|jsrtdntjj|jt|t|t|}|dkrt dn|S(sUse the value of node 'node' as a string and transform it into a tree using the lens 'lens' and store it in the tree at 'path', which will be overwritten. 'path' and 'node' are path expressions.slens MUST be a string!snode MUST be a string!spath MUST be a string!s*The Augeas object has already been closed!isUnable to store text at node!( RRRR!R"RRtaug_text_storeRR.(R$tlenstnodeR0R1((s*/usr/lib/python2.7/site-packages/augeas.pyt text_stores  ' cCst|tstdnt|ts<tdnt|tsZtdnt|tsxtdn|jstdntjj|jt|t|t|t|}|dkrt dn|S(sTransform the tree at 'path' into a string using lens 'lens' and store it in the node 'node_out', assuming the tree was initially generated using the value of node 'node_in'. 'path', 'node_in', and 'node_out' are path expressions.slens MUST be a string!snode_in MUST be a string!spath MUST be a string!snode_out MUST be a string!s*The Augeas object has already been closed!isUnable to store text at node!( RRRR!R"RRtaug_text_retrieveRR.(R$R>tnode_inR0tnode_outR1((s*/usr/lib/python2.7/site-packages/augeas.pyt text_retrieves  0 cCst|tkr!tdnt|tkrN|dkrNtdn|jsftdntjj|jt |t |}|dkrt dn|S(s~Define a variable 'name' whose value is the result of evaluating 'expr'. If a variable 'name' already exists, its name will be replaced with the result of evaluating 'expr'. If 'expr' is None, the variable 'name' will be removed if it is defined. Path variables can be used in path expressions later on by prefixing them with '$'.sname MUST be a string!sexpr MUST be a string or None!s*The Augeas object has already been closed!isUnable to register variable!N( R5R8RRR!R"RRt aug_defvarRR.(R$tnametexprR1((s*/usr/lib/python2.7/site-packages/augeas.pytdefvars  ' cCst|tkr!tdnt|tkrBtdnt|tkrctdn|js{tdntjj|jt|t|t|d}|dkrt dn|S(sDefine a variable 'name' whose value is the result of evaluating 'expr', which must not be None and evaluate to a nodeset. If a variable 'name' already exists, its name will be replaced with the result of evaluating 'expr'. If 'expr' evaluates to an empty nodeset, a node is created, equivalent to calling set(expr, value) and 'name' will be the nodeset containing that single node.sname MUST be a string!sexpr MUST be a string!svalue MUST be a string!s*The Augeas object has already been closed!isUnable to register node!N( R5R8RR!R"RRt aug_defnodeRRR.(R$RFRGR/R1((s*/usr/lib/python2.7/site-packages/augeas.pytdefnodes   * cCst|tstdnt|ts<tdn|jsTtdntjj|jt|t|}|dkrt dndS(sjMove the node 'src' to 'dst'. 'src' must match exactly one node in the tree. 'dst' must either match exactly one node in the tree, or may not exist yet. If 'dst' exists already, it and all its descendants are deleted before moving 'src' there. If 'dst' does not exist yet, it and all its missing ancestors are created.ssrc MUST be a string!sdst MUST be a string!s*The Augeas object has already been closed!isUnable to move src to dst!N( RRRR!R"RRtaug_mvRR.(R$tsrctdstR1((s*/usr/lib/python2.7/site-packages/augeas.pytmove7s ' cCst|tstdnt|ts<tdn|jsTtdntjj|jt|t|}|dkrt dn|S(s6Rename the label of all nodes matching 'src' to 'lbl'.ssrc MUST be a string!sdst MUST be a string!s*The Augeas object has already been closed!isUnable to rename src as dst!( RRRR!R"RRt aug_renameRR.(R$RLRMR1((s*/usr/lib/python2.7/site-packages/augeas.pytrenameKs ' cCst|tstdnt|ts<tdn|jsTtdntjj|jt|t||rdpd}|dkrt dndS(sXCreate a new sibling 'label' for 'path' by inserting into the tree just before 'path' (if 'before' is True) or just after 'path' (if 'before' is False). 'path' must match exactly one existing node in the tree, and 'label' must be a label, i.e. not contain a '/', '*' or end with a bracketed index '[N]'.spath MUST be a string!slabel MUST be a string!s*The Augeas object has already been closed!iisUnable to insert label!N( RRRR!R"RRt aug_insertRR.(R$R0R4tbeforeR1((s*/usr/lib/python2.7/site-packages/augeas.pytinsert\s   cCsRt|tstdn|js6tdntjj|jt|S(sRemove 'path' and all its children. Returns the number of entries removed. All nodes that match 'path', and their descendants, are removed.spath MUST be a string!s*The Augeas object has already been closed!( RRRR!R"RRtaug_rmR(R$R0((s*/usr/lib/python2.7/site-packages/augeas.pytremovess  cCst|tstdn|js6tdntjtj}tj j |jt |tj |}|dkrtd|ng}xgt |D]Y}||r|jttj||tjjtjjtj||qqWtjj||S(sReturn the matches of the path expression 'path'. The returned paths are sufficiently qualified to make sure that they match exactly one node in the current tree. Path expressions use a very simple subset of XPath: the path 'path' consists of a number of segments, separated by '/'; each segment can either be a '*', matching any tree node, or a string, optionally followed by an index in brackets, matching tree nodes labelled with exactly that string. If no index is specified, the expression matches all nodes with that label; the index can be a positive number N, which matches exactly the Nth node with that label (counting from 1), or the special expression 'last()' which matches the last node with the given label. All matches are done in fixed positions in the tree, and nothing matches more than one path segment.spath MUST be a string!s*The Augeas object has already been closed!isError during match procedure!(RRRR!R"R tPOINTERR#RRt aug_matchRR-trangetappendRtcastR+R/t pythonapit PyMem_Free(R$R0tarrayR1tmatchesti((s*/usr/lib/python2.7/site-packages/augeas.pytmatchs"   $c Cs?t|tstdn|js6tdntj}tj}tj}tj}tj}tj}tj}tj} t j j |jt || || || || || || || | } | dkr t dnt|j|j|j|j|j|j|jfS(siGet the span according to input file of the node associated with PATH. If the node is associated with a file, un tuple of 5 elements is returned: (filename, label_start, label_end, value_start, value_end, span_start, span_end). If the node associated with PATH doesn't belong to a file or is doesn't exists, ValueError is raised.spath MUST be a string!s*The Augeas object has already been closed!isError during span procedure(RRRR!R"R R+tc_uintR-RRtaug_spanRR.RR/( R$R0tfilenamet label_startt label_endt value_startt value_endt span_starttspan_endtrR1((s*/usr/lib/python2.7/site-packages/augeas.pytspans*         !  cCsL|jstdntjj|j}|dkrHtdndS(sWrite all pending changes to disk. Only files that had any changes made to them are written. If SAVE_NEWFILE is set in the creation 'flags', create changed files as new files with the extension ".augnew", and leave the original file unmodified. Otherwise, if SAVE_BACKUP is set in the creation 'flags', move the original file to a new file with extension ".augsave". If neither of these flags is set, overwrite the original file.s*The Augeas object has already been closed!isUnable to save to file!N(R!R"RRtaug_savetIOError(R$R1((s*/usr/lib/python2.7/site-packages/augeas.pytsaves   cCsL|jstdntjj|j}|dkrHtdndS(sLoad files into the tree. Which files to load and what lenses to use on them is specified under /augeas/load in the tree; each entry /augeas/load/NAME specifies a 'transform', by having itself exactly one child 'lens' and any number of children labelled 'incl' and 'excl'. The value of NAME has no meaning. The 'lens' grandchild of /augeas/load specifies which lens to use, and can either be the fully qualified name of a lens 'Module.lens' or '@Module'. The latter form means that the lens from the transform marked for autoloading in MODULE should be used. The 'incl' and 'excl' grandchildren of /augeas/load indicate which files to transform. Their value are used as glob patterns. Any file that matches at least one 'incl' pattern and no 'excl' pattern is transformed. The order of 'incl' and 'excl' entries is irrelevant. When AUG_INIT is first called, it populates /augeas/load with the transforms marked for autoloading in all the modules it finds. Before loading any files, AUG_LOAD will remove everything underneath /augeas/files and /files, regardless of whether any entries have been modified or not.s*The Augeas object has already been closed!isaug_load() failed!N(R!R"RRtaug_load(R$R1((s*/usr/lib/python2.7/site-packages/augeas.pytloads   cCs|jddS(sClear all transforms beneath /augeas/load. If load() is called right after this, there will be no files beneath /files.s/augeas/load/*N(RU(R$((s*/usr/lib/python2.7/site-packages/augeas.pytclear_transforms scCs|r+ddl}|jdtddnt|trF|g}nt|tra|g}nx1tt|D]}|j|||tqtWx1tt|D]}|j|||t qWdS(sAdd a transform beneath /augeas/load. lens: the (file)name of the lens to use incl: one or more glob patterns for the files to transform name: deprecated parameter excl: zero or more glob patterns of files to exclude from transforming iNs'name is now deprecated in this functiont stackleveli( twarningstwarntDeprecationWarningRRRXtlent transformtFalsetTrue(R$R>tinclRFtexclRsR_((s*/usr/lib/python2.7/site-packages/augeas.pyt add_transforms     cCst|tstdnt|ts<tdnt|tsZtdn|jsrtdntjj|jt |t ||}|dkrtdndS(s$Add a transform for 'file' using 'lens'. 'excl' specifies if this the file is to be included (False) or excluded (True) from the 'lens'. The 'lens' may be a module name or a full lens name. If a module name is given, then lns will be the lens assumed. slens MUST be a string!sfile MUST be a string!sexcl MUST be a boolean!s*The Augeas object has already been closed!isUnable to add transform!N( RRRtboolR!R"RRt aug_transformR(R$R>tfileR{R1((s*/usr/lib/python2.7/site-packages/augeas.pyRw&s * cCs-|js dStjj|jd|_dS(sClose this Augeas instance and free any storage associated with it. After this call, this Augeas instance is invalid and can not be used for any more operations.N(R!RRt aug_closeR(R$((s*/usr/lib/python2.7/site-packages/augeas.pyR);s iiiiii i@iN((+t__name__t __module__t__doc__RRR R#R trestypetNONEt SAVE_BACKUPt SAVE_NEWFILEt TYPE_CHECKt NO_STDINCt SAVE_NOOPtNO_LOADtNO_MODL_AUTOLOADt ENABLE_SPANRR(R*R2R4R7R<R@RDRHRJRNRPRyRSRUR`RkRnRpRqR|RxRwR)(((s*/usr/lib/python2.7/site-packages/augeas.pyRNsD               1 "   RcBseZdZdZRS(s2Compat class, obsolete. Use class Augeas directly.cOs?ddl}|jdtddtt|j||dS(Nisuse Augeas instead of augeasRri(RsRtRutsuperRR((R$tptkRs((s*/usr/lib/python2.7/site-packages/augeas.pyR(Os (RRRR((((s*/usr/lib/python2.7/site-packages/augeas.pyRLs(Rt __author__t __credits__ttypesR t ctypes.utiltsysRt_pyvert functoolsRtPY3RR8Rt basestringRRRtobjectRR(((s*/usr/lib/python2.7/site-packages/augeas.pyt s&