Пример #1
0
 def refreshServers(self):
     """Refresh the list of available servers."""
     servers = {}
     # look for python plugins
     for module in self.config.mods:
         try:
             __import__(module)
             plugins = getPlugins(ILabradServer, sys.modules[module])
             for plugin in plugins:
                 s = createPythonServerCls(plugin)
                 s.client = self.client
                 if s.name not in servers:
                     servers[s.name] = s
         except:
             logging.error('Error while loading plugins from module "%s":' % module,
                           exc_info=True)
     # look for .ini files
     for dirname in self.config.dirs:
         for path, dirs, files in os.walk(dirname):
             if '.nodeignore' in files:
                 del dirs[:] # clear dirs list so we don't visit subdirs
                 continue
             for f in files:
                 try:
                     _, ext = os.path.splitext(f)
                     if ext.lower() not in self.config.extensions:
                         continue
                     if ext.lower() == '.ini':
                         with open(os.path.join(path, f)) as file:
                             conf = file.read()
                     elif ext.lower() in ['.war', '.jar']:
                         zf = zipfile.ZipFile(os.path.join(path, f))
                         found = False
                         for info in zf.infolist():
                             if 'node.ini' in info.filename:
                                 found = True
                                 member = zf.open(info.filename)
                                 conf = member.read()
                                 member.close()
                                 break
                         zf.close()
                     else:
                         conf = findConfigBlock(path, f)
                         if conf is None:
                             continue
                     s = createGenericServerCls(path, f, conf)
                     s.client = self.client
                     if s.name not in servers:
                         servers[s.name] = s
                 except:
                     fname = os.path.join(path, f)
                     logging.error('Error while loading config file "%s":' % fname,
                               exc_info=True)
     self.servers = servers
     # send a message with the current server list
     dispatcher.send('status', servers=self.status())
Пример #2
0
 def refreshServers(self):
     """Refresh the list of available servers."""
     servers = {}
     # look for python plugins
     for module in self.config.mods:
         try:
             __import__(module)
             plugins = getPlugins(ILabradServer, sys.modules[module])
             for plugin in plugins:
                 s = createPythonServerCls(plugin)
                 s.client = self.client
                 if s.name not in servers:
                     servers[s.name] = s
         except:
             logging.error('Error while loading plugins from module "%s":' % module,
                           exc_info=True)
     # look for .ini files
     for dirname in self.config.dirs:
         for path, dirs, files in os.walk(dirname):
             if '.nodeignore' in files:
                 del dirs[:] # clear dirs list so we don't visit subdirs
                 continue
             for f in files:
                 try:
                     _, ext = os.path.splitext(f)
                     if ext.lower() not in self.config.extensions:
                         continue
                     if ext.lower() == '.ini':
                         with open(os.path.join(path, f)) as file:
                             conf = file.read()
                     elif ext.lower() in ['.war', '.jar']:
                         zf = zipfile.ZipFile(os.path.join(path, f))
                         found = False
                         for info in zf.infolist():
                             if 'node.ini' in info.filename:
                                 found = True
                                 member = zf.open(info.filename)
                                 conf = member.read()
                                 member.close()
                                 break
                         zf.close()
                     else:
                         conf = findConfigBlock(path, f)
                         if conf is None:
                             continue
                     s = createGenericServerCls(path, f, conf)
                     s.client = self.client
                     if s.name not in servers:
                         servers[s.name] = s
                 except:
                     fname = os.path.join(path, f)
                     logging.error('Error while loading config file "%s":' % fname,
                               exc_info=True)
     self.servers = servers
     # send a message with the current server list
     dispatcher.send('status', servers=self.status())
