Ejemplo n.º 1
0
    def image_resource(self, image_name):
        """ Returns the ImageResource object for the specified **image_name**.
        """
        # Get the name of the image file:
        volume_name, file_name = split_image_name(image_name)

        if self.is_zip_file:
            # See if we already have the image file cached in the file system:
            cache_file = self._check_cache(file_name)
            if cache_file is None:
                # If not cached, then create a zip file reference:
                ref = ZipFileReference(
                    resource_factory=resource_manager.resource_factory,
                    zip_file=self.zip_file,
                    path=self.path,
                    volume_name=self.name,
                    file_name=file_name)
            else:
                # Otherwise, create a cache file reference:
                ref = ImageReference(resource_manager.resource_factory,
                                     filename=cache_file)
        else:
            # Otherwise, create a normal file reference:
            ref = ImageReference(resource_manager.resource_factory,
                                 filename=join(self.path, file_name))

        # Create the ImageResource object using the reference (note that the
        # ImageResource class will not allow us to specify the reference in the
        # constructor):
        resource = ImageResource(file_name)
        resource._ref = ref

        # Return the ImageResource:
        return resource
Ejemplo n.º 2
0
    def image_resource ( self, image_name ):
        """ Returns the ImageResource object for the specified **image_name**.
        """
        # Get the name of the image file:
        volume_name, file_name = split_image_name( image_name )

        if self.is_zip_file:
            # See if we already have the image file cached in the file system:
            cache_file = self._check_cache( file_name )
            if cache_file is None:
                # If not cached, then create a zip file reference:
                ref = ZipFileReference(
                          resource_factory = resource_manager.resource_factory,
                          zip_file         = self.zip_file,
                          path             = self.path,
                          volume_name      = self.name,
                          file_name        = file_name )
            else:
                # Otherwise, create a cache file reference:
                ref = ImageReference( resource_manager.resource_factory,
                                      filename = cache_file )
        else:
            # Otherwise, create a normal file reference:
            ref = ImageReference( resource_manager.resource_factory,
                                  filename = join( self.path, file_name ) )

        # Create the ImageResource object using the reference (note that the
        # ImageResource class will not allow us to specify the reference in the
        # constructor):
        resource = ImageResource( file_name )
        resource._ref = ref

        # Return the ImageResource:
        return resource