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] [main]
some_option = some value plugins = day,time
[date] [day]
format = %%A %%d %%H:%%M plugin = date
format = %%A %%d
[time]
plugin = date
format = %%H:%%M

View file

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

View file

@ -1,14 +1,23 @@
import sys
import os import os
import configparser import configparser
import importlib import importlib
import plugins 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') DEFAULT_CONFIG = os.path.join(os.environ['HOME'], 'IdeaProjects/vdstatus/conf.ini')
configuration = configparser.ConfigParser() configuration = configparser.ConfigParser()
configuration.read(DEFAULT_CONFIG) configuration.read(DEFAULT_CONFIG)
importlib.import_module('.date', 'plugins') plugin_list = get_plugins(configuration)
print(plugins.date.run(configuration))
for plugin in plugin_list:
plugin_name = '.' + plugin['plugin']
plugin_module = importlib.import_module(plugin_name, 'plugins')
print(plugin_module.run(plugin))