예제 #1
0
    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'])
예제 #2
0
    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.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']
        )
예제 #3
0
    def test_resize_rotate_size(self):
        config = lazygal.config.LazygalConfig()
        config.set('webgal', 'image-size', 'std=800x600')
        self.setup_album(config)

        norotate_path = self.add_img(self.source_dir, 'norotate.jpg')
        torotate_path = self.add_img(self.source_dir, 'torotate.jpg')
        torotate = GExiv2.Metadata(torotate_path)
        torotate['Exif.Image.Orientation'] = '8'
        torotate.save_file()

        # Generate album
        dest_dir = self.get_working_path()
        self.album.generate(dest_dir)

        dest_norotate_path = os.path.join(dest_dir, 'norotate_std.jpg')
        im = Image.open(dest_norotate_path)
        self.assertEqual(im.size, (
            800,
            533,
        ))
        im.close()

        dest_torotate_path = os.path.join(dest_dir, 'torotate_std.jpg')
        im = Image.open(dest_torotate_path)
        self.assertEqual(im.size, (
            400,
            600,
        ))
        im.close()
예제 #4
0
    def test_metadata_osize_nopublish(self):
        config = lazygal.config.LazygalConfig()
        config.set('webgal', 'publish-metadata', 'No')
        self.setup_album(config)

        img_path = self.add_img(self.source_dir, 'md_filled.jpg')

        # Add some metadata
        source_image = GExiv2.Metadata(img_path)
        dummy_comment = 'nice photo'
        source_image['Exif.Photo.UserComment'] = dummy_comment
        source_image.save_file()

        # Generate album
        dest_dir = self.get_working_path()
        self.album.generate(dest_dir)

        dest_img_path = os.path.join(dest_dir, 'md_filled_small.jpg')
        dest_image = GExiv2.Metadata(dest_img_path)

        # Check that metadata is not here for reduced pictures.
        def com():
            return dest_image['Exif.Photo.UserComment']

        self.assertRaises(KeyError, com)

        # Check that metadata is not in the JSON index
        with open(os.path.join(dest_dir, 'index.json')) as json_fp:
            pindex = json.load(json_fp)
            self.assertFalse('metadata' in pindex['medias']['md_filled.jpg'])
예제 #5
0
    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.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'])
예제 #6
0
    def test_flatten(self):
        config = lazygal.config.LazygalConfig()
        config.set('global', 'dir-flattening-depth', 0)
        self.setup_album(config)

        source_subgal = self.setup_subgal('subgal', ['subgal_img.jpg'])
        self.album.generate(self.dest_path)
예제 #7
0
    def test_flatten(self):
        config = lazygal.config.LazygalConfig()
        config.set('global', 'dir-flattening-depth', 0)
        self.setup_album(config)

        source_subgal = self.setup_subgal('subgal', ['subgal_img.jpg'])
        self.album.generate(self.dest_path)
예제 #8
0
    def test_feed(self):
        config = lazygal.config.LazygalConfig()
        config.set('global', 'puburl', 'http://example.com/album/')
        self.setup_album(config)

        img_path = self.add_img(self.source_dir, 'img01.jpg')
        dest_dir = self.get_working_path()
        self.album.generate(dest_dir)

        self.assertTrue(os.path.isfile(os.path.join(dest_dir, 'index.xml')))
예제 #9
0
    def test_flattenpaginate(self):
        config = lazygal.config.LazygalConfig()
        config.set('webgal', 'thumbs-per-page', 4)
        config.set('global', 'dir-flattening-depth', 0)
        self.setup_album(config)

        pics = ['img%d.jpg' % i for i in range(0, 9)]
        source_subgal = self.setup_subgal('subgal', pics)

        self.album.generate(self.dest_path)
예제 #10
0
    def test_feed(self):
        config = lazygal.config.LazygalConfig()
        config.set('global', 'puburl', 'http://example.com/album/')
        self.setup_album(config)

        img_path = self.add_img(self.source_dir, 'img01.jpg')
        dest_dir = self.get_working_path()
        self.album.generate(dest_dir)

        self.assertTrue(os.path.isfile(os.path.join(dest_dir, 'index.xml')))
