示例#1
0
 def _init_caches(self):
     self._lib_cache = LibraryCache(self._settings, self.update,
                                    self._library_manager)
     self._resource_factory = ResourceFactory(self._settings)
     self._retriever = DatafileRetriever(self._lib_cache,
                                         self._resource_factory)
     self._context_factory = _RetrieverContextFactory()
示例#2
0
文件: namespace.py 项目: pskpg86/RIDE
 def _init_caches(self):
     self._lib_cache = LibraryCache(
         self._settings, self.update, self._library_manager)
     self._resource_factory = ResourceFactory(self._settings)
     self._retriever = DatafileRetriever(self._lib_cache,
                                         self._resource_factory)
     self._context_factory = _RetrieverContextFactory()
示例#3
0
文件: namespace.py 项目: pskpg86/RIDE
class Namespace(object):

    def __init__(self, settings):
        self._settings = settings
        self._library_manager = None
        self._content_assist_hooks = []
        self._update_listeners = set()
        self._init_caches()
        self._set_pythonpath()
        PUBLISHER.subscribe(self._setting_changed, RideSettingsChanged)

    def _init_caches(self):
        self._lib_cache = LibraryCache(
            self._settings, self.update, self._library_manager)
        self._resource_factory = ResourceFactory(self._settings)
        self._retriever = DatafileRetriever(self._lib_cache,
                                            self._resource_factory)
        self._context_factory = _RetrieverContextFactory()

    def _set_pythonpath(self):
        """Add user configured paths to PYTHONAPATH.

        In addition, if `use installaed robot libraries` setting is `True`, and
        a Robot Framework installation is found, remove bundled RF libraries
        from PYTHONAPATH and create spec files for the installed RF's standard
        libraries.
        """
        if self._settings['use installed robot libraries']:
            rf_version = robotlibraryloader.find_installed_robot_libraries(
                self._settings.get('installed robot version', None))
            if rf_version is not None:
                if BUNDLED_LIBRARIES_PATH in sys.path:
                    sys.path.remove(BUNDLED_LIBRARIES_PATH)
                    sys.path.append(REMOTE_LIB_PATH)
                self._settings.set('installed robot version', rf_version)
        elif BUNDLED_LIBRARIES_PATH not in sys.path:
            sys.path.insert(0, BUNDLED_LIBRARIES_PATH)
        for path in self._settings.get('pythonpath', []):
            if path not in sys.path:
                normalized = path.replace('/', os.sep)
                sys.path.insert(0, normalized)
                SYSLOG("Inserted '{0}' to sys.path.".format(normalized))

    def _setting_changed(self, message):
        section, setting = message.keys
        if section == '' and setting == 'pythonpath':
            for p in set(message.old).difference(message.new):
                if p in sys.path:
                    sys.path.remove(p)
            self._set_pythonpath()

    def set_library_manager(self, library_manager):
        self._library_manager = library_manager
        self._lib_cache.set_library_manager(library_manager)

    def update(self, *args):
        self._retriever.expire_cache()
        self._context_factory = _RetrieverContextFactory()
        for listener in self._update_listeners:
            listener()

    def resource_filename_changed(self, old_name, new_name):
        self._resource_factory.resource_filename_changed(old_name, new_name)

    def reset_resource_and_library_cache(self):
        self._init_caches()

    def register_update_listener(self, listener):
        self._update_listeners.add(listener)

    def unregister_update_listener(self, listener):
        if listener in self._update_listeners:
            self._update_listeners.remove(listener)

    def clear_update_listeners(self):
        self._update_listeners.clear()

    def register_content_assist_hook(self, hook):
        self._content_assist_hooks.append(hook)

    def get_all_keywords(self, testsuites):
        kws = set()
        kws.update(self._get_default_keywords())
        kws.update(self._retriever.get_keywords_from_several(testsuites))
        return list(kws)

    def _get_default_keywords(self):
        return self._lib_cache.get_default_keywords()

    def get_suggestions_for(self, controller, start):
        datafile = controller.datafile
        ctx = self._context_factory.ctx_for_controller(controller)
        sugs = set()
        sugs.update(self._get_suggestions_from_hooks(datafile, start))
        if self._blank(start) or not self._looks_like_variable(start):
            sugs.update(self._variable_suggestions(controller, start, ctx))
            sugs.update(self._keyword_suggestions(datafile, start, ctx))
        else:
            sugs.update(self._variable_suggestions(controller, start, ctx))
        sugs_list = list(sugs)
        sugs_list.sort()
        return sugs_list

    def _get_suggestions_from_hooks(self, datafile, start):
        sugs = []
        for hook in self._content_assist_hooks:
            sugs.extend(hook(datafile, start))
        return sugs

    def get_all_cached_library_names(self):
        return self._retriever.get_all_cached_library_names()

    def _blank(self, start):
        return start == ''

    def _looks_like_variable(self, start):
        return len(start) == 1 and start[0] in ['$', '@', '&'] \
            or (len(start) >= 2 and start[:2] in ['${', '@{', '&{'])

    def _variable_suggestions(self, controller, start, ctx):
        self._add_kw_arg_vars(controller, ctx.vars)
        variables = self._retriever.get_variables_from(
            controller.datafile, ctx)
        sugs = (v for v in variables if v.name_matches(start))
        return sugs

    def _add_kw_arg_vars(self, controller, variables):
        for name, value in controller.get_local_variables().iteritems():
            variables.set_argument(name, value)

    def _keyword_suggestions(self, datafile, start, ctx):
        start_normalized = utils.normalize(start)
        return (sug for sug in chain(
            self._get_default_keywords(),
            self._retriever.get_keywords_from(datafile, ctx))
                if sug.name_begins_with(start_normalized) or
                sug.longname_begins_with(start_normalized))

    def get_resources(self, datafile):
        return self._retriever.get_resources_from(datafile)

    def get_resource(self, path, directory='', report_status=True):
        return self._resource_factory.get_resource(
            directory, path,
            report_status=report_status)

    def find_resource_with_import(self, imp):
        ctx = self._context_factory.ctx_for_datafile(imp.parent.parent)
        return self._resource_factory.get_resource_from_import(imp, ctx)

    def new_resource(self, path, directory=''):
        return self._resource_factory.new_resource(directory, path)

    def find_user_keyword(self, datafile, kw_name):
        kw = self.find_keyword(datafile, kw_name)
        return kw if isinstance(kw, _UserKeywordInfo) else None

    def is_user_keyword(self, datafile, kw_name):
        return bool(self.find_user_keyword(datafile, kw_name))

    def find_library_keyword(self, datafile, kw_name):
        kw = self.find_keyword(datafile, kw_name)
        return kw if kw and kw.is_library_keyword() else None

    def is_library_import_ok(self, datafile, imp):
        return self._retriever.is_library_import_ok(
            datafile, imp, self._context_factory.ctx_for_datafile(datafile))

    def is_variables_import_ok(self, datafile, imp):
        return self._retriever.is_variables_import_ok(
            datafile, imp, self._context_factory.ctx_for_datafile(datafile))

    def find_keyword(self, datafile, kw_name):
        if not kw_name:
            return None
        kwds = self._retriever.get_keywords_cached(datafile,
                                                   self._context_factory)
        return kwds.get(kw_name)

    def is_library_keyword(self, datafile, kw_name):
        return bool(self.find_library_keyword(datafile, kw_name))

    def keyword_details(self, datafile, name):
        kw = self.find_keyword(datafile, name)
        return kw.details if kw else None
