Example #1
0
    def test_dirmetadata_update(self):
        """
        Updated directory metadata file shall trigger the rebuild of the
        corresponding webgal directory.
        """
        subgal_path = os.path.join(self.source_dir, 'subgal')
        os.mkdir(subgal_path)
        self.add_img(subgal_path, 'subgal_img.jpg')

        # metadata must exist before creating the Directory() object (md files
        # are probed in the constructor.
        self.album.generate_default_metadata()

        source_subgal = Directory(subgal_path, [], ['subgal_img.jpg'],
                                  self.album)

        dest_path = os.path.join(self.tmpdir, 'dst')

        self.album.generate(dest_path)
        dest_subgal = WebalbumDir(source_subgal, [], self.album, dest_path)

        self.assertFalse(
            dest_subgal.needs_build(),
            'Webalbum subgal has been built and still needs build.')

        # touch the description file
        os.utime(os.path.join(source_subgal.path, 'album_description'), None)
        # New objects in order to probe filesystem
        source_subgal = Directory(subgal_path, [], ['subgal_img.jpg'],
                                  self.album)
        dest_subgal = WebalbumDir(source_subgal, [], self.album, dest_path)

        self.assertTrue(
            dest_subgal.needs_build(),
            'Webalbum subgal should need build because of updated dir md.')
Example #2
0
    def test_latest_media_stamp(self):
        dpath = os.path.join(self.source_dir, 'srcdir')
        os.makedirs(dpath)

        pics = ['pic1.jpg', 'pic2.jpg', 'pic3.jpg']

        for fn in pics:
            self.add_img(dpath, fn)

        # no exif test
        imgpath = os.path.join(dpath, 'pic1.jpg')
        img = GExiv2.Metadata(imgpath)
        del img['Exif.Photo.DateTimeDigitized']
        del img['Exif.Photo.DateTimeOriginal']
        img.save_file()
        os.utime(imgpath, (0, datetime(2011, 7, 3).timestamp()))
        imgpath = os.path.join(dpath, 'pic2.jpg')
        img = GExiv2.Metadata(imgpath)
        del img['Exif.Photo.DateTimeDigitized']
        del img['Exif.Photo.DateTimeOriginal']
        img.save_file()
        os.utime(imgpath, (0, datetime(2011, 7, 4).timestamp()))
        imgpath = os.path.join(dpath, 'pic3.jpg')
        img = GExiv2.Metadata(imgpath)
        del img['Exif.Photo.DateTimeDigitized']
        del img['Exif.Photo.DateTimeOriginal']
        img.save_file()
        os.utime(imgpath, (0, datetime(2011, 7, 2).timestamp()))
        d = Directory(dpath, [], pics, self.album)
        self.assertEqual(d.latest_media_stamp(from_media=True),
                         datetime(2011, 7, 4).timestamp())

        # mixed exif and no exif test
        imgpath = os.path.join(dpath, 'pic2.jpg')
        img = GExiv2.Metadata(imgpath)
        img['Exif.Photo.DateTimeOriginal'] =\
            datetime(2015, 7, 4).strftime('%Y:%m:%d %H:%M:%S')
        img.save_file()
        d = Directory(dpath, [], pics, self.album)
        self.assertEqual(d.latest_media_stamp(from_media=True),
                         datetime(2015, 7, 4).timestamp())

        # full exif
        imgpath = os.path.join(dpath, 'pic1.jpg')
        img = GExiv2.Metadata(imgpath)
        img['Exif.Photo.DateTimeOriginal'] =\
            datetime(2015, 8, 1).strftime('%Y:%m:%d %H:%M:%S')
        img.save_file()
        imgpath = os.path.join(dpath, 'pic3.jpg')
        img = GExiv2.Metadata(imgpath)
        img['Exif.Photo.DateTimeOriginal'] =\
            datetime(2015, 8, 20).strftime('%Y:%m:%d %H:%M:%S')
        img.save_file()
        d = Directory(dpath, [], pics, self.album)
        self.assertEqual(d.latest_media_stamp(from_media=True),
                         datetime(2015, 8, 20).timestamp())
