Mercurial > hg > martINI
annotate martini/config.py @ 10:66d11212175d
this should be ordered too
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Tue, 23 Aug 2016 09:26:27 -0700 |
parents | 77c7556fa8e0 |
children | c77259f467a3 |
rev | line source |
---|---|
0
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
2 |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
3 import os |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
4 import sys |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
5 import urllib2 |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
6 |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
7 from ConfigParser import ConfigParser |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
8 from ConfigParser import InterpolationMissingOptionError |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
9 from ConfigParser import MissingSectionHeaderError |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
10 from ConfigParser import NoOptionError |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
11 from StringIO import StringIO |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
12 |
9 | 13 try: |
14 from collections import OrderedDict | |
15 except ImportError: | |
16 from odict import OrderedDict | |
17 | |
18 | |
0
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
19 def file_pointer(resource): |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
20 """returns a file-like object given a string""" |
9 | 21 # XXX could go in utils.py |
0
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
22 |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
23 if not isinstance(resource, basestring): |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
24 # assume resource is already a file-like object |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
25 return resource |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
26 |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
27 if os.path.exists(resource): |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
28 return file(resource) |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
29 if sum([resource.startswith(http) for http in 'http://', 'https://']): |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
30 return urllib2.urlopen(resource) |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
31 return StringIO(resource) |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
32 |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
33 |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
34 class ConfigMunger(ConfigParser): |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
35 """combine configuration from .ini files""" |
10 | 36 |
0
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
37 def __init__(self, *conf, **kw): |
8
81aed4352851
make martini work with an ordered dictionary
Jeff Hammel <jhammel@mozilla.com>
parents:
7
diff
changeset
|
38 ConfigParser.__init__(self, defaults=kw.get('defaults',{}), |
81aed4352851
make martini work with an ordered dictionary
Jeff Hammel <jhammel@mozilla.com>
parents:
7
diff
changeset
|
39 dict_type=OrderedDict) |
7 | 40 self.optionxform = str |
0
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
41 self.read(*conf) |
10 | 42 |
0
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
43 def __getitem__(self, section): |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
44 """ |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
45 return an object with __getitem__ defined appropriately |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
46 to allow referencing like self['foo']['bar'] |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
47 """ |
10 | 48 return OrderedDict(self.items(section)) |
0
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
49 |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
50 def get(self, section, option, default=None, raw=False, vars=None): |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
51 try: |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
52 value = ConfigParser.get(self, section, option, raw, vars) |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
53 except NoOptionError: |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
54 return default |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
55 return value |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
56 |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
57 def set(self, section, option, value): |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
58 if section not in self.sections(): |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
59 self.add_section(section) |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
60 ConfigParser.set(self, section, option, value) |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
61 |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
62 def move_section(self, section, newname): |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
63 if self.has_section(section): |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
64 _section = self[section] |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
65 self.remove_section(section) |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
66 else: |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
67 _section = {} |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
68 self.read({newname: _section}) |
9 | 69 |
0
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
70 def dict(self): |
9 | 71 """return a dictionary of dictionaries; |
0
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
72 the outer with keys of section names; |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
73 the inner with keys, values of the section""" |
9 | 74 return OrderedDict([(section, self[section]) |
75 for section in self.sections()]) | |
0
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
76 |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
77 def read(self, *ini): |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
78 for _ini in ini: |
9 | 79 if isinstance(_ini, (dict, OrderedDict)): |
0
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
80 for section, contents in _ini.items(): |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
81 for option, value in contents.items(): |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
82 self.set(section, option, value) |
9 | 83 elif isinstance(_ini, (list, tuple)): |
0
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
84 |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
85 # ensure list or tuple of 3-tuples |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
86 assert len([option for option in _ini |
9 | 87 if isinstance(option, tuple) |
0
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
88 and len(option) == 3]) |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
89 |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
90 for section, option, value in _ini: |
9 | 91 self.set(section, option, value) |
0
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
92 else: |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
93 fp = file_pointer(_ini) |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
94 try: |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
95 self.readfp(fp) |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
96 except MissingSectionHeaderError: |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
97 fp.seek(0) |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
98 fp = StringIO("[DEFAULTS]\n" + fp.read()) |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
99 self.readfp(fp) |
9 | 100 |
0
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
101 def missing(self): |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
102 """returns missing variable names""" |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
103 |
9 | 104 missing = set() |
0
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
105 for section in self.sections(): |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
106 for key, val in self.items(section, raw=True): |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
107 try: |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
108 self.get(section, key) |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
109 except InterpolationMissingOptionError, e: |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
110 missing.add(e.reference) |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
111 return missing |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
112 |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
113 def tuples(self): |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
114 """ |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
115 return options in format appropriate to trac: |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
116 [ (section, option, value) ] |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
117 """ |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
118 options = [] |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
119 for section in self.sections(): |
9 | 120 options.extend([(section,) + item |
0
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
121 for item in self.items(section)]) |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
122 return options |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
123 |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
124 def write(self, fp=sys.stdout, raw=False, sorted=True, vars=None): |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
125 sections = self.sections() |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
126 if sorted: |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
127 sections.sort() |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
128 |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
129 for section in sections: |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
130 print >> fp, '[%s]' % section |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
131 options = self.options(section) |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
132 if sorted: |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
133 options.sort() |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
134 for option in options: |
6 | 135 print >> fp, "%s = %s" % (option, self.get(section, option, raw=raw, vars=vars)) |
0
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
136 if section != sections[-1]: |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
137 print >> fp |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
138 |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
139 if __name__ == '__main__': |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
140 import sys |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
141 from optparse import OptionParser |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
142 parser = OptionParser() |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
143 parser.add_option('--missing', action="store_true", default=False, |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
144 help="list missing template variables") |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
145 munger = ConfigMunger() |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
146 options, args = parser.parse_args() |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
147 munger.read(*args) |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
148 if options.missing: |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
149 for missing in munger.missing(): |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
150 print missing |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
151 else: |
3c3522ce6e3a
initial import of martINI from https://svn.openplans.org/svn/standalone/martINI/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
152 munger.write(sys.stdout) |