[137] | 1 | # |
---|
[242] | 2 | import os,types |
---|
| 3 | from StringIO import StringIO |
---|
| 4 | from ConfigParser import SafeConfigParser |
---|
| 5 | |
---|
| 6 | from qthemetemplate.qplone3_theme import qPlone3Theme |
---|
| 7 | |
---|
| 8 | def write_map(cmd, basename, filename, force=False): |
---|
| 9 | argname = os.path.splitext(basename)[0] |
---|
| 10 | value = getattr(cmd.distribution, argname, None) |
---|
| 11 | |
---|
| 12 | if value: |
---|
| 13 | config = SafeConfigParser() |
---|
| 14 | config.add_section('qplone3_theme') |
---|
| 15 | for name, val in value.items(): |
---|
| 16 | val = val and str(val) or '' |
---|
| 17 | config.set('qplone3_theme', name, val) |
---|
| 18 | |
---|
| 19 | strvalue = StringIO() |
---|
| 20 | config.write(strvalue) |
---|
| 21 | value = strvalue.getvalue() |
---|
| 22 | |
---|
| 23 | cmd.write_or_delete_file(argname, filename, value, force) |
---|
| 24 | |
---|
| 25 | |
---|
| 26 | def assert_dict(dist, attr, value): |
---|
| 27 | """Verify that value is a dict or None""" |
---|
| 28 | try: |
---|
| 29 | assert type(value) == types.DictType |
---|
| 30 | except (TypeError,ValueError,AttributeError,AssertionError): |
---|
| 31 | raise DistutilsSetupError( |
---|
| 32 | "%r must be a dict (got %r)" % (attr,value) |
---|
| 33 | ) |
---|