diff --git a/conf.ini b/conf.ini index 452e091..0d3acc2 100644 --- a/conf.ini +++ b/conf.ini @@ -1,5 +1,10 @@ [main] -some_option = some value +plugins = day,time -[date] -format = %%A %%d %%H:%%M \ No newline at end of file +[day] +plugin = date +format = %%A %%d + +[time] +plugin = date +format = %%H:%%M \ No newline at end of file diff --git a/plugins/date.py b/plugins/date.py index 18a38ce..3fc7dc0 100644 --- a/plugins/date.py +++ b/plugins/date.py @@ -2,5 +2,5 @@ import time def run(conf): - fmt = conf['date']['format'] + fmt = conf['format'] return time.strftime(fmt) diff --git a/vdstatus.py b/vdstatus.py index 495d11c..0f62423 100644 --- a/vdstatus.py +++ b/vdstatus.py @@ -1,14 +1,23 @@ -import sys import os import configparser import importlib import plugins +def get_plugins(config): + result = list() + for element in config['main']['plugins'].split(','): + result.append(config[element]) + return result + DEFAULT_CONFIG = os.path.join(os.environ['HOME'], 'IdeaProjects/vdstatus/conf.ini') configuration = configparser.ConfigParser() configuration.read(DEFAULT_CONFIG) -importlib.import_module('.date', 'plugins') -print(plugins.date.run(configuration)) +plugin_list = get_plugins(configuration) + +for plugin in plugin_list: + plugin_name = '.' + plugin['plugin'] + plugin_module = importlib.import_module(plugin_name, 'plugins') + print(plugin_module.run(plugin))