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