Exemple #1
0
    def from_path( lib, path, user_id ):

        picture = None
        try:
            picture = Item.from_path( lib, path, user_id )
        except DBItemNotFoundException as e:
            # Item doesn't exist in DB, but it does on FS, so add it to the DB.
            img_stat = os.stat( e.absolute_path )
            current_app.logger.info(
                'creating entry for file: {}'.format( e.absolute_path ) )
            picture = Picture(
                name=e.filename,
                folder_id=e.folder.id,
                timestamp=datetime.fromtimestamp( img_stat[stat.ST_MTIME] ),
                size=img_stat[stat.ST_SIZE],
                added=datetime.now(),
                hash=Picture.hash_file( e.absolute_path, 1 ),
                hash_algo=1 )
            db.session.add( picture )
            db.session.commit()

        if 'width' not in picture.meta or 'height' not in picture.meta:
            with Image.open( picture.absolute_path ) as im:
                print( im.size )
                picture.meta['width'] = im.size[0]
                picture.meta['height'] = im.size[1]
            db.session.commit()

            current_app.logger.info( 'found new image with size: {}x{}'.format(
                picture.width, picture.height
            ) )

        return picture
Exemple #2
0
    def test_item_machine_path(self):

        DataHelper.create_data_items(self, db)

        file1 = Item.from_path(self.lib.id,
                               'subfolder2/subfolder3/random320x240.png',
                               self.user_id)

        self.assertEqual(file1.folder.machine_path, ['testing_library', 2, 3])