start making a proper module from vdstatus.py, also properly use configparser
This commit is contained in:
parent
7edaa54a6f
commit
e2ca550f37
4 changed files with 19 additions and 15 deletions
2
conf.ini
2
conf.ini
|
@ -1,8 +1,8 @@
|
||||||
[main]
|
[main]
|
||||||
plugins = day,time
|
|
||||||
|
|
||||||
[day]
|
[day]
|
||||||
plugin = date
|
plugin = date
|
||||||
|
color = red
|
||||||
format = %%A %%d
|
format = %%A %%d
|
||||||
|
|
||||||
[time]
|
[time]
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
|
||||||
def run(conf):
|
def run(config, section):
|
||||||
fmt = conf['format']
|
fmt = config.get(section, 'format')
|
||||||
return time.strftime(fmt)
|
result = dict()
|
||||||
|
if config.has_option(section, 'color'):
|
||||||
|
result['color'] = config.get(section, 'color')
|
||||||
|
result['full_text'] = time.strftime(fmt)
|
||||||
|
return result
|
||||||
|
|
21
vdstatus.py
21
vdstatus.py
|
@ -1,23 +1,22 @@
|
||||||
|
import json
|
||||||
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)
|
||||||
|
|
||||||
plugin_list = get_plugins(configuration)
|
|
||||||
|
|
||||||
for plugin in plugin_list:
|
def run_plugins():
|
||||||
plugin_name = '.' + plugin['plugin']
|
outputs = list()
|
||||||
plugin_module = importlib.import_module(plugin_name, 'plugins')
|
for section in configuration.sections():
|
||||||
print(plugin_module.run(plugin))
|
if section == 'main':
|
||||||
|
continue
|
||||||
|
plugin_name = '.' + configuration.get(section, 'plugin')
|
||||||
|
plugin_module = importlib.import_module(plugin_name, 'plugins')
|
||||||
|
outputs.append(plugin_module.run(configuration, section))
|
||||||
|
print(json.dumps(outputs) + ',')
|
||||||
|
|
1
vdstatus_i3
Executable file
1
vdstatus_i3
Executable file
|
@ -0,0 +1 @@
|
||||||
|
#!/usr/bin/env python3 -u
|
Loading…
Reference in a new issue