예제 #11
0
    def test_flattenpaginate(self):
        config = lazygal.config.LazygalConfig()
        config.set('webgal', 'thumbs-per-page', 4)
        config.set('global', 'dir-flattening-depth', 0)
        self.setup_album(config)

        pics = ['img%d.jpg' % i for i in range(0, 9)]
        source_subgal = self.setup_subgal('subgal', pics)

        self.album.generate(self.dest_path)
예제 #12
0
    def test_dirzip(self):
        config = lazygal.config.LazygalConfig()
        config.set('webgal', 'dirzip', 'Yes')
        self.setup_album(config)

        img_path = self.add_img(self.source_dir, 'img01.jpg')
        img_path = self.add_img(self.source_dir, 'img02.jpg')
        dest_dir = self.get_working_path()
        self.album.generate(dest_dir)

        self.assertTrue(os.path.isfile(os.path.join(dest_dir, 'src.zip')))
예제 #13
0
    def test_dirzip(self):
        config = lazygal.config.LazygalConfig()
        config.set('webgal', 'dirzip', 'Yes')
        self.setup_album(config)

        img_path = self.add_img(self.source_dir, 'img01.jpg')
        img_path = self.add_img(self.source_dir, 'img02.jpg')
        dest_dir = self.get_working_path()
        self.album.generate(dest_dir)

        self.assertTrue(os.path.isfile(os.path.join(dest_dir, 'src.zip')))
예제 #14
0
    def test_paginate(self):
        """
        It shall be possible to split big galleries on mutiple index pages.
        """
        config = lazygal.config.LazygalConfig()
        config.set('webgal', 'thumbs-per-page', 4)
        self.setup_album(config)

        pics = ['img%d.jpg' % i for i in range(0, 9)]
        source_subgal = self.setup_subgal('subgal', pics)

        self.album.generate(self.dest_path)
예제 #15
0
    def test_paginate(self):
        """
        It shall be possible to split big galleries on mutiple index pages.
        """
        config = lazygal.config.LazygalConfig()
        config.set('webgal', 'thumbs-per-page', 4)
        self.setup_album(config)

        pics = ['img%d.jpg' % i for i in range(0, 9)]
        source_subgal = self.setup_subgal('subgal', pics)

        self.album.generate(self.dest_path)
예제 #16
0
    def test_filter_by_tag(self):
        config = lazygal.config.LazygalConfig()
        config.set('webgal', 'filter-by-tag', 'lazygal')
        self.setup_album(config)

        # good pictures will be pushed on the destination, false pictures
        # should be filtered out.
        # The sub-directory 'subfalse' should not be created on the destination
        # side, because it should be empty.
        good_path         = self.add_img(self.source_dir, 'good.jpg')
        good_path2        = self.add_img(self.source_dir, 'good2.jpg')
        false_path        = self.add_img(self.source_dir, 'false.jpg')
        subgood           = self.setup_subgal('subgood', ['subgood.jpg', 'subfalse.jpg'])
        subfalse          = self.setup_subgal('subfalse', ['subgood.jpg', 'subfalse.jpg'])
        good_subdir_path  = os.path.join(self.source_dir, subgood.name, 'subgood.jpg')
        false_subdir_path = os.path.join(self.source_dir, subfalse.name, 'subfalse.jpg')
        good     = GExiv2.Metadata(good_path)
        good2    = GExiv2.Metadata(good_path2)
        false    = GExiv2.Metadata(false_path)
        good_sd  = GExiv2.Metadata(good_subdir_path)
        false_sd = GExiv2.Metadata(false_subdir_path)
        good['Iptc.Application2.Keywords']     = 'lazygal'
        good['Xmp.dc.subject']                 = 'lazygal2'
        good.save_file()
        good2['Iptc.Application2.Keywords']    = 'lazygalagain'
        good2['Xmp.dc.subject']                = 'lazygal'
        good2.save_file()
        false['Iptc.Application2.Keywords']    = 'another_tag'
        false.save_file()
        good_sd['Iptc.Application2.Keywords']  = 'lazygal'
        good_sd['Xmp.dc.subject']              = 'lazygal2'
        good_sd.save_file()
        false_sd['Iptc.Application2.Keywords'] = 'lazygal_lazygal'
        false_sd['Xmp.dc.subject']             = 'lazygal2'
        false_sd.save_file()

        # generate album
        dest_dir = self.get_working_path()
        self.album.generate(dest_dir)

        try:
            self.assertTrue(os.path.isfile(os.path.join(dest_dir, 'good_thumb.jpg')))
            self.assertTrue(os.path.isfile(os.path.join(dest_dir, 'good2_thumb.jpg')))
            self.assertFalse(os.path.isfile(os.path.join(dest_dir, 'false_thumb.jpg')))
            self.assertTrue(os.path.isfile(os.path.join(dest_dir, 'subgood', 'subgood_thumb.jpg')))
            self.assertFalse(os.path.isfile(os.path.join(dest_dir, 'subfalse', 'subfalse_thumb.jpg')))
            self.assertFalse(os.path.isfile(os.path.join(dest_dir, 'subfalse')))
        except AssertionError:
            print "\n contents of dest_dir : "
            print os.listdir(dest_dir)
            raise
