Mercurial > hg > config
view python/prefs.py @ 694:ebca6d85213a
File "/usr/lib/python3/dist-packages/IPython/config/__init__.py", line 16, in <module>
from .application import *
File "/usr/lib/python3/dist-packages/IPython/config/application.py", line 31, in <module>
from IPython.config.configurable import SingletonConfigurable
File "/usr/lib/python3/dist-packages/IPython/config/configurable.py", line 33, in <module>
from IPython.utils.text import indent, wrap_paragraphs
File "/usr/lib/python3/dist-packages/IPython/utils/text.py", line 28, in <module>
from IPython.external.path import path
File "/usr/lib/python3/dist-packages/IPython/external/path/__init__.py", line 2, in <module>
from path import *
File "/home/jhammel/python/path.py", line 25
print root(path)
^
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Wed, 09 Jul 2014 16:26:49 -0700 |
parents | 31a41264d51f |
children |
line wrap: on
line source
import re comment = re.compile('/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/', re.MULTILINE) def read(filename): token = '##//' # magical token lines = [i.strip() for i in file(filename).readlines() if i.strip()] retval = {} _lines = [] for line in lines: if line.startswith('#'): continue if '//' in line: line = line.replace('//', token) _lines.append(line) string = '\n'.join(_lines) string = re.sub(comment, '', string) def pref(a, b): retval[a] = b lines = [i.strip().rstrip(';') for i in string.split('\n') if i.strip()] for line in lines: try: _globals = {'retval': retval, 'pref': pref, 'user_pref': pref, 'true': True, 'false': False} eval(line, _globals, {}) except SyntaxError: print line import pdb; pdb.set_trace() for key in retval: if isinstance(retval[key], basestring) and token in retval[key]: retval[key] = retval[key].replace(token, '//') return retval def write(filename, prefs, pref_string='user_pref("%s", %s);'): f = file(filename, 'w') for key, value in prefs.items(): if value is True: print >> f, pref_string % (key, 'true') elif value is False: print >> f, pref_string % (key, 'true') elif isinstance(value, basestring): print >> f, pref_string % (key, repr(string(value))) else: print >> f, pref_string % (key, value) # should be numeric! f.close() if __name__ == '__main__': import sys if not sys.argv[1:]: sys.exit(1) print read(sys.argv[1])