Viewing file: pyalchemist_python.py (2.44 KB) -rwxr-xr-x Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
#!/usr/bin/python ## Copyright (C) 2000 Red Hat, Inc. ## Copyright (C) 2000 Crutcher Dunnavant <crutcher@redhat.com>,
## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2 of the License, or ## (at your option) any later version.
## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details.
## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
from pyalchemist import *
class SubspaceEditor: __dynamic_ctx = None __dynamic_box = None __static_ctx = None
def __init__( self, namespace = None, subspace = "config", namespace_cfg = None):
self.subspace = subspace
if (namespace != None): # extract the subspace_cfg from the system config swb = readNspCtx(namespace = namespace)
self.namespace_cfg = getNspCfg( context = swb, namespace = namespace)
elif (namespace_cfg != None): if (type(namespace_cfg) == AdmListType): self.namespace_cfg = namespace_cfg else: raise ValueError, \ "namespace_cfg not an AdmListType element" else: raise TypeError, \ "expected namespace or namespace_cfg, found neither"
self.subspace_cfg = getSubspCfg(namespace_cfg = self.namespace_cfg, subspace = self.subspace)
def editReadBox(self, editbox): # we find out how many boxes are before the one we want to edit editpos = \ self.subspace_cfg["/read_policy/read_set"][editbox].pos
if editpos != 0: # Construct the preview context, that we wont edit # this context represents the tree as it will be when # the box we are editing merges into it, so that we # can be a bit clever about how we edit, if we want to
# We do NOT make this call if editpos == 0, # because depth = 0 means 'all' s_ctx = readNsp(namespace_cfg = self.namespace_cfg, subspace = self.subspace, depth = editpos) else: s_ctx = None
# set up the box interface d_box = getBox( subspace_cfg = self.subspace_cfg, box_name = editbox)
d_ctx = d_box.read()
return {"static_context" : s_ctx, "dynamic_box" : d_box, "dynamic_context" : d_ctx}
|