diff options
author | Patrick Totzke <patricktotzke@gmail.com> | 2012-07-08 21:28:58 +0100 |
---|---|---|
committer | Patrick Totzke <patricktotzke@gmail.com> | 2012-07-08 21:28:58 +0100 |
commit | 3e88853016b4d9234b67c4a8a665e08e601d3b7e (patch) | |
tree | 030eb7503b25e78cfd875655f10bfb088391c32c /extra | |
parent | b96cc4890e92442c6a2bd1f9faca89da92dcd368 (diff) |
extra: add tagsections_convert.py
a script that converts 'tags' config subsections
that determine the format tagstrings are represented to the new format.
Diffstat (limited to 'extra')
-rwxr-xr-x | extra/tagsections_convert.py | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/extra/tagsections_convert.py b/extra/tagsections_convert.py new file mode 100755 index 00000000..4dbf4554 --- /dev/null +++ b/extra/tagsections_convert.py @@ -0,0 +1,63 @@ +#!/usr/bin/python + +from configobj import ConfigObj +import argparse +import sys +import re + + +def get_leaf_value(cfg, path, fallback=''): + if len(path) == 1: + if isinstance(cfg, ConfigObj): + if path[0] not in cfg.scalars: + return fallback + else: + return cfg[path[0]] + else: + if path[0] not in cfg: + return fallback + else: + return cfg[path[0]] + else: + if path[0] in cfg: + scfg = cfg[path[0]] + sp = path[1:] + return get_leaf_value(scfg, sp, fallback) + else: + return None + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description='update alot theme files') + parser.add_argument('configfile', type=argparse.FileType('r'), + help='theme file to convert') + parser.add_argument('-o', type=argparse.FileType('w'), dest='out', + help='destination', default=sys.stdout) + args = parser.parse_args() + + cfg = ConfigObj(args.configfile) + out = args.out + print args + + def is_256(att): + r = r'(g\d{1,3}(?!\d))|(#[0-9A-Fa-f]{3}(?![0-9A-Fa-f]))' + return re.search(r, att) + + if 'tags' in cfg: + for tag in cfg['tags'].sections: + sec = cfg['tags'][tag] + att = [''] * 6 + if 'fg' in sec: + fg = sec['fg'] + if not is_256(fg): + att[2] = fg + att[4] = fg + del(sec['fg']) + if 'bg' in sec: + bg = sec['bg'] + if not is_256(bg): + att[3] = bg + att[5] = bg + del(sec['bg']) + sec['normal'] = att + cfg.write(out) |