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'])
    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'
            ])
Beispiel #3
0
    def test_second_build(self):
        """
        Once built, a webgal shall not need build.
        """
        source_subgal = self.setup_subgal('subgal', ['subgal_img.jpg'])

        dest_path = os.path.join(self.tmpdir, 'dst')
        dest_subgal = WebalbumDir(source_subgal, [], self.album, dest_path)

        self.assertTrue(
            dest_subgal.needs_build(),
            'Webalbum subgal has not been built and does not need build.')

        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 does need build because of %s.'
            % str(dest_subgal.needs_build(True)))
Beispiel #4
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.'
        )
Beispiel #5
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.')
Beispiel #6
0
    def test_second_build(self):
        """
        Once built, a webgal shall not need build.
        """
        source_subgal = self.setup_subgal(
            'subgal', ['subgal_img.jpg', 'subgal_img2.jpg'])

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

        webgal = WebalbumDir(source_subgal, [], self.album, dest_path)
        self.assertTrue(
            webgal.needs_build_quick(),
            'Webalbum subgal has not been built and does not need build.')

        self.album.generate(dest_path)

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

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

        # second pass
        self.album.generate(dest_path)

        # forced second pass
        self.album.config.set('runtime', 'check-all-dirs', True)
        self.album.generate(dest_path)
Beispiel #7
0
    def test_filecleanup(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')

        # 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:
                       unicode(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)
        self.assertEqual(sorted(dest_gal.list_foreign_files()),
                         [os.path.join(dest_path, 'extra_thumb.jpg')])
Beispiel #8
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 does need build because of %s.'
            % str(dest_subgal.needs_build(True)))

        # touch the description file
        time.sleep(1)  # ensure time diffrence for some systems
        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.')
    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'])
Beispiel #10
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 does need build because of %s.'
            % str(dest_subgal.needs_build(True)))

        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.')
    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))
Beispiel #12
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}])