예제 #17
0
    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.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'])
예제 #18
0
    def test_originals_symlinks(self):
        config = lazygal.config.LazygalConfig()
        config.set('webgal', 'original', 'Yes')
        config.set('webgal', 'original-symlink', 'Yes')
        self.setup_album(config)

        img_path = self.add_img(self.source_dir, 'symlink_target.jpg')

        dest_dir = self.get_working_path()
        self.album.generate(dest_dir)

        symlink = os.path.join(dest_dir, os.path.basename(img_path))
        # Test if the original in the webgal is a symlink
        self.assertTrue(os.path.islink(symlink))
        # Test if that symlink point to the image in the source_dir
        self.assertEqual(os.path.realpath(symlink), img_path)
예제 #19
0
    def test_originals_symlinks(self):
        config = lazygal.config.LazygalConfig()
        config.set('webgal', 'original', 'Yes')
        config.set('webgal', 'original-symlink', 'Yes')
        self.setup_album(config)

        img_path = self.add_img(self.source_dir, 'symlink_target.jpg')

        dest_dir = self.get_working_path()
        self.album.generate(dest_dir)

        symlink = os.path.join(dest_dir, os.path.basename(img_path))
        # Test if the original in the webgal is a symlink
        self.assertTrue(os.path.islink(symlink))
        # Test if that symlink point to the image in the source_dir
        self.assertEqual(os.path.realpath(symlink), img_path)
예제 #20
0
    def test_cleanup(self):
        """
        Check that the foreign files are deleted.
        """
        config = lazygal.config.LazygalConfig()
        config.set('global', 'clean-destination', "true")
        self.setup_album(config)

        pics = ['img%02d.jpg' % i for i in range(4, 8)]
        source_subgal = self.setup_subgal('subgal', pics)

        dest_path = self.get_working_path()

        self.album.generate(dest_path)

        # add thumbs and directories 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'))
        self.add_img(os.path.join(dest_path, 'extra_dir'), 'extra_thumb3.jpg')

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

        self.album.generate(dest_path)

        try:
            for f in [
                    'extra_thumb2.jpg',
                    'img06_thumb.jpg',
                    'img06_small.jpg',
                    'img06_medium.jpg',
                    'img06.html',
                    'img06_medium.html',
            ]:
                self.assertFalse(
                    os.path.isfile(os.path.join(dest_path, 'subgal', f)))

            for f in ['extra_thumb.jpg']:
                self.assertFalse(os.path.isfile(os.path.join(dest_path, f)))
            for f in ['extra_dir']:
                self.assertFalse(os.path.isdir(os.path.join(dest_path, f)))
        except AssertionError:
            print("\n contents of dest_path : ")
            print(sorted(os.listdir(dest_path)))
            print(sorted(os.listdir(os.path.join(dest_path, 'subgal'))))
            raise
예제 #21
0
    def test_sizeasoriginal(self):
        config = lazygal.config.LazygalConfig()
        config.set('webgal', 'original', True)
        config.set('webgal', 'image-size', 'std=0x0')
        self.setup_album(config)

        self.add_img(self.source_dir, 'img.jpg')

        dest_dir = self.get_working_path()
        self.album.generate(dest_dir)

        shouldbeoriginal = os.path.join(dest_dir, 'img.jpg')
        im = Image.open(shouldbeoriginal)
        self.assertEqual(im.size, (
            640,
            427,
        ))
        im.close()
