Beispiel #1
0
class CfgSource(object):
    def __init__(self, filesystem, path):
        self.filesystem = filesystem
        self.path = path
        self.targetpath = ()
        self.tree = CfgTree(filesystem, None, None)
        # self.subtree_handlers set by ..._finalize_data()

    def parse_enter_block(self, key, args):
        if key == 'targetpath':
            path = self.filesystem.relative_path_from_string(args)
            if self.targetpath is not ():
                raise InvalidDataError(
                    'Tried to set targetpath twice for the same source: ' +
                    str(self.targetpath) + ' and ' + str(path))
            self.targetpath = path
            return True
        if key in ('path', 'paths', 'path-glob', 'path-globs'):
            return self.tree.parse_pathmatch(key, args)

    def parse_exit_block(self, key, args, item):
        pass

    def config_is_fully_parsed_so_finalize_data(self):
        self.subtree_handlers = CfgSubtree(None, None)
        self.subtree_handlers.build_children_from_cfgtree(self.tree)
        self.tree = None

    def get_handler_for_path(self, path):
        handler = self.subtree_handlers.get_handler_for_path(path)
        if handler is None:
            return 'dynamic'
        return handler
def add_backup_handlers(tree, ignore=None, dynamic=None, static=None):
    root = CfgSubtree(None, None)
    for paths, handler in (
            (ignore, 'ignore'), (dynamic, 'dynamic'), (static, 'static') ):
        if paths is None:
            continue
        for path in paths:
            root._add_child_path('plain', path, handler=handler)
    tree.set_backup_handlers(root)
def make_cfgsubtree(spec):
    root = CfgSubtree(None, None)
    for item in spec:
        root._add_child_path(item[0], item[1], handler=item[2])
    return root
Beispiel #4
0
 def config_is_fully_parsed_so_finalize_data(self):
     self.subtree_handlers = CfgSubtree(None, None)
     self.subtree_handlers.build_children_from_cfgtree(self.tree)
     self.tree = None