start making a proper module from vdstatus.py, also properly use configparser

This commit is contained in:
Von Random 2016-10-19 12:19:45 +03:00
parent 7edaa54a6f
commit e2ca550f37
4 changed files with 19 additions and 15 deletions

View file

@ -1,8 +1,8 @@
[main]
plugins = day,time
[day]
plugin = date
color = red
format = %%A %%d
[time]

View file

@ -1,6 +1,10 @@
import time
def run(conf):
fmt = conf['format']
return time.strftime(fmt)
def run(config, section):
fmt = config.get(section, 'format')
result = dict()
if config.has_option(section, 'color'):
result['color'] = config.get(section, 'color')
result['full_text'] = time.strftime(fmt)
return result

View file

@ -1,23 +1,22 @@
import json
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)
plugin_list = get_plugins(configuration)
for plugin in plugin_list:
plugin_name = '.' + plugin['plugin']
def run_plugins():
outputs = list()
for section in configuration.sections():
if section == 'main':
continue
plugin_name = '.' + configuration.get(section, 'plugin')
plugin_module = importlib.import_module(plugin_name, 'plugins')
print(plugin_module.run(plugin))
outputs.append(plugin_module.run(configuration, section))
print(json.dumps(outputs) + ',')

1
vdstatus_i3 Executable file
View file

@ -0,0 +1 @@
#!/usr/bin/env python3 -u