def _cleanup_config(config, skip_comments=False): errors = config.validate(VALIDATOR, preserve_errors=True, copy=True) # First flag any required parameters for entry in flatten_errors(config, errors): section_list, key, error = entry section_name, = section_list if error is False: config[section_name][key] = '' config[section_name].comments[key].append('REQUIRED') elif error: print("Bad configspec generated error", error, file=sys.stderr) pending_comments = [] for section in list(config): if pending_comments: if skip_comments: comments = [] else: comments = config.comments.get(section, []) comments = pending_comments + comments config.comments[section] = comments del pending_comments[:] for key, value in config[section].items(): if value is None: if not skip_comments: pending_comments.extend(config[section].comments.get( key, [])) pending_comments.append('%s = "" # no default' % key) del config[section][key] else: if skip_comments: del config[section].comments[key][:] if pending_comments: if skip_comments: comments = [] else: comments = config[section].comments.get(key, []) comments = pending_comments + comments config[section].comments[key] = comments del pending_comments[:] if value is True or value is False: config[section][key] = 'yes' if value else 'no' if pending_comments: if skip_comments: config.final_comment = pending_comments else: config.final_comment = pending_comments + config.final_comment # drop initial whitespace config.initial_comment = [] # insert a blank between [holland:backup] and first section try: config.comments[config.sections[1]].insert(0, '') except IndexError: pass
def _cleanup_config(self, config, skip_comments=False): errors = config.validate(validator, preserve_errors=True,copy=True) # First flag any required parameters for entry in flatten_errors(config, errors): section_list, key, error = entry section_name, = section_list if error is False: config[section_name][key] = '' config[section_name].comments[key].append('REQUIRED') elif error: print >>sys.stderr, "Bad configspec generated error", error pending_comments = [] for section in list(config): if pending_comments: if skip_comments: comments = [] else: comments = config.comments.get(section, []) comments = pending_comments + comments config.comments[section] = comments del pending_comments[:] for idx, (key, value) in enumerate(config[section].items()): if value is None: if not skip_comments: pending_comments.extend(config[section].comments.get(key, [])) pending_comments.append('%s = "" # no default' % key) del config[section][key] else: if skip_comments: del config[section].comments[key][:] if pending_comments: if skip_comments: comments = [] else: comments = config[section].comments.get(key, []) comments = pending_comments + comments config[section].comments[key] = comments del pending_comments[:] if value is True or value is False: config[section][key] = ['no','yes'][value] if pending_comments: if skip_comments: config.final_comment = pending_comments else: config.final_comment = pending_comments + config.final_comment # drop initial whitespace config.initial_comment = [] # insert a blank between [holland:backup] and first section try: config.comments[config.sections[1]].insert(0, '') except IndexError: pass
def _report_errors(cfg, errors): for entry in flatten_errors(cfg, errors): (section, ), key, error = entry param = '.'.join((section, key)) if key is not None: pass else: param = ' '.join((section, '[missing section]')) if not error: error = 'Missing value or section' print(param, ' = ', error, file=sys.stderr)
def _report_errors(cfg, errors): for entry in flatten_errors(cfg, errors): (section,), key, error = entry param = '.'.join((section, key)) if key is not None: pass else: param = ' '.join((section, '[missing section]')) if error == False: error = 'Missing value or section' print >>sys.stderr, param, ' = ', error
def _report_errors(cfg, errors): for entry in flatten_errors(cfg, errors): (section,), key, error = entry param = ".".join((section, key)) if key is not None: pass else: param = " ".join((section, "[missing section]")) if error == False: error = "Missing value or section" print >>sys.stderr, param, " = ", error
def _report_errors(cfg, errors): for entry in flatten_errors(cfg, errors): (section, ), key, error = entry param = ".".join((section, key)) if key is not None: pass else: param = " ".join((section, "[missing section]")) if not error: error = "Missing value or section" print(param, " = ", error, file=sys.stderr)
def _cleanup_config(self, config): errors = config.validate(validator, preserve_errors=True,copy=True) # First flag any required parameters for entry in flatten_errors(config, errors): section_list, key, error = entry section_name, = section_list if error is False: config[section_name][key] = '' config[section_name].comments[key].append('REQUIRED') elif error: print >>sys.stderr, "Bad configspec generated error", error none_keys = [] config.walk(self._filter_none, raise_errors=True, filter_list=none_keys) for sect, key in none_keys: if sect.comments.get(key): comment_list = self._next_key_comments(sect, key) map(lambda x: comment_list.insert(0, x), sect.comments[key]) del sect[key]