mirror of
https://github.com/pkkid/python-plexapi
synced 2024-11-26 05:30:20 +00:00
29 lines
831 B
Python
29 lines
831 B
Python
"""
|
|
PlexConfig
|
|
"""
|
|
from collections import defaultdict
|
|
from ConfigParser import ConfigParser
|
|
|
|
|
|
class PlexConfig(ConfigParser):
|
|
|
|
def __init__(self, path):
|
|
ConfigParser.__init__(self)
|
|
self.read(path)
|
|
self.data = self._as_dict()
|
|
|
|
def get(self, key, default=None, cast=None):
|
|
try:
|
|
section, name = key.split('.')
|
|
value = self.data.get(section.lower(), {}).get(name.lower(), default)
|
|
return cast(value) if cast else value
|
|
except:
|
|
return default
|
|
|
|
def _as_dict(self):
|
|
config = defaultdict(dict)
|
|
for section in self._sections:
|
|
for name, value in self._sections[section].items():
|
|
if name != '__name__':
|
|
config[section.lower()][name.lower()] = value
|
|
return dict(config)
|