|
1 # |
|
2 # Copyright (c) 2008-2015 Thierry Florac <tflorac AT ulthar.net> |
|
3 # All Rights Reserved. |
|
4 # |
|
5 # This software is subject to the provisions of the Zope Public License, |
|
6 # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. |
|
7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED |
|
8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS |
|
10 # FOR A PARTICULAR PURPOSE. |
|
11 # |
|
12 |
|
13 __docformat__ = 'restructuredtext' |
|
14 |
|
15 |
|
16 # import standard library |
|
17 |
|
18 # import interfaces |
|
19 from pyams_media.interfaces import IMediaConversionUtility, CONVERTER_NAME |
|
20 from pyams_utils.interfaces.site import ISiteGenerations |
|
21 from zope.site.interfaces import INewLocalSite |
|
22 |
|
23 # import packages |
|
24 from pyams_media.utility import MediaConversionUtility |
|
25 from pyams_utils.registry import utility_config |
|
26 from pyams_utils.site import check_required_utilities |
|
27 from pyramid.events import subscriber |
|
28 |
|
29 |
|
30 REQUIRED_UTILITIES = ((IMediaConversionUtility, '', MediaConversionUtility, CONVERTER_NAME), ) |
|
31 |
|
32 |
|
33 @subscriber(INewLocalSite) |
|
34 def handle_new_local_site(event): |
|
35 """Create a new conversion utility when a site is created""" |
|
36 site = event.manager.__parent__ |
|
37 check_required_utilities(site, REQUIRED_UTILITIES) |
|
38 |
|
39 |
|
40 @utility_config(name='PyAMS medias converter', provides=ISiteGenerations) |
|
41 class MediaConversionGenerationsChecker(object): |
|
42 """Medias conversion utility generations checker""" |
|
43 |
|
44 generation = 1 |
|
45 |
|
46 def evolve(self, site, current=None): |
|
47 """Check for required utilities""" |
|
48 check_required_utilities(site, REQUIRED_UTILITIES) |