def parse_leases(**kwargs): global PARSED_LEASES to_parse = kwargs.get('to_parse') filename = kwargs.get('filename', config.dhcpd_leases) file_opts = getattr(config, 'file_opts', {}) if to_parse is None: f = get_opener(filename, **file_opts) with f: to_parse = f.read() if isinstance(to_parse, basestring): to_parse = to_parse.splitlines() def iter_lines(start): for i in range(start, len(to_parse)): yield i, to_parse[i] def find_lease_lines(start_line=None): if start_line is None: start_line = 0 lease_lines = None for i, line in iter_lines(start_line): if 'lease' in line and '{' in line: lease_lines = [] lease_lines.append(line) elif '}' in line: if lease_lines is not None: yield lease_lines lease_lines = None elif lease_lines is not None: lease_lines.append(line) for lines in find_lease_lines(): obj = LeaseConf._parse(lines) PARSED_LEASES.append(obj) return PARSED_LEASES
def parse_leases(**kwargs): global PARSED_LEASES to_parse = kwargs.get("to_parse") filename = kwargs.get("filename", config.dhcpd_leases) file_opts = getattr(config, "file_opts", {}) if to_parse is None: f = get_opener(filename, **file_opts) with f: to_parse = f.read() if isinstance(to_parse, basestring): to_parse = to_parse.splitlines() def iter_lines(start): for i in range(start, len(to_parse)): yield i, to_parse[i] def find_lease_lines(start_line=None): if start_line is None: start_line = 0 lease_lines = None for i, line in iter_lines(start_line): if "lease" in line and "{" in line: lease_lines = [] lease_lines.append(line) elif "}" in line: if lease_lines is not None: yield lease_lines lease_lines = None elif lease_lines is not None: lease_lines.append(line) for lines in find_lease_lines(): obj = LeaseConf._parse(lines) PARSED_LEASES.append(obj) return PARSED_LEASES
def parse_conf(**kwargs): global PARSED_NETWORKS to_parse = kwargs.get('to_parse') filename = kwargs.get('filename', config.dhcpd_conf) return_parsed = kwargs.get('return_parsed') file_opts = getattr(config, 'file_opts', {}) if to_parse is None: f = get_opener(filename, **file_opts) with f: to_parse = f.read() root_bracket = NestedBracket(text=to_parse) for bracket in root_bracket.children: if 'shared-network' in bracket.lines[0]: nobj = NetworkConf._parse(bracket=bracket) elif 'subnet' in bracket.lines[0]: sobj = SubnetConf._parse(bracket=bracket) nobj = sobj.parent else: nobj = None if nobj is not None: PARSED_NETWORKS.append(nobj) if return_parsed: return PARSED_NETWORKS, root_bracket return PARSED_NETWORKS
def parse_conf(**kwargs): global PARSED_NETWORKS to_parse = kwargs.get("to_parse") filename = kwargs.get("filename", config.dhcpd_conf) return_parsed = kwargs.get("return_parsed") file_opts = getattr(config, "file_opts", {}) if to_parse is None: f = get_opener(filename, **file_opts) with f: to_parse = f.read() root_bracket = NestedBracket(text=to_parse) for bracket in root_bracket.children: if "shared-network" in bracket.lines[0]: nobj = NetworkConf._parse(bracket=bracket) elif "subnet" in bracket.lines[0]: sobj = SubnetConf._parse(bracket=bracket) nobj = sobj.parent else: nobj = None if nobj is not None: PARSED_NETWORKS.append(nobj) if return_parsed: return PARSED_NETWORKS, root_bracket return PARSED_NETWORKS