Beispiel #1
0
    def __init__(self,
                 servers=None,
                 paths=None,
                 orb=None,
                 filter=[],
                 dynamic=False,
                 *args,
                 **kwargs):
        '''Constructor.

        @param servers A list of servers to parse into the tree.
        @param paths A list of paths from which to get servers to parse
                     into the tree.
        @param orb If not None, the specified ORB will be used. If None,
                   the tree object will create its own ORB.
        @param filter A list of paths (each a list of strings).
                      If not empty, then only objects in the paths will
                      be parsed, to increase speed. If the tail of a
                      path is a directory, that entire directory will be
                      parsed. Directories that are not the tail will
                      only have the next entry in the path parsed.
        @param dynamic Use observers to keep the tree up-to-date. For example,
                       when a component changes state, an observer can notify
                       RTCTree so that the corresponding object in the tree can
                       be updated. Currently this only affects components.
        @raises NonRootPathError

        '''
        super(RTCTree, self).__init__()
        self._root = TreeNode('/', None, dynamic=dynamic)
        self._create_orb(orb)
        self._dynamic = dynamic
        if servers:
            self._parse_name_servers(servers, filter=filter, dynamic=dynamic)
        if paths:
            if type(paths[0]) == str:
                if paths[0][0] != '/':
                    raise exceptions.NonRootPathError(paths[0])
                if len(paths) > 1:
                    self.add_name_server(paths[1],
                                         filter=filter,
                                         dynamic=dynamic)
            else:
                for p in paths:
                    if p[0] != '/':
                        raise exceptions.NonRootPathError(p)
                    if len(p) > 1:
                        self.add_name_server(p[1],
                                             filter=filter,
                                             dynamic=dynamic)
            self.load_servers_from_env(filter=filter, dynamic=dynamic)
        if not servers and not paths:
            self.load_servers_from_env(filter=filter, dynamic=dynamic)