示例#4
0
class Namespace(object):

    def __init__(self, settings=None):
        self._settings = settings
        self._init_caches()
        self._content_assist_hooks = []
        self._update_listeners = []

    def _init_caches(self):
        self._lib_cache = LibraryCache(self._settings)
        self._resource_factory = ResourceFactory(self._settings)
        self._retriever = DatafileRetriever(self._lib_cache, self._resource_factory)
        self._context_factory = _RetrieverContextFactory()

    def update(self):
        self._retriever.expire_cache()
        self._context_factory = _RetrieverContextFactory()
        for listener in self._update_listeners:
            listener()

    def resource_filename_changed(self, old_name, new_name):
        self._resource_factory.resource_filename_changed(old_name, new_name)

    def reset_resource_and_library_cache(self):
        self._init_caches()

    def register_update_listener(self, listener):
        self._update_listeners.append(listener)

    def unregister_update_listener(self, listener):
        self._update_listeners.remove(listener)

    def clear_update_listeners(self):
        self._update_listeners = []

    def register_content_assist_hook(self, hook):
        self._content_assist_hooks.append(hook)

    def get_all_keywords(self, testsuites):
        kws = set()
        kws.update(self._get_default_keywords())
        kws.update(self._retriever.get_keywords_from_several(testsuites))
        return list(kws)

    def _get_default_keywords(self):
        return self._lib_cache.get_default_keywords()

    def get_suggestions_for(self, controller, start):
        datafile = controller.datafile
        ctx = self._context_factory.ctx_for_controller(controller)
        sugs = set()
        sugs.update(self._get_suggestions_from_hooks(datafile, start))
        if self._blank(start) or self._looks_like_variable(start):
            sugs.update(self._variable_suggestions(controller, start, ctx))
        if self._blank(start) or not self._looks_like_variable(start):
            sugs.update(self._keyword_suggestions(datafile, start, ctx))
        sugs_list = list(sugs)
        sugs_list.sort()
        return sugs_list

    def _get_suggestions_from_hooks(self, datafile, start):
        sugs = []
        for hook in self._content_assist_hooks:
            sugs.extend(hook(datafile, start))
        return sugs

    def _blank(self, start):
        return start == ''

    def _looks_like_variable(self, start):
        return (len(start) == 1 and start.startswith('$') or start.startswith('@')) \
            or (len(start) >= 2 and start.startswith('${') or start.startswith('@{'))

    def _variable_suggestions(self, controller, start, ctx):
        datafile = controller.datafile
        start_normalized = normalize(start)
        self._add_kw_arg_vars(controller, ctx.vars)
        vars = self._retriever.get_variables_from(datafile, ctx)
        return (v for v in vars
                if normalize(v.name).startswith(start_normalized))

    def _add_kw_arg_vars(self, controller, vars):
        for name, value in controller.get_local_variables().iteritems():
            vars.set_argument(name, value)

    def _keyword_suggestions(self, datafile, start, ctx):
        start_normalized = normalize(start)
        return (sug for sug in chain(self._get_default_keywords(),
                                           self._retriever.get_keywords_from(datafile, ctx))
                      if sug.name_begins_with(start_normalized) or
                         sug.longname_begins_with(start_normalized))

    def get_resources(self, datafile):
        return self._retriever.get_resources_from(datafile)

    def get_resource(self, path, directory=''):
        return self._resource_factory.get_resource(directory, path)

    def find_resource_with_import(self, imp):
        ctx = self._context_factory.ctx_for_datafile(imp.parent.parent)
        return self._resource_factory.get_resource_from_import(imp, ctx)

    def new_resource(self, path, directory=''):
        return self._resource_factory.new_resource(directory, path)

    def find_user_keyword(self, datafile, kw_name):
        kw = self.find_keyword(datafile, kw_name)
        return kw if isinstance(kw, _UserKeywordInfo) else None

    def is_user_keyword(self, datafile, kw_name):
        return bool(self.find_user_keyword(datafile, kw_name))

    def find_library_keyword(self, datafile, kw_name):
        kw = self.find_keyword(datafile, kw_name)
        return kw if kw and kw.is_library_keyword() else None

    def find_keyword(self, datafile, kw_name):
        if not kw_name:
            return None
        kwds = self._retriever.get_keywords_cached(datafile,
                                                   self._context_factory)
        return kwds.get(kw_name)

    def is_library_keyword(self, datafile, kw_name):
        return bool(self.find_library_keyword(datafile, kw_name))

    def keyword_details(self, datafile, name):
        kw = self.find_keyword(datafile, name)
        return kw.details if kw else None
