当前位置: 首页>>代码示例>>Python>>正文


Python Server.consoleReadTo方法代码示例

本文整理汇总了Python中Server.Server.consoleReadTo方法的典型用法代码示例。如果您正苦于以下问题:Python Server.consoleReadTo方法的具体用法?Python Server.consoleReadTo怎么用?Python Server.consoleReadTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Server.Server的用法示例。


在下文中一共展示了Server.consoleReadTo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: MyServer

# 需要导入模块: from Server import Server [as 别名]
# 或者: from Server.Server import consoleReadTo [as 别名]

#.........这里部分代码省略.........
        w.setText(0, str(key) + ': ' + str(self.onlineDict[name][key]))
        a.insertChild(0, w)
  
  def updatePluginsList(self):
    for pluginName in self.pluginsDict.keys():
      a = QtGui.QTreeWidgetItem(self.ui.treeWidgetPluginList)
      a.setText(0, str(pluginName))
      
  def pluginNameClicked(self):
    pluginName = str(self.ui.treeWidgetPluginList.currentItem().text(0))
    lines = ''
    for line in self.pluginsDict[pluginName]:
      lines = lines + line + '\n'
    self.ui.textBrowserPlugin.setText(lines)

      	
#####################
#Other methodsprint
#####################

  def findPlugins(self):
    bukkitDir = os.path.split(self.s.startupScript)[0]
    pluginsDir = os.path.join(bukkitDir, 'plugins')
    pluginsListRaw = os.listdir(pluginsDir)
    for plugin in pluginsListRaw: #Dont include it twice if there is a .jar and a folder with the same name
      pluginName = plugin.split('.')[0]
      if pluginName not in self.pluginsDict:
        self.pluginsDict[pluginName] = []
    self.updatePluginsList()
    

  def getNewServerLines(self):
    if self.lastServerLine == 'first run': #If we are first starting up the app, read back to the last reboot
      newServerLines = self.s.consoleReadTo(' [INFO] Stopping server')
    else:
      newServerLines = self.s.consoleReadTo(self.lastServerLine)
    if len(newServerLines) > 0:
      self.lastServerLine = newServerLines[-1]
    return newServerLines
    
  def routeServerLines(self):
  
    #Set up variables to monitor if we found any of the relevent lines. We do this so we dont have
    #to call their respective functions of nothing was found
    chatLinesWereFound = False
    playersChanged = False
    
    newServerLines = self.getNewServerLines()
    chatLines = []
    if len(newServerLines) > 0: #Don't waste your time if no new lines are found
      for line in newServerLines:
        matchChat = re.search(r'<\w+>', line)
        matchChat2 = re.search(r'\[CONSOLE\]', line)
        matchLoggedIn = re.search(r'(\d+\-\d+\-\d+ \d+:\d+:\d+) \[INFO\] (\w+) \[/(\d+\.\d+\.\d+\.\d+:\d+)\] logged in with entity id (\d+) at', line)
        matchLoggedOut = re.search(r'\] (\w+) lost connection: disconnect.quitting', line)
        matchLoggedOut2 = re.search(r'\] (\w+) lost connection: disconnect.endOfStream', line)
        matchPlugin = re.search(r'\d+\-\d+\-\d+ \d+:\d+:\d+ \[INFO\] \[(\w+)\]', line)
 
        if matchChat or matchChat2:
          chatLinesWereFound = True
          chatLines.append(line)
        
        if matchLoggedIn:
          playersChanged = True
          time = matchLoggedIn.group(1)
          name = matchLoggedIn.group(2)
开发者ID:doctoboggan,项目名称:blankkit,代码行数:70,代码来源:main.py

示例2: MyServer

# 需要导入模块: from Server import Server [as 别名]
# 或者: from Server.Server import consoleReadTo [as 别名]

#.........这里部分代码省略.........
      a = QtGui.QTreeWidgetItem(self.ui.treeWidgetPluginList)
      a.setText(0, str(pluginName))
      
  def pluginNameClicked(self):
    pluginName = str(self.ui.treeWidgetPluginList.currentItem().text(0))
    lines = '\n'.join(self.pluginsDict[pluginName])
    self.ui.textBrowserPlugin.setText(lines)

      	
#####################
#Other methods
#####################

  #This function finds all the plugins in the plugins folder and stores them in a dict
  def findPlugins(self):
    bukkitDir = os.path.split(self.s.startupScript)[0]
    pluginsDir = os.path.join(bukkitDir, 'plugins')
    pluginsListRaw = os.listdir(pluginsDir)
    for plugin in pluginsListRaw: #Dont include it twice if there is a .jar and a folder with the same name
      pluginName = plugin.split('.')[0]
      if pluginName not in self.pluginsDict:
        self.pluginsDict[pluginName] = []
    self.updatePluginsList()

  #If the server.log file is changed, a signal connected to this function will be emitted
  def newLineDetected(self):
    thread = GenericThread(self.getNewLines, self.lastServerLine)
    self.disconnect(self, QtCore.SIGNAL('stringFound'), self.routeServerLines)
    self.connect(self, QtCore.SIGNAL('stringFound'), self.routeServerLines)
    thread.start()

  #This function is spawned in the thread to get new lines.
  def getNewLines(self, lastLine):
    newServerLines = self.s.consoleReadTo(lastLine)
    self.emit(QtCore.SIGNAL('stringFound'), newServerLines)

  #This function takes a list of new server lines and routes them to where they need to go.
  def routeServerLines(self, newServerLines):
    chatLines = []
    self.lastServerLine = newServerLines[-1] #Store the last line so we know where to read to later
    for line in newServerLines:
      matchChat = re.search(r'<\w+>', line)
      matchChat2 = re.search(r'\[CONSOLE\]', line)
      matchLoggedIn = re.search(r'(\d+\-\d+\-\d+ \d+:\d+:\d+) \[INFO\] (\w+) \[/(\d+\.\d+\.\d+\.\d+:\d+)\] logged in with entity id (\d+) at', line)
      matchLoggedOut = re.search(r'\] (\w+) lost connection: disconnect.quitting', line)
      matchLoggedOut2 = re.search(r'\] (\w+) lost connection: disconnect.endOfStream', line)
      matchPlugin = re.search(r'\d+\-\d+\-\d+ \d+:\d+:\d+ \[INFO\] \[(\w+)\]', line)

      if matchChat or matchChat2:
        chatLines.append(line)
      
      if matchLoggedIn:
        time = matchLoggedIn.group(1)
        name = matchLoggedIn.group(2)
        ip = matchLoggedIn.group(3)
        ID = matchLoggedIn.group(4)
        self.onlineDict[name] = {'Logged In':time[11:],
                                 'IP':ip,
                                 'ID':ID}
      
      if matchLoggedOut or matchLoggedOut2:
        try:
          name = matchLoggedOut.group(1)
        except AttributeError:
          name = matchLoggedOut2.group(1)
        if name in self.onlineDict:
开发者ID:doctoboggan,项目名称:blankkit,代码行数:70,代码来源:main.py


注:本文中的Server.Server.consoleReadTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。