[Zope-CVS] CVS: Packages/Moztop/moztopsupport - __init__.py:1.1 configure.zcml:1.1 interfaces.py:1.1 utilities.py:1.1

Sidnei da Silva sidnei@x3ng.com.br
Thu, 20 Mar 2003 13:24:27 -0500


Update of /cvs-repository/Packages/Moztop/moztopsupport
In directory cvs.zope.org:/tmp/cvs-serv22557/moztopsupport

Added Files:
	__init__.py configure.zcml interfaces.py utilities.py 
Log Message:
Big refactoring. Renamed idesupport to moztop support. Adding a utility to get Resource Types

=== Added File Packages/Moztop/moztopsupport/__init__.py ===
##############################################################################
#
# Copyright (c) 2002, 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Moztop Extension Product

$Id: __init__.py,v 1.1 2003/03/20 18:24:26 sidnei Exp $
"""


=== Added File Packages/Moztop/moztopsupport/configure.zcml ===
<zopeConfigure xmlns='http://namespaces.zope.org/zope'>

  <include package=".rdf" />
  <include package=".xmlrpc" />
  <include package=".xml" />
<!-- 
     Disabled for now. there is a bug in ZCML that doesnt let you
     override configurations at this point

  <include package=".http" />
-->

  <utility factory=".utilities.ResourceTypesUtility"
           permission="zope.Public"
           provides=".interfaces.IResourceTypesUtility" />

</zopeConfigure>


=== Added File Packages/Moztop/moztopsupport/interfaces.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
__doc__ = """ General Interfaces for Moztop

$Id: interfaces.py,v 1.1 2003/03/20 18:24:26 sidnei Exp $"""

from zope.interface import Interface

class IResourceTypesUtility(Interface):
    """ Utility to query available resource types
    and resource type for a given object """

    def getAvailableResourceTypes():
        """ Lists the globally available resource types """

    def getResourceTypeFor(obj):
        """ Returns the resource type for a given object """


=== Added File Packages/Moztop/moztopsupport/utilities.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
__doc__ = """ Utilities that help on doing common tasks for Moztop

$Id: utilities.py,v 1.1 2003/03/20 18:24:26 sidnei Exp $"""

from zope.app.content.folder import RootFolder
from zope.component import getService
from zope.proxy.introspection import removeAllProxies
from moztopsupport.interfaces import IResourceTypesUtility

class ResourceTypesUtility:

    __implements__ = IResourceTypesUtility

    def _getFactoryService(self):
        if not hasattr(self, '_v_factory_service') or \
           self._v_factory_service is None:
           self._v_factory_service = getService(None, 'Factories')
        return self._v_factory_service
        
    def getAvailableResourceTypes(self):
        service = self._getFactoryService()
        available_types = service._GlobalFactoryService__factories.keys()
        available_types.append('Unknown')
        return available_types
        
    def getResourceTypeFor(self, obj):
        if obj.__class__ == RootFolder:
            return 'Folder'
        service = self._getFactoryService()
        for name in self.getAvailableResourceTypes():
            new_obj = None
            try:
                new_obj = service.createObject(name)
                new_obj = removeAllProxies(new_obj)
            except:
                continue
            if obj.__class__ == new_obj.__class__:
                return name
        return 'Unknown'