How to use the sardana.sardanamodulemanager.ModuleManager function in sardana

To help you get started, we’ve selected a few sardana examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github taurus-org / taurus / src / sardana / macroserver / msmacromanager.py View on Github external
:return: the MacroLibrary object for the reloaded macro library"""
        path = path or self.getMacroPath()
        # reverse the path order:
        # more priority elements last. This way if there are repeated elements
        # they first ones (lower priority) will be overwritten by the last ones
        if path:
            path = copy.copy(path)
            path.reverse()

        # if there was previous Macro Library info remove it
        old_macro_lib = self._modules.pop(module_name, None)
        if old_macro_lib is not None:
            for macro in old_macro_lib.get_macros():
                self._macro_dict.pop(macro.name)

        mod_manager = ModuleManager()
        m, exc_info = None, None
        try:
            m = mod_manager.reloadModule(module_name, path)
        except:
            exc_info = sys.exc_info()
        macro_lib = None

        params = dict(module=m, name=module_name,
                      macro_server=self.macro_server, exc_info=exc_info)
        if m is None:
            file_name = self._findMacroLibName(module_name)
            if file_name is None:
                if exc_info:
                    msg = format_exception_only_str(*exc_info[:2])
                else:
                    msg = "Error (re)loading macro library '%s'" % module_name
github taurus-org / taurus / src / sardana / macroserver / msmacromanager.py View on Github external
:raises:
            ImportError in case the reload process is not successful
            LibraryError if trying to reload a macro library
            
        :param module_name: module name
        :param path:
            a list of absolute path to search for libraries [default: None,
            meaning search in MacroPath. If not found, search for a built-in,
            frozen or special module and continue search in sys.path. ]
        :return: the reloaded python module object"""
        
        if module_name in self._modules:
            raise LibraryError("Cannot use simple reload to reload a Macro Library")
        
        mod_manager = ModuleManager()
        retry = path is None
        try:
            if retry:
                path = self.getMacroPath()
                if path:
                    path = copy.copy(path)
                    path.reverse()                
            return mod_manager.reloadModule(module_name, path)
        except ImportError:
            if retry:
                return mod_manager.reloadModule(module_name, path=None)
            else:
                raise
github sardana-org / sardana / src / sardana / macroserver / macroserver.py View on Github external
def set_python_path(self, path):
        mod_man = ModuleManager()
        if self._path_id is not None:
            mod_man.remove_python_path(self._path_id)
        self._path_id = mod_man.add_python_path(path)
github sardana-org / sardana / src / sardana / macroserver / msrecordermanager.py View on Github external
path = copy.copy(path)
            path.reverse()

        # if there was previous Recorder Library info remove it
        old_recorder_lib = self._modules.pop(module_name, None)
        if old_recorder_lib is not None:
            for recorder in old_recorder_lib.get_recorders():
                self._recorder_dict.pop(recorder.name)
                # remove recorders from the map
                for _, recorders in self._scan_recorder_map.iteritems():
                    try:
                        recorders.remove(recorder)
                    except:
                        pass

        mod_manager = ModuleManager()
        m, exc_info = None, None
        try:
            m = mod_manager.reloadModule(
                module_name, path, reload=reload)
        except:
            exc_info = sys.exc_info()

        params = dict(module=m, name=module_name,
                      macro_server=self.macro_server, exc_info=exc_info)
        if m is None:
            file_name = self._findRecorderLibName(module_name)
            if file_name is None:
                if exc_info:
                    msg = format_exception_only_str(*exc_info[:2])
                else:
                    msg = "Error (re)loading recorder library '%s'" \
github sardana-org / sardana / src / sardana / macroserver / msmacromanager.py View on Github external
def reloadMacroLib(self, module_name, path=None):
        """Reloads the given library(=module) names.

        :raises:
            LibraryError in case the reload process is not successful

        :param module_name: macro library name (=python module name)
        :param path:
            a list of absolute path to search for libraries [default: None,
            means the current MacroPath will be used]
        :return: the MacroLibrary object for the reloaded macro library"""
        path = path or self.getMacroPath()
        mod_manager = ModuleManager()
        m, exc_info = None, None
        valid, exc_info = mod_manager.isValidModule(module_name, path)
        if not valid:
            params = dict(module=m, name=module_name,
                          macro_server=self.macro_server, exc_info=exc_info)
            return MacroLibrary(**params)

        # if there was previous Macro Library info remove it
        old_macro_lib = self._modules.pop(module_name, None)
        if old_macro_lib is not None:
            for macro in old_macro_lib.get_macros():
                self._macro_dict.pop(macro.name)

        try:
            m = mod_manager.reloadModule(module_name, path)
        except:
github sardana-org / sardana / src / sardana / pool / pool.py View on Github external
def set_python_path(self, path):
        mod_man = ModuleManager()
        if self._path_id is not None:
            mod_man.remove_python_path(self._path_id)
        self._path_id = mod_man.add_python_path(path)
github sardana-org / sardana / src / sardana / pool / poolcontrollermanager.py View on Github external
"""
        path = path or self.getControllerPath()
        # reverse the path order:
        # more priority elements last. This way if there are repeated elements
        # they first ones (lower priority) will be overwritten by the last ones
        if path:
            path = copy.copy(path)
            path.reverse()

        # if there was previous Controller Lib info remove it
        if self._modules.has_key(module_name):
            self._modules.pop(module_name)

        m, exc_info = None, None
        try:
            m = ModuleManager().reloadModule(module_name, path, reload=reload)
        except:
            exc_info = sys.exc_info()

        controller_lib = None
        params = dict(module=m, name=module_name, pool=self.get_pool())
        if m is None or exc_info is not None:
            params['exc_info'] = exc_info
            controller_lib = ControllerLibrary(**params)
            self._modules[module_name] = controller_lib
        else:
            controller_lib = ControllerLibrary(**params)
            lib_contains_controllers = False
            abs_file = controller_lib.file_path
            for _, klass in inspect.getmembers(m, inspect.isclass):
                if issubclass(klass, controller.Controller):
                    # if it is a class defined in some other class forget it to
github sardana-org / sardana / src / sardana / macroserver / manager.py View on Github external
def __getattr__(self, name):
        try:
            return getattr(MacroManager(), name)
        except:
            try:
                return getattr(TypeManager(), name)
            except:
                try:
                    return getattr(ModuleManager(), name)
                except:
                    try:
                        return getattr(EnvironmentManager(), name)
                    except:
                        raise AttributeError("No Manager has attribute %s"
                                             % name)