Example #3
0
 def get_dir(self, drpath):
     """
     Returns a directory object inside the test album root.
     """
     dpath = os.path.join(self.source_dir, drpath)
     os.makedirs(dpath)
     return Directory(dpath, [], [], self.album)
    def test_sortbyfilename_galsplit(self):
        """
        It shall be possible to sort images in galleries split on multiple
        pages by filename.
        """
        config = lazygal.config.LazygalConfig()
        config.set('webgal', 'sort-medias', 'filename')
        config.set('webgal', 'thumbs-per-page', 3)
        self.setup_album(config)
        subgal_path, pics = self.__setup_pics()

        src_dir = Directory(subgal_path, [], pics, self.album)
        dest_subgal = WebalbumDir(src_dir, [], self.album, self.dest_path)

        dest_subgal.call_populate_deps()
        dest_subgal.sort_task.make()

        self.assertEqual(
            [media.media.filename for media in dest_subgal.medias], [
                u'1-february.jpg', u'3-june.jpg', u'4-december.jpg',
                u'5-august.jpg', u'6-january.jpg'
            ])

        # page #1
        page_medias = dest_subgal.index_pages[0][0].galleries[0][1]
        self.assertEqual([media.media.filename for media in page_medias],
                         [u'1-february.jpg', u'3-june.jpg', u'4-december.jpg'])
        # page #2
        page_medias = dest_subgal.index_pages[1][0].galleries[0][1]
        self.assertEqual([media.media.filename for media in page_medias],
                         [u'5-august.jpg', u'6-january.jpg'])
Example #5
0
    def test_subgal_update(self):
        """
        Updated subgals shall trigger the webgal rebuild and the parent
        directory index rebuild.
        """
        source_subgal = self.setup_subgal('subgal', ['subgal_img.jpg'])

        dest_path = os.path.join(self.tmpdir, 'dst')

        self.album.generate(dest_path)
        dest_subgal = WebalbumDir(source_subgal, [], self.album, dest_path)

        self.assertFalse(
            dest_subgal.needs_build(),
            'Webalbum subgal has been built and still needs build.')

        self.add_img(source_subgal.path, 'subgal_img2.jpg')
        # New objects to ensure pic is taken into account
        source_subgal = Directory(source_subgal.path, [],
                                  ['subgal_img.jpg', 'subgal_img2.jpg'],
                                  self.album)
        dest_subgal = WebalbumDir(source_subgal, [], self.album, dest_path)

        # Subgal should need build.
        self.assertTrue(
            dest_subgal.needs_build(),
            'Webalbum subgal should need build because of added pic in subgal.'
        )

        # Parent directory should need build.
        source_gal = Directory(self.source_dir, [source_subgal], [],
                               self.album)
        dest_gal = WebalbumDir(source_gal, [dest_subgal], self.album,
                               dest_path)
        self.assertTrue(
            dest_gal.needs_build(),
            'Webalbum gal should need build because of added pic in subgal.')

        # Parent directory should need build.
        parent_index = WebalbumIndexPage(dest_gal, 'small', 0, [dest_subgal],
                                         [(dest_subgal, dest_subgal.medias)])
        self.assertTrue(
            parent_index.needs_build(),
            'Webalbum gal index should need build because of added pic in subgal.'
        )
Example #6
0
    def test_auto_metadata_album_picture(self):
        img_names = ('ontop.jpg', 'second.jpg', )
        for img_name in img_names:
            self.add_img(self.source_dir, img_name)

        self.album_root = Directory(self.source_dir, [], img_names,
                                    self.album_root.album)

        self.assertEqual(img_names[0], self.album_root.album_picture)
    def test_spot_foreign_files(self):
        """
        Files that are not part of what was generated or updated shall be
        spotted.
        """
        pics = ['img%d.jpg' % i for i in range(0, 8)]
        source_subgal = self.setup_subgal('subgal', pics)

        dest_path = self.get_working_path()

        self.album.generate(dest_path)

        # add a thumbs that should not be there
        self.add_img(dest_path, 'extra_thumb.jpg')
        self.add_img(os.path.join(dest_path, 'subgal'), 'extra_thumb2.jpg')
        os.mkdir(os.path.join(dest_path, 'extra_dir'))

        # remove a pic in source_dir
        os.unlink(os.path.join(self.source_dir, 'subgal', 'img6.jpg'))

        # new objects to probe filesystem
        pics.remove('img6.jpg')
        source_subgal = Directory(os.path.join(self.source_dir, 'subgal'), [],
                                  pics, self.album)
        dest_subgal = WebalbumDir(source_subgal, [], self.album, dest_path)
        expected = map(lambda fn: os.path.join(dest_path, 'subgal', fn), [
            'extra_thumb2.jpg',
            'img6_thumb.jpg',
            'img6_small.jpg',
            'img6_medium.jpg',
            'img6.html',
            'img6_medium.html',
        ])
        self.assertEqual(sorted(dest_subgal.list_foreign_files()),
                         sorted(expected))
        source_gal = Directory(self.source_dir, [source_subgal], [],
                               self.album)
        dest_gal = WebalbumDir(source_gal, [dest_subgal], self.album,
                               dest_path)
        expected = map(lambda fn: os.path.join(dest_path, fn),
                       ['extra_thumb.jpg', 'extra_dir'])
        self.assertEqual(sorted(dest_gal.list_foreign_files()),
                         sorted(expected))