示例#5
0
 def _init_caches(self):
     self._lib_cache = LibraryCache()
     self._resource_factory = ResourceFactory()
     self._retriever = DatafileRetriever(self._lib_cache, self._resource_factory)
     self._context_factory = _RetrieverContextFactory()
示例#6
0
class Namespace(object):
    def __init__(self, settings):
        self._settings = settings
        self._library_manager = None
        self._init_caches()
        self._content_assist_hooks = []
        self._update_listeners = set()

    def _init_caches(self):
        self._lib_cache = LibraryCache(self._settings, self.update,
                                       self._library_manager)
        self._resource_factory = ResourceFactory(self._settings)
        self._retriever = DatafileRetriever(self._lib_cache,
                                            self._resource_factory)
        self._context_factory = _RetrieverContextFactory()

    def set_library_manager(self, library_manager):
        self._library_manager = library_manager
        self._lib_cache.set_library_manager(library_manager)

    def update(self, *args):
        self._retriever.expire_cache()
        self._context_factory = _RetrieverContextFactory()
        for listener in self._update_listeners:
            listener()

    def resource_filename_changed(self, old_name, new_name):
        self._resource_factory.resource_filename_changed(old_name, new_name)

    def reset_resource_and_library_cache(self):
        self._init_caches()

    def register_update_listener(self, listener):
        self._update_listeners.add(listener)

    def unregister_update_listener(self, listener):
        if listener in self._update_listeners:
            self._update_listeners.remove(listener)

    def clear_update_listeners(self):
        self._update_listeners.clear()

    def register_content_assist_hook(self, hook):
        self._content_assist_hooks.append(hook)

    def get_all_keywords(self, testsuites):
        kws = set()
        kws.update(self._get_default_keywords())
        kws.update(self._retriever.get_keywords_from_several(testsuites))
        return list(kws)

    def _get_default_keywords(self):
        return self._lib_cache.get_default_keywords()

    def get_suggestions_for(self, controller, start):
        datafile = controller.datafile
        ctx = self._context_factory.ctx_for_controller(controller)
        sugs = set()
        sugs.update(self._get_suggestions_from_hooks(datafile, start))
        if self._blank(start) or self._looks_like_variable(start):
            sugs.update(self._variable_suggestions(controller, start, ctx))
        if self._blank(start) or not self._looks_like_variable(start):
            sugs.update(self._keyword_suggestions(datafile, start, ctx))
        sugs_list = list(sugs)
        sugs_list.sort()
        return sugs_list

    def _get_suggestions_from_hooks(self, datafile, start):
        sugs = []
        for hook in self._content_assist_hooks:
            sugs.extend(hook(datafile, start))
        return sugs

    def get_all_cached_library_names(self):
        return self._retriever.get_all_cached_library_names()

    def _blank(self, start):
        return start == ''

    def _looks_like_variable(self, start):
        return (len(start) == 1 and start.startswith('$') or start.startswith('@')) \
            or (len(start) >= 2 and start.startswith('${') or start.startswith('@{'))

    def _variable_suggestions(self, controller, start, ctx):
        datafile = controller.datafile
        start_normalized = normalize(start)
        self._add_kw_arg_vars(controller, ctx.vars)
        vars = self._retriever.get_variables_from(datafile, ctx)
        return (v for v in vars
                if normalize(v.name).startswith(start_normalized))

    def _add_kw_arg_vars(self, controller, vars):
        for name, value in controller.get_local_variables().iteritems():
            vars.set_argument(name, value)

    def _keyword_suggestions(self, datafile, start, ctx):
        start_normalized = normalize(start)
        return (
            sug
            for sug in chain(self._get_default_keywords(),
                             self._retriever.get_keywords_from(datafile, ctx))
            if sug.name_begins_with(start_normalized)
            or sug.longname_begins_with(start_normalized))

    def get_resources(self, datafile):
        return self._retriever.get_resources_from(datafile)

    def get_resource(self, path, directory='', report_status=True):
        return self._resource_factory.get_resource(directory,
                                                   path,
                                                   report_status=report_status)

    def find_resource_with_import(self, imp):
        ctx = self._context_factory.ctx_for_datafile(imp.parent.parent)
        return self._resource_factory.get_resource_from_import(imp, ctx)

    def new_resource(self, path, directory=''):
        return self._resource_factory.new_resource(directory, path)

    def find_user_keyword(self, datafile, kw_name):
        kw = self.find_keyword(datafile, kw_name)
        return kw if isinstance(kw, _UserKeywordInfo) else None

    def is_user_keyword(self, datafile, kw_name):
        return bool(self.find_user_keyword(datafile, kw_name))

    def find_library_keyword(self, datafile, kw_name):
        kw = self.find_keyword(datafile, kw_name)
        return kw if kw and kw.is_library_keyword() else None

    def is_library_import_ok(self, datafile, imp):
        return self._retriever.is_library_import_ok(
            datafile, imp, self._context_factory.ctx_for_datafile(datafile))

    def is_variables_import_ok(self, datafile, imp):
        return self._retriever.is_variables_import_ok(
            datafile, imp, self._context_factory.ctx_for_datafile(datafile))

    def find_keyword(self, datafile, kw_name):
        if not kw_name:
            return None
        kwds = self._retriever.get_keywords_cached(datafile,
                                                   self._context_factory)
        return kwds.get(kw_name)

    def is_library_keyword(self, datafile, kw_name):
        return bool(self.find_library_keyword(datafile, kw_name))

    def keyword_details(self, datafile, name):
        kw = self.find_keyword(datafile, name)
        return kw.details if kw else None
