summaryrefslogtreecommitdiff
path: root/docs/source/generate_configs.py
diff options
context:
space:
mode:
authorPatrick Totzke <patricktotzke@gmail.com>2012-03-04 22:18:36 +0000
committerPatrick Totzke <patricktotzke@gmail.com>2012-03-04 22:18:36 +0000
commitffc711c405935976e1dbe4c2affbe778858a70ab (patch)
treee165bbbe4ee8f5443055ba6ca1aeb34720558f94 /docs/source/generate_configs.py
parent906155394d256510609390022711e13ac0b25b87 (diff)
doc: info on type/default config values
Diffstat (limited to 'docs/source/generate_configs.py')
-rwxr-xr-xdocs/source/generate_configs.py40
1 files changed, 31 insertions, 9 deletions
diff --git a/docs/source/generate_configs.py b/docs/source/generate_configs.py
index 96eb37c1..41fa9a08 100755
--- a/docs/source/generate_configs.py
+++ b/docs/source/generate_configs.py
@@ -4,29 +4,51 @@ HERE = os.path.dirname(__file__)
sys.path.append(os.path.join(HERE, '..', '..', '..'))
from alot.commands import COMMANDS
from configobj import ConfigObj
+from validate import Validator
import re
-def rewrite_scalarcomments(config, path, sort=False):
+def rewrite_entries(config, path, sec=None, sort=False):
file = open(path, 'w')
+
+ if sec == None:
+ sec = config
if sort:
- config.scalars.sort()
- for entry in config.scalars:
+ 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)
+
+ #print etype
description = '\n.. _%s:\n' % entry.replace('_', '-')
description += '\n.. describe:: %s\n\n' % entry
- comments = [config.inline_comments[entry]] + config.comments[entry]
+ comments = [sec.inline_comments[entry]] + sec.comments[entry]
for c in comments:
if c:
description += ' '*4 + re.sub('^\s*#\s*', '', c) + '\n'
+ description += '\n :type: %s\n' % etype
+
+ if default != None:
+ if etype in ['string', 'string_list'] and default != 'None':
+ description += ' :default: "%s"\n\n' % (default)
+ else:
+ description += ' :default: %s\n\n' % (default)
file.write(description)
file.close()
if __name__ == "__main__":
specpath = os.path.join(HERE, '..','..', 'alot', 'defaults', 'alot.rc.spec')
- config = ConfigObj(specpath)
+ config = ConfigObj(None, configspec=specpath, stringify=False, list_values=False)
+ config.validate(Validator())
alotrc_table_file = os.path.join(HERE, 'configuration', 'alotrc_table.rst')
- rewrite_scalarcomments(config, alotrc_table_file, sort=True)
+ rewrite_entries(config.configspec, alotrc_table_file, sort=True)
- rewrite_scalarcomments(config['accounts']['__many__'],
- os.path.join(HERE, 'configuration',
- 'accounts_table.rst'))
+ rewrite_entries(config, os.path.join(HERE, 'configuration',
+ 'accounts_table.rst'),
+ sec=config.configspec['accounts']['__many__'])