Example #8
0
    def setup_subgal(self, name, pic_names, vid_names=None):
        subgal_path = os.path.join(self.source_dir, name)
        if not os.path.isdir(subgal_path):
            os.mkdir(subgal_path)
        for pic_name in pic_names:
            self.add_img(subgal_path, pic_name)
        if vid_names:
            for vid_name in vid_names:
                self.add_video(subgal_path, vid_name)

        return Directory(subgal_path, [], pic_names, self.album)
Example #9
0
    def test_album_picture(self):
        img_names = ('ontop.jpg', 'second.jpg', )
        for img_name in img_names:
            self.add_img(self.source_dir, img_name)
        self.create_file(os.path.join(self.source_dir, 'album-picture'),
                         '\n'.join(img_names))

        # Reload the directory now that the metadata file is present
        self.album_root = Directory(self.source_dir, [], [],
                                    self.album_root.album)

        self.assertEqual(img_names[0], self.album_root.album_picture)
Example #10
0
    def test_matew_metadata_album_picture(self):
        img_names = ('ontop.jpg', 'second.jpg', 'realtitle.jpg')
        for img_name in img_names:
            self.add_img(self.source_dir, img_name)

        self.create_file(os.path.join(self.source_dir, 'album_description'),'''
Album image identifier "realtitle.jpg"
''')

        # Reload the directory now that the metadata file is created
        self.album_root = Directory(self.source_dir, [], [],
                                    self.album_root.album)

        self.assertEqual(img_names[2], self.album_root.album_picture)
    def test_sortsubgals_dirnamereverse(self):
        """
        It shall be possible to sort sub-galleries accoring to the directory
        name.
        """
        config = lazygal.config.LazygalConfig()
        config.set('webgal', 'sort-subgals', 'dirname:reverse')
        self.setup_album(config)

        subgal_names = (
            'john',
            '2012_Trip',
            'albert',
            '1999_Christmas',
            'joe',
        )
        subgals_src = []
        subgals_dst = []
        for subgal_name in subgal_names:
            path, pics = self.__setup_pics(subgal_name)
            src = Directory(path, [], pics, self.album)
            dst = WebalbumDir(src, [], self.album,
                              os.path.join(self.dest_path, subgal_name))
            subgals_src.append(src)
            subgals_dst.append(dst)

        src_dir = Directory(self.source_dir, subgals_src, [], self.album)
        dest_subgal = WebalbumDir(src_dir, subgals_dst, self.album,
                                  self.dest_path)

        dest_subgal.call_populate_deps()
        dest_subgal.sort_task.make()

        self.assertEqual(
            [subgal.source_dir.name for subgal in dest_subgal.subgals],
            [u'john', u'joe', u'albert', u'2012_Trip', u'1999_Christmas'])
    def test_sortbyfilename(self):
        """
        It shall be possible to sort images in a gallery by filename.
        """
        config = lazygal.config.LazygalConfig()
        config.set('webgal', 'sort-medias', 'filename')
        self.setup_album(config)
        subgal_path, pics = self.__setup_pics()

        src_dir = Directory(subgal_path, [], pics, self.album)
        dest_subgal = WebalbumDir(src_dir, [], self.album, self.dest_path)

        dest_subgal.call_populate_deps()
        dest_subgal.sort_task.make()

        self.assertEqual(
            [media.media.filename for media in dest_subgal.medias], [
                u'1-february.jpg', u'3-june.jpg', u'4-december.jpg',
                u'5-august.jpg', u'6-january.jpg'
            ])
