本文整理汇总了Python中server.Server.init方法的典型用法代码示例。如果您正苦于以下问题:Python Server.init方法的具体用法?Python Server.init怎么用?Python Server.init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类server.Server
的用法示例。
在下文中一共展示了Server.init方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from server import Server [as 别名]
# 或者: from server.Server import init [as 别名]
class Wrapper:
def __init__(self):
self.log = Log()
self.configManager = Config(self.log)
self.plugins = {}
self.server = False
self.proxy = False
self.halt = False
self.listeners = []
self.update = False
self.storage = storage.Storage("main", self.log)
self.permissions = storage.Storage("permissions", self.log)
self.commands = {}
self.events = {}
self.permission = {}
self.help = {}
def loadPlugin(self, i):
if "disabled_plugins" not in self.storage: self.storage["disabled_plugins"] = []
self.log.info("Loading plugin %s..." % i)
if os.path.isdir("wrapper-plugins/%s" % i):
plugin = import_module(i)
name = i
elif i[-3:] == ".py":
plugin = import_module(i[:-3])
name = i[:-3]
else:
return False
try: name = plugin.NAME
except: pass
try: id = plugin.ID
except: id = name
try: version = plugin.VERSION
except: version = (0, 1)
try: description = plugin.DESCRIPTION
except: description = None
try: summary = plugin.SUMMARY
except: summary = None
try: author = plugin.AUTHOR
except: author = None
try: website = plugin.WEBSITE
except: website = None
if id in self.storage["disabled_plugins"]:
self.log.warn("Plugin '%s' disabled - not loading" % name)
return
main = plugin.Main(API(self, name, id), PluginLog(self.log, name))
self.plugins[id] = {"main": main, "good": True, "module": plugin} # "events": {}, "commands": {},
self.plugins[id]["name"] = name
self.plugins[id]["version"] = version
self.plugins[id]["summary"] = summary
self.plugins[id]["description"] = description
self.plugins[id]["author"] = author
self.plugins[id]["website"] = website
self.plugins[id]["filename"] = i
self.commands[id] = {}
self.events[id] = {}
self.permission[id] = {}
self.help[id] = {}
main.onEnable()
def unloadPlugin(self, plugin):
del self.commands[plugin]
del self.events[plugin]
del self.help[plugin]
try:
self.plugins[plugin]["main"].onDisable()
except:
self.log.error("Error while disabling plugin '%s'" % plugin)
self.log.getTraceback()
try:
reload(self.plugins[plugin]["module"])
except:
self.log.error("Error while reloading plugin '%s' -- it was probably deleted or is a bugged version" % plugin)
self.log.getTraceback()
def loadPlugins(self):
self.log.info("Loading plugins...")
if not os.path.exists("wrapper-plugins"):
os.mkdir("wrapper-plugins")
sys.path.append("wrapper-plugins")
for i in os.listdir("wrapper-plugins"):
try:
if i[0] == ".": continue
if os.path.isdir("wrapper-plugins/%s" % i): self.loadPlugin(i)
elif i[-3:] == ".py": self.loadPlugin(i)
except:
for line in traceback.format_exc().split("\n"):
self.log.debug(line)
self.log.error("Failed to import plugin '%s'" % i)
self.plugins[i] = {"name": i, "good": False}
self.callEvent("helloworld.event", {"testValue": True})
def disablePlugins(self):
self.log.error("Disabling plugins...")
for i in self.plugins:
self.unloadPlugin(i)
def reloadPlugins(self):
for i in self.plugins:
try:
self.unloadPlugin(i)
except:
for line in traceback.format_exc().split("\n"):
self.log.debug(line)
#.........这里部分代码省略.........
示例2: __init__
# 需要导入模块: from server import Server [as 别名]
# 或者: from server.Server import init [as 别名]
class Wrapper:
def __init__(self):
self.log = Log()
self.configManager = Config(self.log)
self.plugins = {}
self.server = False
self.proxy = False
self.halt = False
self.listeners = []
self.update = False
self.storage = storage.Storage("main", self.log)
self.permissions = storage.Storage("permissions", self.log)
self.commands = {}
self.events = {}
self.permission = {}
def loadPlugin(self, i):
self.log.info("Loading plugin %s..." % i)
if os.path.isdir("wrapper-plugins/%s" % i):
plugin = import_module(i)
name = i
elif i[-3:] == ".py":
plugin = import_module(i[:-3])
name = i[:-3]
else:
return False
try: name = plugin.NAME
except: pass
try: id = plugin.ID
except: id = name
try: version = plugin.VERSION
except: version = (0, 1)
try: description = plugin.DESCRIPTION
except: description = None
try: summary = plugin.SUMMARY
except: summary = None
main = plugin.Main(API(self, name, id), PluginLog(self.log, name))
self.plugins[id] = {"main": main, "good": True, "module": plugin} # "events": {}, "commands": {},
self.plugins[id]["name"] = name
self.plugins[id]["version"] = version
self.plugins[id]["summary"] = summary
self.plugins[id]["description"] = description
self.plugins[id]["filename"] = i
self.commands[id] = {}
self.events[id] = {}
self.permission[id] = {}
main.onEnable()
def unloadPlugin(self, plugin):
del self.commands[plugin]
del self.events[plugin]
try:
self.plugins[plugin]["main"].onDisable()
except:
self.log.error("Error while disabling plugin '%s'" % plugin)
self.log.getTraceback()
reload(self.plugins[plugin]["module"])
def loadPlugins(self):
self.log.info("Loading plugins...")
if not os.path.exists("wrapper-plugins"):
os.mkdir("wrapper-plugins")
sys.path.append("wrapper-plugins")
for i in os.listdir("wrapper-plugins"):
try:
if i[0] == ".": continue
if os.path.isdir("wrapper-plugins/%s" % i): self.loadPlugin(i)
elif i[-3:] == ".py": self.loadPlugin(i)
except:
for line in traceback.format_exc().split("\n"):
self.log.debug(line)
self.log.error("Failed to import plugin '%s'" % i)
self.plugins[i] = {"name": i, "good": False}
self.callEvent("helloworld.event", {"testValue": True})
def disablePlugins(self):
self.log.error("Disabling plugins...")
for i in self.plugins:
self.unloadPlugin(i)
def reloadPlugins(self):
for i in self.plugins:
try:
self.unloadPlugin(i)
except:
for line in traceback.format_exc().split("\n"):
self.log.debug(line)
self.log.error("Failed to unload plugin '%s'" % i)
try:
reload(self.plugins[plugin]["module"])
except:
pass
self.plugins = {}
self.loadPlugins()
self.log.info("Plugins reloaded")
def callEvent(self, event, payload):
if event == "player.runCommand":
if not self.playerCommand(payload): return False
for sock in self.listeners:
sock.append({"event": event, "payload": payload})
try:
for pluginID in self.events:
if event in self.events[pluginID]:
try:
#.........这里部分代码省略.........
示例3: QApplication
# 需要导入模块: from server import Server [as 别名]
# 或者: from server.Server import init [as 别名]
self.setText(msg)
if __name__ == "__main__":
from PyQt4.QtGui import QApplication, QLabel, QMessageBox
import sys
import os
print os.getpid()
app = QApplication(sys.argv)
text = QLabel(" QLocalServer tests")
# text = Label(" QLocalServer tests")
text.resize(600,400)
s = Server()
if (s.init("localserver-test")==False):
QMessageBox.information(text,"info", "There is already exist one!") #// 初使化失败, 说明已经有一个在运行了
sys.exit(-1)
# QObject.connect(s,SIGNAL("newMessage(PyQt_PyObject)"),text, SLOT("setText__2(PyQt_PyObject)"))
# QObject.connect(s,SIGNAL("newMessage(QString)"),text, SLOT("setText__2(QString)"))
QObject.connect(s,SIGNAL("newMessage(QString)"),text, SLOT("setText(QString)"))
text.show()
sys.exit(app.exec_())