예제 #22
0
    def test_resize_rotate_size(self):
        config = lazygal.config.LazygalConfig()
        config.set('webgal', 'image-size', 'std=800x600')
        self.setup_album(config)

        norotate_path = self.add_img(self.source_dir, 'norotate.jpg')
        torotate_path = self.add_img(self.source_dir, 'torotate.jpg')
        torotate = GExiv2.Metadata(torotate_path)
        torotate['Exif.Image.Orientation'] = '8'
        torotate.save_file()

        # Generate album
        dest_dir = self.get_working_path()
        self.album.generate(dest_dir)

        dest_norotate_path = os.path.join(dest_dir, 'norotate_std.jpg')
        self.assertEqual(Image.open(dest_norotate_path).size, (800, 533, ))
        dest_torotate_path = os.path.join(dest_dir, 'torotate_std.jpg')
        self.assertEqual(Image.open(dest_torotate_path).size, (400, 600, ))
예제 #23
0
    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'
            ])
예제 #24
0
    def test_filter_and_dirzip(self):
        config = lazygal.config.LazygalConfig()
        config.set('webgal', 'dirzip', 'Yes')
        config.set('webgal', 'filter-by-tag', 'lazygal')
        self.setup_album(config)

        # We need at least two pictures to display, because lazygal generates a
        # zip archive only if there is more than one picture.
        tagfound_path = self.add_img(self.source_dir, 'tagfound.jpg')
        tagfound_path2 = self.add_img(self.source_dir, 'tagfound2.jpg')
        tagnotfound_path = self.add_img(self.source_dir, 'tagnotfound.jpg')
        tagfound = GExiv2.Metadata(tagfound_path)
        tagfound2 = GExiv2.Metadata(tagfound_path2)
        tagnotfound = GExiv2.Metadata(tagnotfound_path)
        tagfound['Iptc.Application2.Keywords'] = 'lazygal'
        tagfound['Xmp.dc.subject'] = 'lazygal2'
        tagfound.save_file()
        tagfound2['Iptc.Application2.Keywords'] = 'lazygalagain'
        tagfound2['Xmp.dc.subject'] = 'lazygal'
        tagfound2.save_file()
        tagnotfound['Iptc.Application2.Keywords'] = 'another_tag'
        tagnotfound.save_file()

        # generate album
        dest_dir = self.get_working_path()
        self.album.generate(dest_dir)

        try:
            self.assertTrue(os.path.isfile(os.path.join(dest_dir, 'src.zip')))
            self.assertTrue(
                os.path.isfile(os.path.join(dest_dir, 'tagfound_thumb.jpg')))
            self.assertTrue(
                os.path.isfile(os.path.join(dest_dir, 'tagfound2_thumb.jpg')))
            self.assertFalse(
                os.path.isfile(os.path.join(dest_dir, 'false_thumb.jpg')))
        except AssertionError:
            print("\n contents of dest_dir : ")
            print(os.listdir(dest_dir))
            raise
예제 #25
0
    def test_metadata_osize_nopublish(self):
        config = lazygal.config.LazygalConfig()
        config.set('webgal', 'publish-metadata', 'No')
        self.setup_album(config)

        img_path = self.add_img(self.source_dir, 'md_filled.jpg')

        # Add some metadata
        source_image = GExiv2.Metadata(img_path)
        dummy_comment = 'nice photo'
        source_image['Exif.Photo.UserComment'] = dummy_comment
        source_image.save_file()

        # Generate album
        dest_dir = self.get_working_path()
        self.album.generate(dest_dir)

        dest_img_path = os.path.join(dest_dir, 'md_filled_small.jpg')
        dest_image = GExiv2.Metadata(dest_img_path)

        # Check that metadata is not here for reduced pictures.
        def com(): return dest_image['Exif.Photo.UserComment']
        self.assertRaises(KeyError, com)
예제 #26
0
    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'])
