def testThumbnailer(self):
     '''Tests the creation a file'''
     thumbnailer = ImageThumbnailer(self.filename)
     thumbnailer.create_thumbnail()
     if self.debug:
         print 'Expecting thumbnail : %s' % thumbnailer._thumb_file
     self.assertTrue(os.path.exists(thumbnailer._thumb_file))
 def testThumbnailer(self):
     '''Tests the creation a file'''
     thumbnailer = ImageThumbnailer(self.filename)
     thumbnailer.create_thumbnail()
     if self.debug:
         print 'Expecting thumbnail : %s' % thumbnailer._thumb_file
     self.assertTrue(os.path.exists(thumbnailer._thumb_file))
Beispiel #3
0
    def _add_file(self, filename):
        '''Add an image to the store.'''
        photo_file = models.PhotoImage()
        photo_file.filename = unicode(filename)

        thumbnailer = ImageThumbnailer(filename)
        thumbnailer.create_thumbnail()
        photo_file.thumbnail = unicode(thumbnailer.filename)

        self._store.add(photo_file)
        self._store.commit()

        return photo_file
Beispiel #4
0
    def _add_file(self, filename):
        '''Add an image to the store.'''
        photo_file = models.PhotoImage()
        photo_file.filename = unicode(filename)

        thumbnailer = ImageThumbnailer(filename)
        thumbnailer.create_thumbnail()
        photo_file.thumbnail = unicode(thumbnailer.filename)

        self._store.add(photo_file)
        self._store.commit()

        return photo_file
Beispiel #5
0
    def _addAlbum(self, path):
        """
        Create a new album into image cache. Folders are handled as albums.
        Nested folders are not nested in database! All albums are on top level.
        """

        album_info = os.path.join(path, ".entertainer_album.info")
        album_thumb = os.path.join(path, ".entertainer_album.jpg")

        # Get album information
        if os.path.exists(album_info):
            try:
                inf_f = open(album_info)
                a_title = inf_f.readline()[6:]
                a_description = inf_f.readline()[12:]
            except IOError:
                a_title = path[path.rfind('/')+1:].replace('_',' ').title()
                a_description = ""
        else:
            a_title = path[path.rfind('/')+1:].replace('_',' ').title()
            a_description = ""

        if os.path.exists(album_thumb):
            thumbnailer = ImageThumbnailer(album_thumb)
            thumbnailer.create_thumbnail()
            a_hash = thumbnailer.get_hash()
        else:
            a_hash = ""

        album_row = (path, a_title, a_description, a_hash)
        self.db_cursor.execute(
            """
            INSERT INTO album(path, title, description, hash)
            VALUES(?,?,?,?)
            """, album_row)
        self.db_conn.commit()
Beispiel #6
0
    def _addAlbum(self, path):
        """
        Create a new album into image cache. Folders are handled as albums.
        Nested folders are not nested in database! All albums are on top level.
        """

        album_info = os.path.join(path, ".entertainer_album.info")
        album_thumb = os.path.join(path, ".entertainer_album.jpg")

        # Get album information
        if os.path.exists(album_info):
            try:
                inf_f = open(album_info)
                a_title = inf_f.readline()[6:]
                a_description = inf_f.readline()[12:]
            except IOError:
                a_title = path[path.rfind('/') + 1:].replace('_', ' ').title()
                a_description = ""
        else:
            a_title = path[path.rfind('/') + 1:].replace('_', ' ').title()
            a_description = ""

        if os.path.exists(album_thumb):
            thumbnailer = ImageThumbnailer(album_thumb)
            thumbnailer.create_thumbnail()
            a_hash = thumbnailer.get_hash()
        else:
            a_hash = ""

        album_row = (path, a_title, a_description, a_hash)
        self.db_cursor.execute(
            """
            INSERT INTO album(path, title, description, hash)
            VALUES(?,?,?,?)
            """, album_row)
        self.db_conn.commit()
