def rewrite_entries(config, path, specpath, sec=None, sort=False): file = open(path, 'w') file.write(NOTE % specpath) if sec is None: sec = config if sort: sec.scalars.sort() for entry in sec.scalars: v = Validator() #config.validate(v) #print config[entry] #etype = re.sub('\(.*\)','', config[entry]) ##if etype == 'option': etype, eargs, ekwargs, default = v._parse_check(sec[entry]) if default is not None: default = config._quote(default) if etype == 'gpg_key_hint': etype = 'string' description = '\n.. _%s:\n' % entry.replace('_', '-') description += '\n.. describe:: %s\n\n' % entry comments = [sec.inline_comments[entry]] + sec.comments[entry] for c in comments: if c: description += ' ' * 4 + re.sub('^\s*#', '', c) description = description.rstrip(' ') + '\n' if etype == 'option': description += '\n :type: option, one of %s\n' % eargs else: if etype == 'force_list': etype = 'string list' description += '\n :type: %s\n' % etype if default is not None: default = default.replace('*', '\\*') if etype in ['string', 'string_list', 'gpg_key_hint' ] and default != 'None': description += ' :default: "%s"\n\n' % (default) else: description += ' :default: %s\n\n' % (default) file.write(description) file.close()
def genrst(app): logging.info("Generating rst files for xoa options") srcdir = app.env.srcdir file_table = os.path.join(srcdir, app.config.genoptions_table) file_declarations = os.path.join( srcdir, app.config.genoptions_declarations) for ff in file_table, file_declarations: fd = os.path.dirname(ff) if not os.path.exists(fd): os.makedirs(fd) cfgspecs = ConfigObj( xoa.CONFIG_SPECS.split("\n"), list_values=False, interpolation=False, raise_errors=True, file_error=True, ) validator = Validator() ftable = open(file_table, 'w') ftable.write(table_header) fdecl = open(file_declarations, 'w') for sec in cfgspecs.sections: for optname, optspecs in cfgspecs[sec].items(): opttype, fun_args, fun_kwargs, optdef = validator._parse_check( optspecs) optdesc = cfgspecs[sec].inline_comments[optname].strip("# ") optdesc = optdesc.capitalize() optname = f"{sec}.{optname}" ftable.write(table_line_format.format(**locals())) fdecl.write(decl_format.format(**locals())) ftable.close() fdecl.close()
def rewrite_entries(config, path, specpath, sec=None, sort=False): file = open(path, 'w') file.write(NOTE % specpath) if sec is None: sec = config if sort: sec.scalars.sort() for entry in sec.scalars: v = Validator() #config.validate(v) #print config[entry] #etype = re.sub('\(.*\)','', config[entry]) ##if etype == 'option': etype, eargs, ekwargs, default = v._parse_check(sec[entry]) if default is not None: default = config._quote(default) if etype == 'gpg_key_hint': etype = 'string' description = '\n.. _%s:\n' % entry.replace('_', '-') description += '\n.. describe:: %s\n\n' % entry comments = [sec.inline_comments[entry]] + sec.comments[entry] for c in comments: if c: description += ' '*4 + re.sub('^\s*#', '', c) description = description.rstrip(' ') + '\n' if etype == 'option': description += '\n :type: option, one of %s\n' % eargs else: if etype == 'force_list': etype = 'string list' description += '\n :type: %s\n' % etype if default is not None: default = default.replace('*','\\*') if etype in ['string', 'string_list', 'gpg_key_hint'] and default != 'None': description += ' :default: "%s"\n\n' % (default) else: description += ' :default: %s\n\n' % (default) file.write(description) file.close()
def rewrite_entries(config, path, specpath, sec=None, sort=False): file = open(path, "w") file.write(NOTE % specpath) if sec == None: sec = config if sort: sec.scalars.sort() for entry in sec.scalars: v = Validator() # config.validate(v) # print config[entry] # etype = re.sub('\(.*\)','', config[entry]) ##if etype == 'option': etype, eargs, ekwargs, default = v._parse_check(sec[entry]) if default is not None: default = config._quote(default) if etype == "gpg_key_hint": etype = "string" description = "\n.. _%s:\n" % entry.replace("_", "-") description += "\n.. describe:: %s\n\n" % entry comments = [sec.inline_comments[entry]] + sec.comments[entry] for c in comments: if c: description += " " * 4 + re.sub("^\s*#", "", c) + "\n" if etype == "option": description += "\n :type: option, one of %s\n" % eargs else: if etype == "force_list": etype = "string list" description += "\n :type: %s\n" % etype if default != None: default = default.replace("*", "\\*") if etype in ["string", "string_list", "gpg_key_hint"] and default != "None": description += ' :default: "%s"\n\n' % (default) else: description += " :default: %s\n\n" % (default) file.write(description) file.close()