示例#7
0
class Namespace(object):

    def __init__(self, settings):
        self._settings = settings
        self._library_manager = None
        self._content_assist_hooks = []
        self._update_listeners = set()
        self._init_caches()
        self._set_pythonpath()
        PUBLISHER.subscribe(self._setting_changed, RideSettingsChanged)

    def _init_caches(self):
        self._lib_cache = LibraryCache(
            self._settings, self.update, self._library_manager)
        self._resource_factory = ResourceFactory(self._settings)
        self._retriever = DatafileRetriever(self._lib_cache, self._resource_factory)
        self._context_factory = _RetrieverContextFactory()

    def _set_pythonpath(self):
        values = self._settings.get('pythonpath', [])
        for path in values:
            if path not in sys.path:
                sys.path.insert(0, path.replace('/', os.sep))

    def _setting_changed(self, message):
        section, setting = message.keys
        if section == '' and setting == 'pythonpath':
            for p in set(message.old).difference(message.new):
                if p in sys.path:
                    sys.path.remove(p)
            self._set_pythonpath()

    def set_library_manager(self, library_manager):
        self._library_manager = library_manager
        self._lib_cache.set_library_manager(library_manager)

    def update(self, *args):
        self._retriever.expire_cache()
        self._context_factory = _RetrieverContextFactory()
        for listener in self._update_listeners:
            listener()

    def resource_filename_changed(self, old_name, new_name):
        self._resource_factory.resource_filename_changed(old_name, new_name)

    def reset_resource_and_library_cache(self):
        self._init_caches()

    def register_update_listener(self, listener):
        self._update_listeners.add(listener)

    def unregister_update_listener(self, listener):
        if listener in self._update_listeners:
            self._update_listeners.remove(listener)

    def clear_update_listeners(self):
        self._update_listeners.clear()

    def register_content_assist_hook(self, hook):
        self._content_assist_hooks.append(hook)

    def get_all_keywords(self, testsuites):
        kws = set()
        kws.update(self._get_default_keywords())
        kws.update(self._retriever.get_keywords_from_several(testsuites))
        return list(kws)

    def _get_default_keywords(self):
        return self._lib_cache.get_default_keywords()

    def get_suggestions_for(self, controller, start):
        datafile = controller.datafile
        ctx = self._context_factory.ctx_for_controller(controller)
        sugs = set()
        sugs.update(self._get_suggestions_from_hooks(datafile, start))
        if self._blank(start) or self._looks_like_variable(start):
            sugs.update(self._variable_suggestions(controller, start, ctx))
        else:
            sugs.update(self._variable_suggestions(controller, '${'+start, ctx))
            sugs.update(self._variable_suggestions(controller, '@{'+start, ctx))
        if self._blank(start) or not self._looks_like_variable(start):
            sugs.update(self._keyword_suggestions(datafile, start, ctx))
        sugs_list = list(sugs)
        sugs_list.sort()
        return sugs_list

    def _get_suggestions_from_hooks(self, datafile, start):
        sugs = []
        for hook in self._content_assist_hooks:
            sugs.extend(hook(datafile, start))
        return sugs

    def get_all_cached_library_names(self):
        return self._retriever.get_all_cached_library_names()

    def _blank(self, start):
        return start == ''

    def _looks_like_variable(self, start):
        return (len(start) == 1 and start.startswith('$') or
                start.startswith('@')) \
            or (len(start) >= 2 and start.startswith('${') or
                start.startswith('@{'))

    def _variable_suggestions(self, controller, start, ctx):
        datafile = controller.datafile
        start_normalized = utils.normalize(start)
        self._add_kw_arg_vars(controller, ctx.vars)
        variables = self._retriever.get_variables_from(datafile, ctx)
        return (v for v in variables
                if utils.normalize(v.name).startswith(start_normalized))

    def _add_kw_arg_vars(self, controller, variables):
        for name, value in controller.get_local_variables().iteritems():
            variables.set_argument(name, value)

    def _keyword_suggestions(self, datafile, start, ctx):
        start_normalized = utils.normalize(start)
        return (sug for sug in chain(
            self._get_default_keywords(),
            self._retriever.get_keywords_from(datafile, ctx))
                if sug.name_begins_with(start_normalized) or
                sug.longname_begins_with(start_normalized))

    def get_resources(self, datafile):
        return self._retriever.get_resources_from(datafile)

    def get_resource(self, path, directory='', report_status=True):
        return self._resource_factory.get_resource(
            directory, path, report_status=report_status)

    def find_resource_with_import(self, imp):
        ctx = self._context_factory.ctx_for_datafile(imp.parent.parent)
        return self._resource_factory.get_resource_from_import(imp, ctx)

    def new_resource(self, path, directory=''):
        return self._resource_factory.new_resource(directory, path)

    def find_user_keyword(self, datafile, kw_name):
        kw = self.find_keyword(datafile, kw_name)
        return kw if isinstance(kw, _UserKeywordInfo) else None

    def is_user_keyword(self, datafile, kw_name):
        return bool(self.find_user_keyword(datafile, kw_name))

    def find_library_keyword(self, datafile, kw_name):
        kw = self.find_keyword(datafile, kw_name)
        return kw if kw and kw.is_library_keyword() else None

    def is_library_import_ok(self, datafile, imp):
        return self._retriever.is_library_import_ok(
            datafile, imp, self._context_factory.ctx_for_datafile(datafile))

    def is_variables_import_ok(self, datafile, imp):
        return self._retriever.is_variables_import_ok(
            datafile, imp, self._context_factory.ctx_for_datafile(datafile))

    def find_keyword(self, datafile, kw_name):
        if not kw_name:
            return None
        kwds = self._retriever.get_keywords_cached(datafile,
                                                   self._context_factory)
        return kwds.get(kw_name)

    def is_library_keyword(self, datafile, kw_name):
        return bool(self.find_library_keyword(datafile, kw_name))

    def keyword_details(self, datafile, name):
        kw = self.find_keyword(datafile, name)
        return kw.details if kw else None
