a functional prototype, plugins can be easily added and kinda work
This commit is contained in:
parent
7038b9a76a
commit
7edaa54a6f
3 changed files with 21 additions and 7 deletions
11
conf.ini
11
conf.ini
|
@ -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
|
|
@ -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)
|
||||||
|
|
15
vdstatus.py
15
vdstatus.py
|
@ -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))
|
||||||
|
|
Loading…
Reference in a new issue