예제 #27
0
    def test_filter_and_dirzip(self):
        config = lazygal.config.LazygalConfig()
        config.set('webgal', 'dirzip', 'Yes')
        config.set('webgal', 'filter-by-tag', 'lazygal')
        self.setup_album(config)

        # We need at least two pictures to display, because lazygal generates a
        # zip archive only if there is more than one picture.
        good_path = self.add_img(self.source_dir, 'good.jpg')
        good_path2 = self.add_img(self.source_dir, 'good2.jpg')
        false_path = self.add_img(self.source_dir, 'false.jpg')
        good = GExiv2.Metadata(good_path)
        good2 = GExiv2.Metadata(good_path2)
        false = GExiv2.Metadata(false_path)
        good['Iptc.Application2.Keywords'] = 'lazygal'
        good['Xmp.dc.subject'] = 'lazygal2'
        good.save_file()
        good2['Iptc.Application2.Keywords'] = 'lazygalagain'
        good2['Xmp.dc.subject'] = 'lazygal'
        good2.save_file()
        false['Iptc.Application2.Keywords'] = 'another_tag'
        false.save_file()

        # generate album
        dest_dir = self.get_working_path()
        self.album.generate(dest_dir)

        try:
            self.assertTrue(os.path.isfile(os.path.join(dest_dir, 'src.zip')))
            self.assertTrue(os.path.isfile(os.path.join(dest_dir, 'good_thumb.jpg')))
            self.assertTrue(os.path.isfile(os.path.join(dest_dir, 'good2_thumb.jpg')))
            self.assertFalse(os.path.isfile(os.path.join(dest_dir, 'false_thumb.jpg')))
        except AssertionError:
            print "\n contents of dest_dir : "
            print os.listdir(dest_dir)
            raise
예제 #28
0
    def test_filter_by_tag(self):
        config = lazygal.config.LazygalConfig()
        config.set('webgal', 'filter-by-tag', 'lazygal')
        self.setup_album(config)

        # tagfound pictures will be pushed on the destination, tagnotfound pictures
        # should be filtered out.
        # The sub-directory 'sdir_tagnotfound' should not be created on the destination
        # side, because it should be empty.
        tagfound_path = self.add_img(self.source_dir, 'tagfound.jpg')
        tagfound2_path = self.add_img(self.source_dir, 'tagfound2.jpg')
        tagnotfound_path = self.add_img(self.source_dir, 'tagnotfound.jpg')
        untagged_path = self.add_img(self.source_dir, 'untagged.jpg')
        sdir_tagfound = self.setup_subgal(
            'sdir_tagfound', ['sdir_tagfound.jpg', 'sdir_tagnotfound.jpg'])
        sdir_tagnotfound = self.setup_subgal('sdir_tagnotfound',
                                             ['sdir_tagnotfound.jpg'])
        sdir_untagged = self.setup_subgal('sdir_untagged', ['untagged.jpg'])
        tagfound_subdir_path = os.path.join(self.source_dir,
                                            sdir_tagfound.name,
                                            'sdir_tagfound.jpg')
        tagnotfound_subdir_path = os.path.join(self.source_dir,
                                               sdir_tagnotfound.name,
                                               'sdir_tagnotfound.jpg')
        tagfound = GExiv2.Metadata(tagfound_path)
        tagfound2 = GExiv2.Metadata(tagfound2_path)
        tagnotfound = GExiv2.Metadata(tagnotfound_path)
        tagfound_sd = GExiv2.Metadata(tagfound_subdir_path)
        tagnotfound_sd = GExiv2.Metadata(tagnotfound_subdir_path)
        tagfound['Iptc.Application2.Keywords'] = 'lazygal'
        tagfound['Xmp.dc.subject'] = 'lazygal2'
        tagfound.save_file()
        tagfound2['Iptc.Application2.Keywords'] = 'lazygalagain'
        tagfound2['Xmp.dc.subject'] = 'lazygal'
        tagfound2.save_file()
        tagnotfound['Iptc.Application2.Keywords'] = 'another_tag'
        tagnotfound.save_file()
        tagfound_sd['Iptc.Application2.Keywords'] = 'lazygal'
        tagfound_sd['Xmp.dc.subject'] = 'lazygal2'
        tagfound_sd.save_file()
        tagnotfound_sd['Iptc.Application2.Keywords'] = 'lazygal_lazygal'
        tagnotfound_sd['Xmp.dc.subject'] = 'lazygal2'
        tagnotfound_sd.save_file()

        # generate album
        dest_dir = self.get_working_path()
        self.album.generate(dest_dir)

        try:
            self.assertTrue(
                os.path.isdir(os.path.join(dest_dir, 'sdir_tagfound')))
            self.assertTrue(
                os.path.isfile(os.path.join(dest_dir, 'tagfound_thumb.jpg')))
            self.assertTrue(
                os.path.isfile(os.path.join(dest_dir, 'tagfound2_thumb.jpg')))
            self.assertFalse(
                os.path.isfile(os.path.join(dest_dir,
                                            'tagnotfound_thumb.jpg')))
            self.assertTrue(
                os.path.isfile(
                    os.path.join(dest_dir, 'sdir_tagfound',
                                 'sdir_tagfound_thumb.jpg')))
            self.assertFalse(
                os.path.isfile(
                    os.path.join(dest_dir, 'sdir_tagnotfound',
                                 'sdir_tagnotfound_thumb.jpg')))
            self.assertFalse(
                os.path.isdir(os.path.join(dest_dir, 'sdir_tagnotfound')))
            self.assertFalse(
                os.path.isfile(
                    os.path.join(dest_dir, 'sdir_untagged', 'untagged.jpg')))
            self.assertFalse(
                os.path.isdir(os.path.join(dest_dir, 'sdir_untagged')))
        except AssertionError:
            print("\n contents of dest_dir : ")
            print(os.listdir(dest_dir))
            raise