示例#8
0
class Namespace(object):

    def __init__(self, settings):
        self._settings = settings
        self._library_manager = None
        self._content_assist_hooks = []
        self._update_listeners = set()
        self._init_caches()
        self._set_pythonpath()
        PUBLISHER.subscribe(self._setting_changed, RideSettingsChanged)

    def _init_caches(self):
        self._lib_cache = LibraryCache(
            self._settings, self.update, self._library_manager)
        self._resource_factory = ResourceFactory(self._settings)
        self._retriever = DatafileRetriever(self._lib_cache,
                                            self._resource_factory)
        self._context_factory = _RetrieverContextFactory()

    def _set_pythonpath(self):
        """Add user configured paths to PYTHONAPATH.

        In addition, if `use installaed robot libraries` setting is `True`, and
        a Robot Framework installation is found, remove bundled RF libraries
        from PYTHONAPATH and create spec files for the installed RF's standard
        libraries.
        """
        if self._settings['use installed robot libraries']:
            rf_version = robotlibraryloader.find_installed_robot_libraries(
                self._settings.get('installed robot version', None))
            if rf_version is not None:
                if BUNDLED_LIBRARIES_PATH in sys.path:
                    sys.path.remove(BUNDLED_LIBRARIES_PATH)
                    sys.path.append(REMOTE_LIB_PATH)
                self._settings.set('installed robot version', rf_version)
        for path in self._settings.get('pythonpath', []):
            if path not in sys.path:
                normalized = path.replace('/', os.sep)
                sys.path.insert(0, normalized)
                SYSLOG("Inserted '{0}' to sys.path.".format(normalized))

    def _setting_changed(self, message):
        section, setting = message.keys
        if section == '' and setting == 'pythonpath':
            for p in set(message.old).difference(message.new):
                if p in sys.path:
                    sys.path.remove(p)
            self._set_pythonpath()

    def set_library_manager(self, library_manager):
        self._library_manager = library_manager
        self._lib_cache.set_library_manager(library_manager)

    def update(self, *args):
        self._retriever.expire_cache()
        self._context_factory = _RetrieverContextFactory()
        for listener in self._update_listeners:
            listener()

    def resource_filename_changed(self, old_name, new_name):
        self._resource_factory.resource_filename_changed(old_name, new_name)

    def reset_resource_and_library_cache(self):
        self._init_caches()

    def register_update_listener(self, listener):
        self._update_listeners.add(listener)

    def unregister_update_listener(self, listener):
        if listener in self._update_listeners:
            self._update_listeners.remove(listener)

    def clear_update_listeners(self):
        self._update_listeners.clear()

    def register_content_assist_hook(self, hook):
        self._content_assist_hooks.append(hook)

    def get_all_keywords(self, testsuites):
        kws = set()
        kws.update(self._get_default_keywords())
        kws.update(self._retriever.get_keywords_from_several(testsuites))
        return list(kws)

    def _get_default_keywords(self):
        return self._lib_cache.get_default_keywords()

    def get_suggestions_for(self, controller, start):
        datafile = controller.datafile
        ctx = self._context_factory.ctx_for_controller(controller)
        sugs = set()
        sugs.update(self._get_suggestions_from_hooks(datafile, start))
        if self._blank(start) or self._looks_like_variable(start):
            sugs.update(self._variable_suggestions(controller, start, ctx))
        else:
            sugs.update(self._variable_suggestions(controller, '${' + start,
                                                   ctx))
            sugs.update(self._variable_suggestions(controller, '@{' + start,
                                                   ctx))
        if self._blank(start) or not self._looks_like_variable(start):
            sugs.update(self._keyword_suggestions(datafile, start, ctx))
        sugs_list = list(sugs)
        sugs_list.sort()
        return sugs_list

    def _get_suggestions_from_hooks(self, datafile, start):
        sugs = []
        for hook in self._content_assist_hooks:
            sugs.extend(hook(datafile, start))
        return sugs

    def get_all_cached_library_names(self):
        return self._retriever.get_all_cached_library_names()

    def _blank(self, start):
        return start == ''

    def _looks_like_variable(self, start):
        return (len(start) == 1 and start.startswith('$') or
                start.startswith('@')) \
            or (len(start) >= 2 and start.startswith('${') or
                start.startswith('@{'))

    def _variable_suggestions(self, controller, start, ctx):
        datafile = controller.datafile
        start_normalized = utils.normalize(start)
        self._add_kw_arg_vars(controller, ctx.vars)
        variables = self._retriever.get_variables_from(datafile, ctx)
        return (v for v in variables
                if utils.normalize(v.name).startswith(start_normalized))

    def _add_kw_arg_vars(self, controller, variables):
        for name, value in controller.get_local_variables().iteritems():
            variables.set_argument(name, value)

    def _keyword_suggestions(self, datafile, start, ctx):
        start_normalized = utils.normalize(start)
        return (sug for sug in chain(
            self._get_default_keywords(),
            self._retriever.get_keywords_from(datafile, ctx))
                if sug.name_begins_with(start_normalized) or
                sug.longname_begins_with(start_normalized))

    def get_resources(self, datafile):
        return self._retriever.get_resources_from(datafile)

    def get_resource(self, path, directory='', report_status=True):
        return self._resource_factory.get_resource(
            directory, path,
            report_status=report_status)

    def find_resource_with_import(self, imp):
        ctx = self._context_factory.ctx_for_datafile(imp.parent.parent)
        return self._resource_factory.get_resource_from_import(imp, ctx)

    def new_resource(self, path, directory=''):
        return self._resource_factory.new_resource(directory, path)

    def find_user_keyword(self, datafile, kw_name):
        kw = self.find_keyword(datafile, kw_name)
        return kw if isinstance(kw, _UserKeywordInfo) else None

    def is_user_keyword(self, datafile, kw_name):
        return bool(self.find_user_keyword(datafile, kw_name))

    def find_library_keyword(self, datafile, kw_name):
        kw = self.find_keyword(datafile, kw_name)
        return kw if kw and kw.is_library_keyword() else None

    def is_library_import_ok(self, datafile, imp):
        return self._retriever.is_library_import_ok(
            datafile, imp, self._context_factory.ctx_for_datafile(datafile))

    def is_variables_import_ok(self, datafile, imp):
        return self._retriever.is_variables_import_ok(
            datafile, imp, self._context_factory.ctx_for_datafile(datafile))

    def find_keyword(self, datafile, kw_name):
        if not kw_name:
            return None
        kwds = self._retriever.get_keywords_cached(datafile,
                                                   self._context_factory)
        return kwds.get(kw_name)

    def is_library_keyword(self, datafile, kw_name):
        return bool(self.find_library_keyword(datafile, kw_name))

    def keyword_details(self, datafile, name):
        kw = self.find_keyword(datafile, name)
        return kw.details if kw else None