示例#1
0
class ImageServer(ChimeraObject):

    __config__  = {'save_dir': '$HOME/images/$LAST_NOON_DATE',
                   
                   # Root directory where images are stored for use when autoloading existing
                   'load_dir': '$HOME/images',

                   # Load existing load_dir images on startup
                   'autoload': True,
                   
                   'http_host': '0.0.0.0',
                   'http_port': 7669}
    
    def __init__(self):
        ChimeraObject.__init__(self)
        
        self.imagesByID   = {}
        self.imagesByPath = {}

    def __start__ (self):
        self.http = ImageServerHTTP(self)
        self.http.start()
        
        if self['autoload']:
            self.log.info('Loading existing images...')
            loaddir = os.path.expanduser(self['load_dir'])
            loaddir = os.path.expandvars(loaddir)
            loaddir = os.path.realpath(loaddir)
            self._loadImageDir(loaddir)

    def __stop__(self):

        self.http.stop()

        for image in self.imagesByID.values():
            self.unregister(image)

    def _loadImageDir(self, dir):

        filesToLoad = []

        if os.path.exists(dir):        

            # build files list
            for root, dirs, files in os.walk(dir):
                filesToLoad += [os.path.join(dir, root, f) for f in files if f.endswith(".fits")]
                
            for file in filesToLoad:
                self.log.debug('Loading %s' % file)
                self.register(Image.fromFile(file))

    def register(self, image):
        try:
            if "CHM_ID" in image:
                image.setGUID(image["CHM_ID"])
            else:
                image += ("CHM_ID", image.GUID())
                image.save()
                
            self.getDaemon().connect(image)
            self.imagesByID[image.GUID()]    = image
            self.imagesByPath[image.filename()] = image

            # save Image's HTTP address
            image.http(self.getHTTPByID(image.GUID()))
            return image.getProxy()
        except Exception, e:
            print ''.join(Pyro.util.getPyroTraceback(e))
示例#2
0
class ImageServer(ChimeraObject):

    __config__  = { # root directory where images are stored
                   'images_dir': '~/images',    
                   # path relative to images_dir where images for a
                   # night will be stored, use "" to save all images
                   # on the same directory
                   'night_dir' : '$LAST_NOON_DATE', 

                   # Load existing images on startup?
                   'autoload': False,

                   'httpd': True, 
                   'http_host': 'default',
                   'http_port': 7669}
    
    def __init__(self):
        ChimeraObject.__init__(self)
        
        self.imagesByID   = {}
        self.imagesByPath = {}

    def __start__ (self):

        if self["http_host"] == "default":
            self["http_host"] = self.getManager().getHostname()
        
        if self["httpd"]:    
            self.http = ImageServerHTTP(self)
            self.http.start()
        
        if self['autoload']:
            self.log.info('Loading existing images...')
            loaddir = os.path.expanduser(self['images_dir'])
            loaddir = os.path.expandvars(loaddir)
            loaddir = os.path.realpath(loaddir)
            self._loadImageDir(loaddir)

    def __stop__(self):

        if self["httpd"]:    
            self.http.stop()

        for image in self.imagesByID.values():
            self.unregister(image)

    def _loadImageDir(self, dir):

        filesToLoad = []

        if os.path.exists(dir):        

            # build files list
            for root, dirs, files in os.walk(dir):
                filesToLoad += [os.path.join(dir, root, f) for f in files if f.endswith(".fits")]
                
            for file in filesToLoad:
                self.log.debug('Loading %s' % file)
                self.register(Image.fromFile(file))

    def register(self, image):
        try:
            if "CHM_ID" in image:
                image.setGUID(image["CHM_ID"])
            else:
                image += ("CHM_ID", image.GUID())
                image.save()
                
            self.getDaemon().connect(image)
            self.imagesByID[image.GUID()]    = image
            self.imagesByPath[image.filename()] = image

            # save Image's HTTP address
            image.http(self.getHTTPByID(image.GUID()))
            return image.getProxy()
        except Exception, e:
            print ''.join(Pyro.util.getPyroTraceback(e))
示例#3
0
class ImageServer(ChimeraObject):

    __config__ = {  # root directory where images are stored
        'images_dir': '~/images',
        # path relative to images_dir where images for a
        # night will be stored, use "" to save all images
        # on the same directory
        'night_dir': '$LAST_NOON_DATE',

        # Load existing images on startup?
        'autoload': False,

        'httpd': True,
        'http_host': 'default',
        'http_port': 7669,
        'max_images': 10,
    }

    def __init__(self):
        ChimeraObject.__init__(self)

        self.imagesByID = OrderedDict()
        self.imagesByPath = OrderedDict()

    def __start__(self):

        if self["http_host"] == "default":
            self["http_host"] = self.getManager().getHostname()

        if self["httpd"]:
            self.http = ImageServerHTTP(self)
            self.http.start()

        if self['autoload']:
            self.log.info('Loading existing images...')
            loaddir = os.path.expanduser(self['images_dir'])
            loaddir = os.path.expandvars(loaddir)
            loaddir = os.path.realpath(loaddir)
            self._loadImageDir(loaddir)

    def __stop__(self):

        if self["httpd"]:
            self.http.stop()

        for image in self.imagesByID.values():
            self.unregister(image)

    def _loadImageDir(self, dir):

        filesToLoad = []

        if os.path.exists(dir):

            # build files list
            for root, dirs, files in os.walk(dir):
                filesToLoad += [
                    os.path.join(dir, root, f) for f in files
                    if f.endswith(".fits")
                ]

            for file in filesToLoad:
                self.log.debug('Loading %s' % file)
                self.register(Image.fromFile(file))

    def register(self, image):
        try:
            if len(self.imagesByID) > self['max_images']:
                remove_items = self.imagesByID.keys()[:-self['max_images']]

                for item in remove_items:
                    self.log.debug('Unregistering image %s' % item)
                    self.unregister(self.imagesByID[item])

            if "CHM_ID" in image:
                image.setGUID(image["CHM_ID"])
            else:
                image += ("CHM_ID", image.GUID())
                image.save()

            self.getDaemon().connect(image)
            self.imagesByID[image.GUID()] = image
            self.imagesByPath[image.filename()] = image

            # save Image's HTTP address
            image.http(self.getHTTPByID(image.GUID()))
            return image.getProxy()
        except Exception, e:
            print ''.join(Pyro.util.getPyroTraceback(e))