def read_config(cls, filepath): lines = open(filepath).readlines() repo_manager = RepoManager() dct = OrderedDict() cur_section = None for line in lines: if line.startswith('['): section = re.findall(r'^[[](.*?)[]]$', line)[0] cur_section = section.strip() elif line.startswith(' '): key, val = re.findall(r'^[ ]{4}([^ ]+)\s*=\s*([^ ]+)$', line)[0] if not cur_section in dct: dct[cur_section] = OrderedDict() dct[cur_section][key.strip()] = val.strip() for section, d in dct.items(): repo_manager.add_repo(section, d) return repo_manager
def __init__(self): self.repos = OrderedDict()