From 7acb6c6902bd59f9ba7c1f8f56d124ca1b87e2e0 Mon Sep 17 00:00:00 2001 From: yomguy <> Date: Mon, 30 Aug 2010 01:36:59 +0000 Subject: [PATCH] cleanup --- telemeta/core.py | 176 +-------------------------------------- telemeta/web/__init__.py | 2 +- telemeta/web/base.py | 17 +--- 3 files changed, 5 insertions(+), 190 deletions(-) diff --git a/telemeta/core.py b/telemeta/core.py index 90179b7c..c7e7e221 100644 --- a/telemeta/core.py +++ b/telemeta/core.py @@ -1,20 +1,14 @@ # -*- coding: utf-8 -*- # # Copyright (C) 2007 Samalyse SARL -# Copyright (C) 2003-2005 Edgewall Software -# Copyright (C) 2003-2004 Jonas Borgström -# Copyright (C) 2004-2005 Christopher Lenz # All rights reserved. # # This software is licensed as described in the file COPYING, which # you should have received as part of this distribution. # -# Author: Jonas Borgström -# Christopher Lenz -# Olivier Guilyardi +# Author: Olivier Guilyardi -__all__ = ['Component', 'ExtensionPoint', 'implements', 'Interface', - 'TelemetaError'] +__all__ = ['TelemetaError'] class TelemetaError(Exception): @@ -27,169 +21,3 @@ class TelemetaError(Exception): # self.title = title # self.show_traceback = show_traceback - -class Interface(object): - """Marker base class for extension point interfaces.""" - - -class ExtensionPoint(property): - """Marker class for extension points in components.""" - - def __init__(self, interface): - """Create the extension point. - - @param interface: the `Interface` subclass that defines the protocol - for the extension point - """ - property.__init__(self, self.extensions) - self.interface = interface - self.__doc__ = 'List of components that implement `%s`' % \ - self.interface.__name__ - - def extensions(self, component): - """Return a list of components that declare to implement the extension - point interface.""" - extensions = ComponentMeta._registry.get(self.interface, []) - return filter(None, [component.compmgr[cls] for cls in extensions]) - - def __repr__(self): - """Return a textual representation of the extension point.""" - return '' % self.interface.__name__ - - -class ComponentMeta(type): - """Meta class for components. - - Takes care of component and extension point registration. - """ - _components = [] - _registry = {} - - def __new__(cls, name, bases, d): - """Create the component class.""" - - d['_implements'] = _implements[:] - del _implements[:] - - new_class = type.__new__(cls, name, bases, d) - if name == 'Component': - # Don't put the Component base class in the registry - return new_class - - # Only override __init__ for Components not inheriting ComponentManager - if True not in [issubclass(x, ComponentManager) for x in bases]: - # Allow components to have a no-argument initializer so that - # they don't need to worry about accepting the component manager - # as argument and invoking the super-class initializer - init = d.get('__init__') - if not init: - # Because we're replacing the initializer, we need to make sure - # that any inherited initializers are also called. - for init in [b.__init__._original for b in new_class.mro() - if issubclass(b, Component) - and '__init__' in b.__dict__]: - break - def maybe_init(self, compmgr, init=init, cls=new_class): - if cls not in compmgr.components: - compmgr.components[cls] = self - if init: - init(self) - maybe_init._original = init - new_class.__init__ = maybe_init - - if d.get('abstract'): - # Don't put abstract component classes in the registry - return new_class - - ComponentMeta._components.append(new_class) - for interface in d.get('_implements', []): - ComponentMeta._registry.setdefault(interface, []).append(new_class) - for base in [base for base in bases if hasattr(base, '_implements')]: - for interface in base._implements: - ComponentMeta._registry.setdefault(interface, []).append(new_class) - - return new_class - - -_implements = [] - -def implements(*interfaces): - """Can be used in the class definiton of `Component` subclasses to declare - the extension points that are extended. - """ - _implements.extend(interfaces) - - -class Component(object): - """Base class for components. - - Every component can declare what extension points it provides, as well as - what extension points of other components it extends. - """ - __metaclass__ = ComponentMeta - - def __new__(cls, *args, **kwargs): - """Return an existing instance of the component if it has already been - activated, otherwise create a new instance. - """ - # If this component is also the component manager, just invoke that - if issubclass(cls, ComponentManager): - self = super(Component, cls).__new__(cls) - self.compmgr = self - return self - - # The normal case where the component is not also the component manager - compmgr = args[0] - self = compmgr.components.get(cls) - if self is None: - self = super(Component, cls).__new__(cls) - self.compmgr = compmgr - compmgr.component_activated(self) - return self - - -class ComponentManager(object): - """The component manager keeps a pool of active components.""" - - def __init__(self): - """Initialize the component manager.""" - self.components = {} - self.enabled = {} - if isinstance(self, Component): - self.components[self.__class__] = self - - def __contains__(self, cls): - """Return wether the given class is in the list of active components.""" - return cls in self.components - - def __getitem__(self, cls): - """Activate the component instance for the given class, or return the - existing the instance if the component has already been activated.""" - if cls not in self.enabled: - self.enabled[cls] = self.is_component_enabled(cls) - if not self.enabled[cls]: - return None - component = self.components.get(cls) - if not component: - if cls not in ComponentMeta._components: - raise TelemetaError, 'Component "%s" not registered' % cls.__name__ - try: - component = cls(self) - except TypeError, e: - raise TelemetaError, 'Unable to instantiate component %r (%s)' \ - % (cls, e) - return component - - def component_activated(self, component): - """Can be overridden by sub-classes so that special initialization for - components can be provided. - """ - - def is_component_enabled(self, cls): - """Can be overridden by sub-classes to veto the activation of a - component. - - If this method returns False, the component with the given class will - not be available. - """ - return True diff --git a/telemeta/web/__init__.py b/telemeta/web/__init__.py index 22d21398..6857d986 100644 --- a/telemeta/web/__init__.py +++ b/telemeta/web/__init__.py @@ -1,2 +1,2 @@ from telemeta.web.base import WebView -from pages import * +import pages diff --git a/telemeta/web/base.py b/telemeta/web/base.py index d1853093..6b5aff80 100644 --- a/telemeta/web/base.py +++ b/telemeta/web/base.py @@ -36,6 +36,7 @@ import re import os import sys import datetime +import timeside from django.template import RequestContext, loader from django import template @@ -49,11 +50,6 @@ from django.contrib.auth.decorators import login_required from telemeta.models import MediaItem, Location, MediaCollection, EthnicGroup from telemeta.models import dublincore, Enumeration -#from telemeta.core import Component, ExtensionPoint -#from telemeta.export import * -#from telemeta.visualization import * -#from telemeta.analysis import * -#from telemeta.analysis.vamp import * import telemeta.interop.oai as oai from telemeta.interop.oaidatasource import TelemetaOAIDataSource from django.core.exceptions import ObjectDoesNotExist @@ -61,9 +57,6 @@ from telemeta.util.unaccent import unaccent from telemeta.web import pages from telemeta.util.unaccent import unaccent_icmp -import timeside - - def render(request, template, data = None, mimetype = None): return render_to_response(template, data, context_instance=RequestContext(request), mimetype=mimetype) @@ -152,12 +145,6 @@ class WebView: 'unit':analyzer.unit(), 'value':str(value)}) -# vamp = VampCoreAnalyzer() -# vamp_plugins = vamp.get_plugins_list() -# vamp_plugin_list = [] -# for plugin in vamp_plugins: -# vamp_plugin_list.append(':'.join(plugin[1:])) - return render(request, template, {'item': item, 'export_formats': formats, 'visualizers': graphers, 'visualizer_id': grapher_id,'analysers': analyzers, @@ -213,7 +200,7 @@ class WebView: item = MediaItem.objects.get(public_id=public_id) audio = os.path.join(os.path.dirname(__file__), item.file.path) decoder = timeside.decoder.FileDecoder(audio) - print decoder.format(), mime_type +# print decoder.format(), mime_type if decoder.format() == mime_type: # source > stream media = audio -- 2.39.5