本文整理汇总了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)
示例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: