From e4b0c7f50efbe0c42aa933cb58a86a44367c1140 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Sat, 15 Aug 2015 14:50:43 +0200 Subject: Implemented module version of mcwrapper mcwrapper functionality split to modules. This is basic implementation of modules handling. Two module types are recognized. For server and commands for mcwrapper cli interface. This way can be implemented different command and server features simply without modifying main script. Interface between main script and modules is defined using service lists. Service list informs main script what function should be called in module. More detailed description should be written to README.md file. Or even separated file describing module interface. In this commit are implemented five different modules. Players and status are server modules. They are used only if mcwrapper is running instance of Minecraft server. Modules say and list-modules are implementing mcwrapper actions. And last module argmodules is implementing mcwrapper argument. For modules usage also added utils.py. This contains shared usable code that is used even by main mcwrapper script. --- modules/list-modules.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 modules/list-modules.py (limited to 'modules/list-modules.py') diff --git a/modules/list-modules.py b/modules/list-modules.py new file mode 100644 index 0000000..ca93dc3 --- /dev/null +++ b/modules/list-modules.py @@ -0,0 +1,51 @@ +import sys +import re +import utils +from utils import conf +import importlib.machinery as imp + +services = ( + utils.Service.action, + ) + +def action(args): + if conf.action == None: + if args[0].lower() != 'list-modules': + return False + conf.action = 'list-modules' + conf.action_module = sys.modules[__name__] + return 1 + elif conf.identifier == None: + conf.identifier = args[0] + return 1 + return 0 + +def action_exec(): + if conf.verbose_level >= 1: + for mod in conf.modules: + try: + module = imp.SourceFileLoader(mod, + conf.modulesFolder + '/' + mod + '.py').load_module() + print(module) + for service in module.services: + print(' ' + utils.Service.toStr(service)) + except FileNotFoundError: + sys.exit('Unknown module: ' + mod) + else: + # TODO add check if module exists + for mod in conf.modules: + print(mod) + +def action_help(): + print(' list-modules') + print(' List all modules that will be used.') + +def action_full_help(): + print('mcwrapper [arguments...] list-modules [IDENTIFIER]') + print(' List all modules that will be used.') + print('') + print(' arguments') + utils.printArgumentsHelp() + print(' IDENTIFIER') + print(' Identifier of Minecraft server instance.') + print(' If specified, server modules are printed.') -- cgit v1.2.3