예제 #1
0
파일: parser.py 프로젝트: presto53/radist
    def __init__(self, URI=None, config=None):
        """URI is the link to config.

        config is string represent of config.

        For tests you can use something like
        In [6]: r = radist.RadistConf(config='''/R/qwe
          primary=index1.rambler.ru:/:/tmp'''
        )

        """
        RadistNode.__init__(self, 'R')
        content = adv_get_content(URI, config)
        node = None
        for line in get_line_iterator(content):
            if line.startswith('/R'):
                path = line.split('/')[2:]
                if len(path) > 0:
                    node = self
                    while len(path) > 0:
                        xdir = path.pop(0)
                        nnode = getattr(node, make_child_name(xdir), None)
                        if nnode == None:
                            nnode = RadistNode(xdir)
                            try:
                                node.add_child(nnode)
                            except RadistError, err:
                                raise RadistConfError(str(err))
                        elif len(path) == 0 and nnode.has_attrs:
                            raise RadistConfError('dublicated path: %s' % line)
                        node = nnode
                else:
                    raise RadistConfError("don't know how works with R-path /R")
예제 #2
0
파일: ix.py 프로젝트: presto53/radist
    def __init__(self, URI=None, config=None):
        self.clear_special_roles()
        self.directive_count = 0
        self.directories = {}

        RadistNode.__init__(self, 'ix')
        content = adv_get_content(URI, config)

        clusters = {}
        for line, special in get_line_iterator(content, directives):
            if is_special_role(special):
                self.directive_count += 1
                self.add_special_role(parse_special_role_directive(special))
            elif is_directory(special):
                self.update_directories(special)
                self.directive_count += 1

            x = self.__get_roles(line)
            if x is None:
                # server without roles, skip one
                continue
            server, roles = x
#            print "start dancing..."
            for role, attrs in roles:
                special = self.get_special(role, attrs)
                for path, node in special.get_extra_nodes():
                    if self.get_default(path, None) is None:
                        self.add_node_to_path(path, node)

                for path, number in special.get_roles():
                    if type(number) != int:
                        name = number
                    else:
                        if number == -1:
                            if path not in clusters:
                                clusters[path] = -1
                            clusters[path] += 1
                            number = clusters[path]
                        name = "%03d" % number
                    node = RadistNode(name)
                    if self.directories_for(path, name):
                        node.add_attr('primary', RadistPrimary(self.directories_for(path, name)))
                    else:
                        node.add_attr('primary', \
                            RadistPrimary('%(server)s:/spool/_R_/%(path)s:/spool/_R_/%(path)s/tmp-radist' % \
                                {'server': server, 'path': path.split('/')[-1]}))
                    self.add_node_to_path('/'.join([path, node.name]), node)