a functional prototype, plugins can be easily added and kinda work

This commit is contained in:
Von Random 2016-10-19 02:11:49 +03:00
parent 7038b9a76a
commit 7edaa54a6f
3 changed files with 21 additions and 7 deletions

View file

@ -1,5 +1,10 @@
[main]
some_option = some value
plugins = day,time
[date]
format = %%A %%d %%H:%%M
[day]
plugin = date
format = %%A %%d
[time]
plugin = date
format = %%H:%%M

View file

@ -2,5 +2,5 @@ import time
def run(conf):
fmt = conf['date']['format']
fmt = conf['format']
return time.strftime(fmt)

View file

@ -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))