Example #13
0
    def test_perdir_conf_old(self):
        """
        Lazygal shall read old-style configuration files in every source
        directory, the parent directory configuration shall apply to child
        directories.
        """

        os.makedirs(os.path.join(self.source_dir, 'gal', 'subgal'))

        # src_dir/.lazygal
        config = configparser.RawConfigParser()
        config.add_section('template-vars')
        config.set('template-vars', 'foo', 'root')
        config.set('template-vars', 'root', 'root')
        config.add_section('webgal')
        config.set('webgal', 'image-size', 'normal=800x600')
        with open(os.path.join(self.source_dir, '.lazygal'), 'a') as f:
            config.write(f)

        # src_dir/gal/.lazygal
        config = configparser.RawConfigParser()
        config.add_section('template-vars')
        config.set('template-vars', 'foo', 'gal')
        config.set('template-vars', 'gal', 'gal')
        with open(os.path.join(self.source_dir, 'gal', '.lazygal'), 'a') as f:
            config.write(f)

        # src_dir/gal/subgal/.lazygal
        config = configparser.RawConfigParser()
        config.add_section('template-vars')
        config.set('template-vars', 'foo', 'subgal')
        config.set('template-vars', 'subgal', 'subgal')
        with open(os.path.join(self.source_dir, 'gal', 'subgal', '.lazygal'), 'a') as f:
            config.write(f)

        config = lazygal.config.LazygalConfig()
        config.set('global', 'puburl', 'http://example.com/album/')
        self.setup_album(config)

        source_gal = self.setup_subgal('gal', ['gal_img.jpg'])
        source_subgal = self.setup_subgal(os.path.join('gal', 'subgal'),
                                          ['subgal_img.jpg'])
        source_root = Directory(self.source_dir, [source_gal], [], self.album)

        dest_path = self.get_working_path()

        dest_subgal = WebalbumDir(source_subgal, [], self.album, dest_path)
        self.assertEqual(dest_subgal.config.get('global', 'puburl'),
                         'http://example.com/album/')
        self.assertEqual(dest_subgal.config.get('template-vars', 'root'),
                         'root')
        self.assertEqual(dest_subgal.config.get('template-vars', 'gal'),
                         'gal')
        self.assertEqual(dest_subgal.config.get('template-vars', 'subgal'),
                         'subgal')
        self.assertEqual(dest_subgal.config.get('template-vars', 'foo'),
                         'subgal')
        self.assertEqual(dest_subgal.config.get('webgal', 'image-size'),
            [{'name': 'normal', 'defs': '800x600', 'default': True}])

        dest_gal = WebalbumDir(source_gal, [dest_subgal], self.album, dest_path)
        self.assertEqual(dest_gal.config.get('global', 'puburl'),
                         'http://example.com/album/')
        self.assertEqual(dest_gal.config.get('template-vars', 'root'), 'root')
        self.assertEqual(dest_gal.config.get('template-vars', 'gal'), 'gal')
        self.assertRaises(lazygal.config.NoOptionError,
                          dest_gal.config.get, 'template-vars', 'subgal')
        self.assertEqual(dest_gal.config.get('template-vars', 'foo'), 'gal')
        self.assertEqual(dest_gal.config.get('webgal', 'image-size'),
            [{'name': 'normal', 'defs': '800x600', 'default': True}])

        dest_root = WebalbumDir(source_root, [dest_gal], self.album, dest_path)
        self.assertEqual(dest_root.config.get('global', 'puburl'),
                         'http://example.com/album/')
        self.assertEqual(dest_root.config.get('template-vars', 'root'), 'root')
        self.assertRaises(lazygal.config.NoOptionError,
                          dest_root.config.get, 'template-vars', 'gal')
        self.assertRaises(lazygal.config.NoOptionError,
                          dest_root.config.get, 'template-vars', 'subgal')
        self.assertEqual(dest_root.config.get('template-vars', 'foo'), 'root')
        self.assertEqual(dest_root.config.get('webgal', 'image-size'),
            [{'name': 'normal', 'defs': '800x600', 'default': True}])
Example #14
0
    def setUp(self):
        super().setUp()

        self.source_dir = self.get_working_path()
        album = Album(self.source_dir)
        self.album_root = Directory(self.source_dir, [], [], album)