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]
|
||||
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
|
|
@ -2,5 +2,5 @@ import time
|
|||
|
||||
|
||||
def run(conf):
|
||||
fmt = conf['date']['format']
|
||||
fmt = conf['format']
|
||||
return time.strftime(fmt)
|
||||
|
|
15
vdstatus.py
15
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))
|
||||
|
|
Loading…
Reference in a new issue