Package: collective.mtrsetup
collective.mtrsetupcollective.mtrsetup provides a GenericSetup extension for importing and
exporting mimetypes to / from the mimetypes registry.How to useAddcollective.mtrsetupas dependency to yoursetup.pyAdd a zcml-include to yourconfigure.zcmlordependency.zcmlAdd a dependency toprofile-collective.mtrsetup:defaultto yourmetadata.xmlin your generic setup profileCreate amimetypes.xmlas showed below in your generic setup profileOpenOffice / Office 2007There is a additional generic setup profile provided in this
package (profile-collective.mtrsetup:default) which adds icons for
OpenOffice (with backwards compatiblity to StarOffice) and adds the
already used ms-office-icons to the new office 2007 mimetypes.
The official Office 2007 icons are not added because of the license.ExamplesHere are some examples of how to use it.Setup some testing stuff:>>> from collective.mtrsetup.tests.base import purge_registry
>>> from collective.mtrsetup.tests.base import import_mimetypes_registry
>>> from collective.mtrsetup.tests.base import export_mimetypes_registry
>>> from zope.component.hooks import getSite>>> portal = getSite()
>>> registry = portal.mimetypes_registry
>>> purge_registry(registry)
>>> len(registry.mimetypes())
0We can add new mimetypes with a simple mimetype tag in amimetypes.xmlin our generic setup
profile:>>> filedata = """
... <?xml version="1.0"?>
... <object name="mimetypes_registry" meta_type="MimeTypes Registry">
...  <mimetype name="Any type" mimetypes="image/any"
...            extensions="any" globs="*.any" binary="True"
...            icon_path="àny.png" />
... </object>
... """.strip()
>>> import_mimetypes_registry(registry, filedata)
[(20, 'mimetypes', 'Mimetype imported: <DOM Element: object at ...>')]Now we have just one mimetype correctly configured>>> registry.list_mimetypes()
['image/any']
>>> image_any = registry.lookup('image/any')
>>> image_any
(<mimetype image/any>,)
>>> print image_any[0].icon_path
àny.pngNow we should be able to export the current configuration:>>> print export_mimetypes_registry(registry)
<?xml version="1.0"...?>
<object name="mimetypes_registry" meta_type="MimeTypes Registry">
  <mimetype name="Any type" binary="True" extensions="any" globs="*.any"
      icon_path="àny.png" mimetypes="image/any"/>
</object>We can also just modify a existing one:>>> filedata = """
... <object name="mimetypes_registry" meta_type="MimeTypes Registry">
...  <mimetype name="Any type" mimetypes="image/any image/another" />
... </object>
... """.strip()
>>> import_mimetypes_registry(registry, filedata)
[(20, 'mimetypes', 'Mimetype imported: <DOM Element: object at ...>')]The above notiation just updates the mimetype record, whereimage/any is the first
mimetype:>>> print export_mimetypes_registry(registry)
<?xml version="1.0"...?>
<object name="mimetypes_registry" meta_type="MimeTypes Registry">
  <mimetype name="Any type" binary="True" extensions="any" globs="*.any"
      icon_path="àny.png" mimetypes="image/any image/another"/>
</object>Finally we can delete a mimetype by just adding the delete flag:>>> filedata = """
... <object name="mimetypes_registry" meta_type="MimeTypes Registry">
...  <mimetype name="Any type" mimetypes="image/any" delete="True" />
... </object>
... """.strip()
>>> import_mimetypes_registry(registry, filedata)
[(20, 'mimetypes', 'Mimetype imported: <DOM Element: object at ...>')]
>>> print export_mimetypes_registry(registry)
<?xml version="1.0"...?>
<object name="mimetypes_registry" meta_type="MimeTypes Registry"/>You have to add at least one mimetype, otherwise the import will fail:>>> filedata = """
... <object name="mimetypes_registry" meta_type="MimeTypes Registry">
...  <mimetype mimetypes="" />
... </object>
... """.strip()
>>> import_mimetypes_registry(registry, filedata)
[(30, 'mimetypes', u'Require attributes: "mimetypes" for <mimetype mimetypes=""/>'), (20, 'mimetypes', 'Mimetype imported: <DOM Element: object at ...>')]Changelog1.6.0 (2019-10-23)Add Plone 5.1 support by replacing the old PloneTestCase with plone.app.testing [mathias.leimgruber]Drop Plone 4.1 support [mathias.leimgruber]1.5.4 (2017-07-31)Remove z3c.autoinclude:includeDependencies. [jone]1.5.3 (2017-04-05)The mimetype values should be string not unicode,
especially for the icon_path
[ale-rt]1.5.2 (2014-06-20)Fixed mimetype icon URLs to be relative
and not absolute from root
[keul]1.5.1 (2014-01-02)Added xmind mimetype in example profile.
[thomasdesvenain]1.5 (2013-08-26)Added mmap mimetype in example profile.
[thomasdesvenain]1.4.1 (2012-12-21)Fixed release (fixed MANIFEST.in)
[thomasdesvenain]1.4 (2012-12-21)Add csv mimetype in example profile.
[thomasdesvenain]1.3Add rtf mimetype with icon in example profile.
[thomasdesvenain]1.21.1In some Plone 3 setups “GenericSetup.mimetypes Require attributes”
warning appears, fixed by adding all required attr to a mimetype record.
[07.02.2011, mathias.leimgruber]Added record for MS Project (Icon not included)
[07.02.2011, mathias.leimgruber]1.0Updated MANIFEST.in: added docs directory to release
[09.08.2010, jbaumann]1.0a2Updated README.txt (rest)
[12.04.2010, jbaumann]1.0a1Added updates for OpenOffice mimetypes (added new icons) and for Office 2007
mimetypes (using the old office-like icons).
[12.04.2010, jbaumann]Assuerd that the GS import/export adapter works on both, plone3 and plone4.
Plone3’s getToolByName returns the Tool, with plone4 it returns the Utility. The Tool and
the Utility do not have the same interfaces and plone3 crashes when using the old-style
utility interfaces for adapter registration - so we need to use a zcml:condition.
[12.04.2010, jbaumann]Implemented exporting, added tests
[09.04.2010, jbaumann]Improved testing system
[09.04.2010, jbaumann]Initial implementation
[08.04.2010, jbaumann]