Browse Source

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

master
Von Random 3 years ago
parent
commit
e2ca550f37
4 changed files with 19 additions and 15 deletions
  1. 1
    1
      conf.ini
  2. 7
    3
      plugins/date.py
  3. 10
    11
      vdstatus.py
  4. 1
    0
      vdstatus_i3

+ 1
- 1
conf.ini View File

@@ -1,8 +1,8 @@
[main]
plugins = day,time

[day]
plugin = date
color = red
format = %%A %%d

[time]

+ 7
- 3
plugins/date.py 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

+ 10
- 11
vdstatus.py 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']
plugin_module = importlib.import_module(plugin_name, 'plugins')
print(plugin_module.run(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')
outputs.append(plugin_module.run(configuration, section))
print(json.dumps(outputs) + ',')

+ 1
- 0
vdstatus_i3 View File

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

Loading…
Cancel
Save