1#!/usr/bin/python 2# generate man config documentation from mcelog.conf example 3# genconfig.py mcelog.conf intro.html 4import sys 5import re 6import string 7import argparse 8 9ap = argparse.ArgumentParser(description="generate man config documentation from mcelog.conf example") 10ap.add_argument('config', type=argparse.FileType('r'), help="mcelog example config file") 11ap.add_argument('intro', type=argparse.FileType('r'), help="intro file") 12args = ap.parse_args() 13 14def parse(f): 15 lineno = 1 16 explanation = 0 17 header = 1 18 for line in f: 19 lineno += 1 20 21 # skip first comment 22 if header: 23 if not re.match('^#', line): 24 header = 0 25 continue 26 27 # explanation 28 m = re.match('^#\s(.*)', line) 29 if m: 30 explanation += 1 31 s = m.group(1) 32 if explanation == 1: 33 s = string.capitalize(s) 34 print s 35 continue 36 37 if explanation: 38 print ".PP" 39 explanation = 0 40 41 # empty line: new option 42 if re.match('\s+', line): 43 new_option() 44 continue 45 # group 46 m = re.match('\[(.*)\]', line) 47 if m: 48 start_group(m.group(1)) 49 continue 50 # config option 51 m = re.match('^(#?)([a-z-]+) = (.*)', line) 52 if m: 53 config_option(m.group(1), m.group(2), m.group(3)) 54 continue 55 print >>sys.stderr, "Unparseable line %d" % (lineno-1) 56 57def config_option(enabled, name, value): 58 print ".B %s = %s" % (name, value) 59 print ".PP" 60 61def start_group(name): 62 print ".SS \"The %s config section\"" % (name) 63 64def new_option(): 65 print ".PP" 66 67 68print """ 69.\\" Auto generated mcelog.conf manpage. Do not edit. 70.TH "mcelog.conf" 5 "mcelog" 71""" 72 73print args.intro.read() 74parse(args.config) 75print """ 76.SH SEE ALSO 77.BR mcelog (8), 78.BR mcelog.triggers (5) 79.B http://www.mcelog.org 80""" 81