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


Python Server.init方法代码示例

本文整理汇总了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)
#.........这里部分代码省略.........
开发者ID:gitter-badger,项目名称:minecraft-wrapper,代码行数:103,代码来源:__main__.py

示例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:
#.........这里部分代码省略.........
开发者ID:eristoddle,项目名称:minecraft-wrapper,代码行数:103,代码来源:__main__.py

示例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_())




开发者ID:github-jxm,项目名称:QtCrearor_fast_learn,代码行数:28,代码来源:main.py


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