32 lines
783 B
Python
32 lines
783 B
Python
from configparser import ConfigParser
|
|
|
|
from .local import Local
|
|
from .remote import Remote
|
|
|
|
class Config:
|
|
def __init__(self):
|
|
self._parser = ConfigParser()
|
|
|
|
@classmethod
|
|
def from_file(cls, path):
|
|
o = cls()
|
|
o._parser.read(path)
|
|
return o
|
|
|
|
@property
|
|
def locals(self):
|
|
for section in self._parser.sections:
|
|
if section.startswith("Local "):
|
|
yield Local.from_config(section)
|
|
|
|
@property
|
|
def remotes(self):
|
|
for section in self._parser.sections:
|
|
if section.startswith("Remote "):
|
|
yield Remote.from_config(section)
|
|
|
|
@property
|
|
def defaults(self):
|
|
if "DEFAULT" in self._parser.sections:
|
|
return self._parser["DEFAULT"]
|
|
return {} |