Пример #3
0
 def refreshServers(self):
     """Refresh the list of available servers."""
     servers = {}
     # look for python plugins
     for module in self.config.mods:
         try:
             __import__(module)
             plugins = getPlugins(ILabradServer, sys.modules[module])
             for plugin in plugins:
                 s = createPythonServerCls(plugin)
                 s.client = self.client
                 if s.name not in servers:
                     servers[s.name] = s
         except:
             print 'Error while loading plugins from module "%s":' % module
             failure.Failure().printTraceback(elideFrameworkCode=1)
     # look for .ini files
     for dirname in self.config.dirs:
         for path, dirs, files in os.walk(dirname):
             for f in files:
                 try:
                     _, ext = os.path.splitext(f)
                     if ext.lower() not in self.config.extensions:
                         continue
                     if ext.lower() == '.ini':
                         with open(os.path.join(path, f)) as file:
                             conf = file.read()
                     else:
                         conf = findConfigBlock(path, f)
                         if conf is None:
                             continue
                     s = createGenericServerCls(path, f, conf)
                     s.client = self.client
                     if s.name not in servers:
                         servers[s.name] = s
                 except:
                     fname = os.path.join(path, f)
                     print 'Error while loading config file "%s":' % fname
                     failure.Failure().printTraceback(elideFrameworkCode=1)
     self.servers = servers
     # send a message with the current server list
     dispatcher.send('status', servers=self.status())        
Пример #4
0
 def refreshServers(self):
     """Refresh the list of available servers."""
     servers = {}
     # look for python plugins
     for module in self.config.mods:
         try:
             __import__(module)
             plugins = getPlugins(ILabradServer, sys.modules[module])
             for plugin in plugins:
                 s = createPythonServerCls(plugin)
                 s.client = self.client
                 if s.name not in servers:
                     servers[s.name] = s
         except:
             print 'Error while loading plugins from module "%s":' % module
             failure.Failure().printTraceback(elideFrameworkCode=1)
     # look for .ini files
     for dirname in self.config.dirs:
         for path, dirs, files in os.walk(dirname):
             for f in files:
                 try:
                     _, ext = os.path.splitext(f)
                     if ext.lower() not in self.config.extensions:
                         continue
                     if ext.lower() == '.ini':
                         with open(os.path.join(path, f)) as file:
                             conf = file.read()
                     else:
                         conf = findConfigBlock(path, f)
                         if conf is None:
                             continue
                     s = createGenericServerCls(path, f, conf)
                     s.client = self.client
                     if s.name not in servers:
                         servers[s.name] = s
                 except:
                     fname = os.path.join(path, f)
                     print 'Error while loading config file "%s":' % fname
                     failure.Failure().printTraceback(elideFrameworkCode=1)
     self.servers = servers
     # send a message with the current server list
     dispatcher.send('status', servers=self.status())
Пример #5
0
    def refreshServers(self):
        """Refresh the list of available servers."""
        # configs is a nested map from name to version to list of classes.
        #
        # This allows us to deal with cases where there are many definitions
        # for different server versions, and possibly also redundant defitions
        # for the same version.
        configs = {}

        # look for .ini files
        for dirname in self.config.dirs:
            for path, dirs, files in os.walk(dirname):
                if '.nodeignore' in files:
                    del dirs[:] # clear dirs list so we don't visit subdirs
                    continue
                for f in files:
                    try:
                        _, ext = os.path.splitext(f)
                        if ext.lower() not in self.config.extensions:
                            continue
                        if ext.lower() == '.ini':
                            with open(os.path.join(path, f)) as file:
                                conf = file.read()
                        elif ext.lower() in ['.war', '.jar']:
                            zf = zipfile.ZipFile(os.path.join(path, f))
                            found = False
                            for info in zf.infolist():
                                if 'node.ini' in info.filename:
                                    found = True
                                    member = zf.open(info.filename)
                                    conf = member.read()
                                    member.close()
                                    break
                            zf.close()
                        else:
                            conf = findConfigBlock(path, f)
                            if conf is None:
                                continue
                        s = createGenericServerCls(path, f, conf)
                        s.client = self.client
                        if s.name not in configs:
                            configs[s.name] = {}
                        versions = configs.setdefault(s.name, {})
                        classes = versions.setdefault(s.version, [])
                        classes.append(s)
                    except Exception:
                        fname = os.path.join(path, f)
                        logging.error('Error while loading config file "%s":' % fname,
                                  exc_info=True)

        servers_dict = {}
        for versions in configs.values():
            for servers in versions.values():
                if len(servers) > 1:
                    conflicting_files = [s.filename for s in servers]
                    s = servers[0]
                    logging.warning(
                        'Found redundant server configs with same name and '
                        'version; will use {}. name={}, version={}, '
                        'conflicting_files={}'
                        .format(s.filename, s.name, s.version,
                                conflicting_files))

            servers = [ss[0] for ss in versions.values()]
            servers.sort(key=lambda s: version_tuple(s.version))
            if len(servers) > 1:
                # modify server name for all but the latest version
                for s in servers[:-1]:
                    s.name = '{}-{}'.format(s.name, s.version)

            for s in servers:
                servers_dict[s.name] = s
        self.servers = servers_dict
        # send a message with the current server list
        dispatcher.send('status', servers=self.status())
