[docs]classAugeas(augeas.Augeas):""" A smarter and faster wrapper around :class:`augeas.Augeas`.augeas For faster startup, no modules and lenses are preloaded:: aug = Augeas(modules=[{ 'name': 'Interfaces', # module name 'lens': 'Interfaces.lns', # lens name 'incl': [ # included files list self.path, self.path + '.d/*', ] }]) Don't forget to call :func:`.load()` afterwards. """def__init__(self,modules=[],loadpath=None):augeas.Augeas.__init__(self,loadpath=loadpath,flags=augeas.Augeas.NO_MODL_AUTOLOAD|augeas.Augeas.NO_LOAD)formoduleinmodules:path=f'/augeas/load/{module["name"]}'self.set(f'{path}/lens',module['lens'])forindex,inclinenumerate(module['incl']):self.set(f'{path}/incl[{index+1}]',incl)def__enc(self,v):returnv
[docs]defsetd(self,path,value,default=None):""" Sets `path` to `value`, or removes `path` if `value == default` """ifvalueisnotNone:self.set(path,value)ifvalue==default:self.remove(path)
[docs]defraise_error(self):""" Extracts error information from Augeas tree and raises :exc:`AugeasError` """raiseAugeasError(self)
[docs]defdump(self,path):""" Dumps contents under `path` to stdout. """forspinself.match(path+'/*'):print(sp,'=',self.get(sp))
[docs]@interfaceclassAugeasEndpoint():""" Implement this to provide Augeas trees to the frontend. """id=Nonedef__init__(self,context):self.context=context
[docs]defget_augeas(self):""" Should return a ready-to-use :class:`Augeas` """raiseNotImplementedError
[docs]defget_root_path(self):""" Should return an Augeas path of the root node to be provided to the frontend. """raiseNotImplementedError