annotate pyikriam/lconf.py @ 167:6ab01f709650

Fix semantic error
author Thinker K.F. Li <thinker@branda.to>
date Sun, 02 Nov 2008 01:00:35 +0800
parents d4b7d8f51e9f
children
rev   line source
158
d4b7d8f51e9f More exactly parser for $HOME/.eagleeye.pm
Thinker K.F. Li <thinker@branda.to>
parents: 64
diff changeset
1 import os, string
d4b7d8f51e9f More exactly parser for $HOME/.eagleeye.pm
Thinker K.F. Li <thinker@branda.to>
parents: 64
diff changeset
2 import re
d4b7d8f51e9f More exactly parser for $HOME/.eagleeye.pm
Thinker K.F. Li <thinker@branda.to>
parents: 64
diff changeset
3
d4b7d8f51e9f More exactly parser for $HOME/.eagleeye.pm
Thinker K.F. Li <thinker@branda.to>
parents: 64
diff changeset
4 _user_home = os.environ['HOME']
d4b7d8f51e9f More exactly parser for $HOME/.eagleeye.pm
Thinker K.F. Li <thinker@branda.to>
parents: 64
diff changeset
5 dfl_profile = os.path.join(_user_home, '.eagleeye.pm')
d4b7d8f51e9f More exactly parser for $HOME/.eagleeye.pm
Thinker K.F. Li <thinker@branda.to>
parents: 64
diff changeset
6 _reo_assign = re.compile('^\\$::([_a-zA-Z][_a-zA-Z0-9]+) *= *([\'"][^"]*[\'"]).*$')
d4b7d8f51e9f More exactly parser for $HOME/.eagleeye.pm
Thinker K.F. Li <thinker@branda.to>
parents: 64
diff changeset
7
d4b7d8f51e9f More exactly parser for $HOME/.eagleeye.pm
Thinker K.F. Li <thinker@branda.to>
parents: 64
diff changeset
8 def _real_load_conf(conf_o):
d4b7d8f51e9f More exactly parser for $HOME/.eagleeye.pm
Thinker K.F. Li <thinker@branda.to>
parents: 64
diff changeset
9 confs = [_reo_assign.match(line)
d4b7d8f51e9f More exactly parser for $HOME/.eagleeye.pm
Thinker K.F. Li <thinker@branda.to>
parents: 64
diff changeset
10 for line in conf_o
d4b7d8f51e9f More exactly parser for $HOME/.eagleeye.pm
Thinker K.F. Li <thinker@branda.to>
parents: 64
diff changeset
11 if line.startswith('$::')]
d4b7d8f51e9f More exactly parser for $HOME/.eagleeye.pm
Thinker K.F. Li <thinker@branda.to>
parents: 64
diff changeset
12 cd = dict([(mo.group(1), eval(mo.group(2)))
d4b7d8f51e9f More exactly parser for $HOME/.eagleeye.pm
Thinker K.F. Li <thinker@branda.to>
parents: 64
diff changeset
13 for mo in confs if mo])
d4b7d8f51e9f More exactly parser for $HOME/.eagleeye.pm
Thinker K.F. Li <thinker@branda.to>
parents: 64
diff changeset
14 return cd
d4b7d8f51e9f More exactly parser for $HOME/.eagleeye.pm
Thinker K.F. Li <thinker@branda.to>
parents: 64
diff changeset
15
64
19d2a7b175b3 Load configure data from .eagleeye.pm
kevin@localhost.localdomain
parents:
diff changeset
16 class LoadConfigfile(object):
158
d4b7d8f51e9f More exactly parser for $HOME/.eagleeye.pm
Thinker K.F. Li <thinker@branda.to>
parents: 64
diff changeset
17 def __init__(self, profile=dfl_profile):
d4b7d8f51e9f More exactly parser for $HOME/.eagleeye.pm
Thinker K.F. Li <thinker@branda.to>
parents: 64
diff changeset
18 prof_o = open(profile, 'r')
d4b7d8f51e9f More exactly parser for $HOME/.eagleeye.pm
Thinker K.F. Li <thinker@branda.to>
parents: 64
diff changeset
19 self.cd = _real_load_conf(prof_o)
d4b7d8f51e9f More exactly parser for $HOME/.eagleeye.pm
Thinker K.F. Li <thinker@branda.to>
parents: 64
diff changeset
20 pass
d4b7d8f51e9f More exactly parser for $HOME/.eagleeye.pm
Thinker K.F. Li <thinker@branda.to>
parents: 64
diff changeset
21 pass
64
19d2a7b175b3 Load configure data from .eagleeye.pm
kevin@localhost.localdomain
parents:
diff changeset
22
158
d4b7d8f51e9f More exactly parser for $HOME/.eagleeye.pm
Thinker K.F. Li <thinker@branda.to>
parents: 64
diff changeset
23 if __name__ == '__main__':
d4b7d8f51e9f More exactly parser for $HOME/.eagleeye.pm
Thinker K.F. Li <thinker@branda.to>
parents: 64
diff changeset
24 from StringIO import StringIO
d4b7d8f51e9f More exactly parser for $HOME/.eagleeye.pm
Thinker K.F. Li <thinker@branda.to>
parents: 64
diff changeset
25 conf = '''
d4b7d8f51e9f More exactly parser for $HOME/.eagleeye.pm
Thinker K.F. Li <thinker@branda.to>
parents: 64
diff changeset
26 $::user = "alsfjsf"; #lsfjslf
d4b7d8f51e9f More exactly parser for $HOME/.eagleeye.pm
Thinker K.F. Li <thinker@branda.to>
parents: 64
diff changeset
27 $::server = "fkljalfasf"; # sfjslf
d4b7d8f51e9f More exactly parser for $HOME/.eagleeye.pm
Thinker K.F. Li <thinker@branda.to>
parents: 64
diff changeset
28 $::pass = "lsfjslfsf";
d4b7d8f51e9f More exactly parser for $HOME/.eagleeye.pm
Thinker K.F. Li <thinker@branda.to>
parents: 64
diff changeset
29 '''
d4b7d8f51e9f More exactly parser for $HOME/.eagleeye.pm
Thinker K.F. Li <thinker@branda.to>
parents: 64
diff changeset
30 conf_o = StringIO(conf)
d4b7d8f51e9f More exactly parser for $HOME/.eagleeye.pm
Thinker K.F. Li <thinker@branda.to>
parents: 64
diff changeset
31 cd = _real_load_conf(conf_o)
d4b7d8f51e9f More exactly parser for $HOME/.eagleeye.pm
Thinker K.F. Li <thinker@branda.to>
parents: 64
diff changeset
32 print cd
d4b7d8f51e9f More exactly parser for $HOME/.eagleeye.pm
Thinker K.F. Li <thinker@branda.to>
parents: 64
diff changeset
33 pass