Beispiel #7
0
    def _addJPEGfile(self, filename):
        """
        Add JPEG image to the image cache. Raises exception if adding fails.

        Process:
            - Open file
            - Get image date and time
            - Get image title and description
            - Get image size
            - Generate thumbnail / get hash from thumbnailer
            - Insert data to image cache database
        """
        tmp = datetime.datetime.fromtimestamp(os.stat(filename)[-1])
        timestamp = [str(tmp.year) + "-" + str(tmp.month) + "-" +
            str(tmp.day), str(tmp.hour) + ":" + str(tmp.minute) + ":" +
            str(tmp.second)]

        # Generate name from filename
        tmp = filename[filename.rfind('/') + 1 : filename.rfind('.')]
        title = tmp.replace('_',' ').title() # Make title more attractive
        description = "" # No description for this image file

        try:
            im = Image.open(filename)
            width, height = im.size
        except IOError:
            self.logger.error("Couldn't identify image file: " + filename)
            return

        # Create thumbnail and return hash
        thumbnailer = ImageThumbnailer(filename)
        thumbnailer.create_thumbnail()
        thumb_hash = thumbnailer.get_hash()
        del thumbnailer
        album_path = filename[:filename.rfind('/')]

        db_row = (filename, # Filename (full path)
                  title, # Title of the image
                  description, # Description of the image
                  timestamp[0], # Image's taken date
                  timestamp[1], # Image's taken time
                  width,  # Image's width
                  height, # Image's height
                  os.path.getsize(filename), # Image file size in bytes
                  thumb_hash, # Thumbnail hash (hash of the filename)
                  album_path) # Path of the album (folder of this image)

        self.db_cursor.execute(
            """
            INSERT INTO image(filename,
                title,
                description,
                date,
                time,
                width,
                height,
                filesize,
                hash,
                album_path)
                VALUES(?,?,?,?,?,?,?,?,?,?)""", db_row)
        self.db_conn.commit()
Beispiel #8
0
    def _addJPEGfile(self, filename):
        """
        Add JPEG image to the image cache. Raises exception if adding fails.

        Process:
            - Open file
            - Get image date and time
            - Get image title and description
            - Get image size
            - Generate thumbnail / get hash from thumbnailer
            - Insert data to image cache database
        """
        tmp = datetime.datetime.fromtimestamp(os.stat(filename)[-1])
        timestamp = [
            str(tmp.year) + "-" + str(tmp.month) + "-" + str(tmp.day),
            str(tmp.hour) + ":" + str(tmp.minute) + ":" + str(tmp.second)
        ]

        # Generate name from filename
        tmp = filename[filename.rfind('/') + 1:filename.rfind('.')]
        title = tmp.replace('_', ' ').title()  # Make title more attractive
        description = ""  # No description for this image file

        try:
            im = Image.open(filename)
            width, height = im.size
        except IOError:
            self.logger.error("Couldn't identify image file: " + filename)
            return

        # Create thumbnail and return hash
        thumbnailer = ImageThumbnailer(filename)
        thumbnailer.create_thumbnail()
        thumb_hash = thumbnailer.get_hash()
        del thumbnailer
        album_path = filename[:filename.rfind('/')]

        db_row = (
            filename,  # Filename (full path)
            title,  # Title of the image
            description,  # Description of the image
            timestamp[0],  # Image's taken date
            timestamp[1],  # Image's taken time
            width,  # Image's width
            height,  # Image's height
            os.path.getsize(filename),  # Image file size in bytes
            thumb_hash,  # Thumbnail hash (hash of the filename)
            album_path)  # Path of the album (folder of this image)

        self.db_cursor.execute(
            """
            INSERT INTO image(filename,
                title,
                description,
                date,
                time,
                width,
                height,
                filesize,
                hash,
                album_path)
                VALUES(?,?,?,?,?,?,?,?,?,?)""", db_row)
        self.db_conn.commit()