예제 #29
0
    def test_clean_dirsymlinks(self):
        """
        Check that symlinks in directory source, that should make albums
        in dest, are not cleaned up in dest.
        """
        config = lazygal.config.LazygalConfig()
        config.set('global', 'clean-destination', "true")
        self.setup_album(config)

        pics = ['img.jpg']
        source_subgal = self.setup_subgal('subgal', pics)

        # add a symlink on source that should be duplicated in dest
        out_of_tree_subgal = os.path.join(self.get_working_path(),
                                          'oot_subgal')
        os.mkdir(out_of_tree_subgal)
        self.add_img(out_of_tree_subgal, 'oot_img.jpg')
        os.symlink(out_of_tree_subgal,
                   os.path.join(self.source_dir, 'oot_subgal_symlink'))

        dest_path = self.get_working_path()

        self.album.generate(dest_path)

        # all the files in subgal should be here after the first generation
        try:
            self.assertTrue(os.path.isdir(os.path.join(dest_path, 'subgal')))
            for f in [
                    'img_thumb.jpg',
                    'img_small.jpg',
                    'img_medium.jpg',
                    'img.html',
                    'img_medium.html',
            ]:
                self.assertTrue(
                    os.path.isfile(os.path.join(dest_path, 'subgal', f)))
            self.assertTrue(
                os.path.isdir(os.path.join(dest_path, 'oot_subgal_symlink')))
            for f in [
                    'oot_img_thumb.jpg',
                    'oot_img_small.jpg',
                    'oot_img_medium.jpg',
                    'oot_img.html',
                    'oot_img_medium.html',
            ]:
                self.assertTrue(
                    os.path.isfile(
                        os.path.join(dest_path, 'oot_subgal_symlink', f)))
        except AssertionError:
            print("\n contents of dest_path after first generation: ")
            print(sorted(os.listdir(dest_path)))
            print(sorted(os.listdir(os.path.join(dest_path, 'subgal'))))
            raise

        # remove the pic in subgal, and force a new generation
        os.unlink(os.path.join(self.source_dir, 'subgal', 'img.jpg'))
        os.rmdir(os.path.join(self.source_dir, 'subgal'))
        self.album.generate(dest_path)

        # only file in symlinkd gal should be there
        try:
            self.assertFalse(os.path.exists(os.path.join(dest_path, 'subgal')))
            for f in [
                    'img_thumb.jpg',
                    'img_small.jpg',
                    'img_medium.jpg',
                    'img.html',
                    'img_medium.html',
            ]:
                self.assertFalse(
                    os.path.exists(os.path.join(dest_path, 'subgal', f)))
            self.assertTrue(
                os.path.isdir(os.path.join(dest_path, 'oot_subgal_symlink')))
            for f in [
                    'oot_img_thumb.jpg',
                    'oot_img_small.jpg',
                    'oot_img_medium.jpg',
                    'oot_img.html',
                    'oot_img_medium.html',
            ]:
                self.assertTrue(
                    os.path.isfile(
                        os.path.join(dest_path, 'oot_subgal_symlink', f)))
        except AssertionError:
            print("\n contents of dest_path after first generation: ")
            print(sorted(os.listdir(dest_path)))
            print(sorted(os.listdir(os.path.join(dest_path, 'subgal'))))
            raise
