diff options
author | Lucas Hoffmann <l-m-h@web.de> | 2017-07-14 14:21:46 +0200 |
---|---|---|
committer | Lucas Hoffmann <l-m-h@web.de> | 2017-07-31 18:50:27 +0200 |
commit | b92a122f330caed2d4ce22b1ac4aab3f1b3e7011 (patch) | |
tree | a23f984464c883ff382eb6b3246f9e8bd5da02db /docs/source/generate_configs.py | |
parent | 78d069ea38277721e31b621daf8df0d8b8174041 (diff) |
Clean up doc source generators
Diffstat (limited to 'docs/source/generate_configs.py')
-rwxr-xr-x | docs/source/generate_configs.py | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/docs/source/generate_configs.py b/docs/source/generate_configs.py index 2b9cc806..a5427792 100755 --- a/docs/source/generate_configs.py +++ b/docs/source/generate_configs.py @@ -1,12 +1,18 @@ from __future__ import absolute_import + import sys import os +import re + +from configobj import ConfigObj +from validate import Validator + HERE = os.path.dirname(__file__) sys.path.insert(0, os.path.join(HERE, '..', '..')) + from alot.commands import COMMANDS -from configobj import ConfigObj -from validate import Validator -import re + + NOTE = """ .. CAUTION: THIS FILE IS AUTO-GENERATED from the inline comments of specfile %s. @@ -14,6 +20,8 @@ NOTE = """ If you want to change its content make your changes to that spec to ensure they woun't be overwritten later. """ + + def rewrite_entries(config, path, specpath, sec=None, sort=False): file = open(path, 'w') file.write(NOTE % specpath) @@ -24,10 +32,6 @@ def rewrite_entries(config, path, specpath, sec=None, sort=False): 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) @@ -49,22 +53,28 @@ def rewrite_entries(config, path, specpath, sec=None, sort=False): 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': + 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() + if __name__ == "__main__": - specpath = os.path.join(HERE, '..','..', 'alot', 'defaults', 'alot.rc.spec') - config = ConfigObj(None, configspec=specpath, stringify=False, list_values=False) + specpath = os.path.join(HERE, '..', '..', 'alot', 'defaults', + 'alot.rc.spec') + config = ConfigObj(None, configspec=specpath, stringify=False, + list_values=False) config.validate(Validator()) alotrc_table_file = os.path.join(HERE, 'configuration', 'alotrc_table') - rewrite_entries(config.configspec, alotrc_table_file, 'defaults/alot.rc.spec', sort=True) + rewrite_entries(config.configspec, alotrc_table_file, + 'defaults/alot.rc.spec', sort=True) - rewrite_entries(config, os.path.join(HERE, 'configuration', 'accounts_table'), + rewrite_entries(config, + os.path.join(HERE, 'configuration', 'accounts_table'), 'defaults/alot.rc.spec', sec=config.configspec['accounts']['__many__']) |