Пример #6
0
 def serverConnected(self, ID, name):
     """Called when a server connects to LabRAD."""
     dispatcher.send('serverConnected', ID=ID, name=name)
Пример #7
0
 def emitMessage(self, msg):
     """Emit a message to other parts of this application."""
     dispatcher.send(msg,
                     sender=self,
                     server=self.__class__.name,
                     instance=self.name)
Пример #8
0
 def serverConnected(self, ID, name):
     """Called when a server connects to LabRAD."""
     dispatcher.send('serverConnected', ID=ID, name=name)
Пример #9
0
 def emitMessage(self, msg):
     """Emit a message to other parts of this application."""
     dispatcher.send(msg,
                     sender=self,
                     server=self.__class__.name,
                     instance=self.name)
Пример #10
0
    def refreshServers(self):
        """Refresh the list of available servers."""
        # configs is a nested map from name to version to list of classes.
        #
        # This allows us to deal with cases where there are many definitions
        # for different server versions, and possibly also redundant defitions
        # for the same version.
        configs = {}

        # look for .ini files
        for dirname in self.config.dirs:
            for path, dirs, files in os.walk(dirname):
                if '.nodeignore' in files:
                    del dirs[:] # clear dirs list so we don't visit subdirs
                    continue
                for f in files:
                    try:
                        _, ext = os.path.splitext(f)
                        if ext.lower() not in self.config.extensions:
                            continue
                        if ext.lower() == '.ini':
                            with open(os.path.join(path, f)) as file:
                                conf = file.read()
                        elif ext.lower() in ['.war', '.jar']:
                            zf = zipfile.ZipFile(os.path.join(path, f))
                            found = False
                            for info in zf.infolist():
                                if 'node.ini' in info.filename:
                                    found = True
                                    member = zf.open(info.filename)
                                    conf = member.read()
                                    member.close()
                                    break
                            zf.close()
                        else:
                            conf = findConfigBlock(path, f)
                            if conf is None:
                                continue
                        s = createGenericServerCls(path, f, conf)
                        s.client = self.client
                        if s.name not in configs:
                            configs[s.name] = {}
                        versions = configs.setdefault(s.name, {})
                        classes = versions.setdefault(s.version, [])
                        classes.append(s)
                    except Exception:
                        fname = os.path.join(path, f)
                        logging.error('Error while loading config file "%s":' % fname,
                                  exc_info=True)

        servers_dict = {}
        for versions in configs.values():
            for servers in versions.values():
                if len(servers) > 1:
                    conflicting_files = [s.filename for s in servers]
                    s = servers[0]
                    logging.warning(
                        'Found redundant server configs with same name and '
                        'version; will use {}. name={}, version={}, '
                        'conflicting_files={}'
                        .format(s.filename, s.name, s.version,
                                conflicting_files))

            servers = [ss[0] for ss in versions.values()]
            servers.sort(key=lambda s: version_tuple(s.version))
            if len(servers) > 1:
                # modify server name for all but the latest version
                for s in servers[:-1]:
                    s.name = '{}-{}'.format(s.name, s.version)

            for s in servers:
                servers_dict[s.name] = s
        self.servers = servers_dict
        # send a message with the current server list
        dispatcher.send('status', servers=self.status())