[theme] Add YAML as optional format for themes

This addresses issue #4
This commit is contained in:
Tobias Witek 2016-11-05 16:53:18 +01:00
parent 6eea8da1af
commit e2a6d41389
2 changed files with 68 additions and 2 deletions

View file

@ -1,5 +1,6 @@
import os
import json
import yaml
import glob
def getpath():
@ -12,8 +13,13 @@ def themes():
class Theme:
def __init__(self, config):
self._config = config
with open("{}/{}.json".format(getpath(), config.theme())) as f:
self._data = json.load(f)
if os.path.isfile("{}/{}.yaml".format(getpath(), config.theme())):
with open("{}/{}.yaml".format(getpath(), config.theme())) as f:
self._data = yaml.load(f)
else:
with open("{}/{}.json".format(getpath(), config.theme())) as f:
self._data = json.load(f)
self._defaults = self._data.get("defaults", {})
self._cycles = self._defaults.get("cycle", [])
self.begin()