예제 #30
0
    def test_types(self):
        config = lazygal.config.LazygalConfig()

        # bool
        for true in ('1', 'yes', 'true', 'on'):
            config.set('runtime', 'quiet', true)
            self.assertTrue(config.get('runtime', 'quiet') is True, true)
        for false in ('0', 'no', 'false', 'off'):
            config.set('runtime', 'quiet', false)
            self.assertTrue(config.get('runtime', 'quiet') is False, false)

        # int
        config.set('webgal', 'thumbs-per-page', '2')
        self.assertEqual(config.get('webgal', 'thumbs-per-page'), 2)

        # int or false
        config.set('global', 'dir-flattening-depth', 'False')
        self.assertTrue(config.get('global', 'dir-flattening-depth') is False)
        config.set('global', 'dir-flattening-depth', '2')
        self.assertEqual(config.get('global', 'dir-flattening-depth'), 2)

        # list
        config.set('webgal', 'filter-by-tag', 'foo, bar')
        self.assertEqual(config.get('webgal', 'filter-by-tag'), ['foo', 'bar'])

        # dict
        config.set('webgal', 'image-size', 'medium=foo, normal=bar')
        self.assertEqual(config.get('webgal', 'image-size'),
                         [{'name': 'medium', 'defs': 'foo', 'default': True},
                          {'name': 'normal', 'defs': 'bar', 'default': False},
                         ])

        # order
        config.set('webgal', 'sort-medias', 'dirname:reverse')
        self.assertEqual(config.get('webgal', 'sort-medias'),
                         {'order': 'dirname', 'reverse': True})

        # false or string
        config.set('webgal', 'original-baseurl', 'False')
        self.assertTrue(config.get('webgal', 'original-baseurl') is False)
        config.set('webgal', 'original-baseurl', './foo')
        self.assertEqual(config.get('webgal', 'original-baseurl'), './foo')
예제 #31
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}])
예제 #32
0
    def test_perdir_conf(self):
        """
        Lazygal shall read 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')
        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')

        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(ConfigParser.NoOptionError,
                          dest_gal.config.get, 'template-vars', 'subgal')
        self.assertEqual(dest_gal.config.get('template-vars', 'foo'), 'gal')

        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(ConfigParser.NoOptionError,
                          dest_root.config.get, 'template-vars', 'gal')
        self.assertRaises(ConfigParser.NoOptionError,
                          dest_root.config.get, 'template-vars', 'subgal')
        self.assertEqual(dest_root.config.get('template-vars', 'foo'), 'root')
예제 #33
0
    def test_clean_empty_dirs(self):
        """
        Check that empty dirs at destination are removed
        .
        This case might happen when (1) the destination dir is created according
        to the contents of source_dir.
        (2) Then source_dir becomes empty, either because all the images have
        been removed, or because tag filtering is applied with different
        settings. The next lazygal generation should remove the destination dir.
        """
        config = lazygal.config.LazygalConfig()
        config.set('global', 'clean-destination', "true")
        self.setup_album(config)

        pics = ['img.jpg']
        source_subgal = self.setup_subgal('subgal', pics)

        dest_path = self.get_working_path()
        self.album.generate(dest_path)

        # all the files in subgal should be here after the first generation
        try:
            for f in [
                    'img_thumb.jpg',
                    'img_small.jpg',
                    'img_medium.jpg',
                    'img.html',
                    'img_medium.html',
            ]:
                self.assertTrue(
                    os.path.isfile(os.path.join(dest_path, 'subgal', f)))

            for f in ['subgal']:
                self.assertTrue(os.path.isdir(os.path.join(dest_path, f)))
        except AssertionError:
            print("\n contents of dest_path after first generation: ")
            print(sorted(os.listdir(dest_path)))
            print(sorted(os.listdir(os.path.join(dest_path, 'subgal'))))
            raise

        # remove the pic in subgal, and force a new generation
        os.unlink(os.path.join(self.source_dir, 'subgal', 'img.jpg'))
        self.album.generate(dest_path)

        # now the subdirectory subgal and its contents should no longer be there
        try:
            for f in [
                    'img.jpg',
                    'img_thumb.jpg',
                    'img_small.jpg',
                    'img_medium.jpg',
                    'img.html',
                    'img_medium.html',
            ]:
                self.assertFalse(
                    os.path.isfile(os.path.join(dest_path, 'subgal', f)))

            for f in ['subgal']:
                self.assertFalse(os.path.isdir(os.path.join(dest_path, f)))
        except AssertionError:
            print("\n contents of dest_path after the second generation: ")
            print(sorted(os.listdir(dest_path)))
            print(sorted(os.listdir(os.path.join(dest_path, 'subgal'))))
            raise