Exemple #1
0
def getImageServer(manager):

    try:
        toReturn = manager.getProxy('/ImageServer/0')
    except ObjectNotFoundException:
        try:
            toReturn = manager.addLocation('/ImageServer/imageserver',
                                           ChimeraPath().controllers)
        except Exception as e:
            print(''.join(Pyro4.util.getPyroTraceback(e)))
            raise ClassLoaderException('Unable to create imageserver')

    if not toReturn:
        raise ClassLoaderException('Unable to create or find an ImageServer')

    return toReturn
Exemple #2
0
def getImageServer(manager):

    try:
        toReturn = manager.getProxy('/ImageServer/0')
    except ObjectNotFoundException:
        try:
            toReturn = manager.addLocation('/ImageServer/imageserver',
                                           [ChimeraPath.controllers()])
        except Exception, e:
            print ''.join(Pyro.util.getPyroTraceback(e))
            raise ClassLoaderException('Unable to create imageserver')
Exemple #3
0
    def _lookupClass(self, clsname, path):
        """
        Based on this recipe
        http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52241
        by Jorgen Hermann
        """

        if clsname.lower() in self._cache:
            return self._cache[clsname.lower()]

        if not isinstance(path, (list, tuple)):
            path = [path]

        sys.path = path + sys.path

        try:

            module = __import__(
                clsname.lower(), globals(), locals(), [clsname])

        except ImportError:

            # Python trick: An ImportError exception catched here
            # could came from both the __import__ above or from the
            # module imported by the __import__ above... So, we need a
            # way to know the difference between those exceptions.  A
            # simple (reliable?) way is to use the length of the
            # exception traceback as a indicator. If the traceback had
            # only 1 entry, the exceptions comes from the __import__
            # above, more than one the exception comes from the
            # imported module

            tb_size = len(traceback.extract_tb(sys.exc_info()[2]))

            # ImportError above
            if tb_size == 1:
                raise ClassLoaderException(
                    "Couldn't find module %s (%s)." % (clsname, path))

            # ImportError on loaded module
            else:
                raise ClassLoaderException(
                    "Module %s found but couldn't be loaded." % clsname)

        except:
            raise ClassLoaderException(
                "Module %s found but couldn't be loaded." % clsname)

        # turns sys.path back
        [sys.path.remove(p) for p in path]

        cls = None

        for k, v in vars(module).items():
            if k.lower() == clsname.lower():
                cls = v
                break

        if not cls:
            raise ClassLoaderException(
                "Module found but couldn't fount class on module '%s' (%s)." %
                (clsname.lower(), module.__file__))

        self._cache[clsname.lower()] = cls

        return self._cache[clsname.lower()]
Exemple #4
0
from chimera.core.exceptions import ChimeraException, ObjectNotFoundException, ClassLoaderException
from chimera.core.path import ChimeraPath
import Pyro.util


def getImageServer(manager):

    try:
        toReturn = manager.getProxy('/ImageServer/0')
    except ObjectNotFoundException:
        try:
            toReturn = manager.addLocation('/ImageServer/imageserver',
                                           ChimeraPath().controllers)
        except Exception, e:
            print ''.join(Pyro.util.getPyroTraceback(e))
            raise ClassLoaderException('Unable to create imageserver')

    if not toReturn:
        raise ClassLoaderException('Unable to create or find an ImageServer')

    return toReturn


class ImageServerException(ChimeraException):
    pass


class InvalidFitsImageException(ImageServerException):
    pass