コード例 #1
0
    def test_get_gallery_logic(self):
        config_logic_mapping = [
            (dict(), FilesGalleryLogic),
            (dict(remote_gallery_type=''), FilesGalleryLogic),
            (dict(remote_gallery_type='onedrive'), OnedriveGalleryLogic),
            (dict(remote_gallery_type='google'), GoogleGalleryLogic),
            (dict(remote_gallery_type='aaaaaaaa'), FilesGalleryLogic),
        ]

        for config_logic in config_logic_mapping:
            self.assertIs(
                config_logic[1],
                gallery_logic.get_gallery_logic(config_logic[0]).__class__)
コード例 #2
0
    def gallery_build(self, force_thumbnail_regeneration=False):
        '''
        Build the gallery (create thumbnails)

        Args:
            force_thumbnail_regeneration (bool, optional):
                Force to re-generate all thumbnails. Defaults to False.

        Raises:
            RuntimeError: will be raised if there is any error

        Returns:
            bool: returns True if everything worked fine
        '''

        gallery_config_path = _pltostr(self.gallery_config_path)
        gallery_config = spg_common.read_gallery_config(gallery_config_path)

        if not gallery_config:
            spg_common.log(
                f"Cannot load the gallery.json file ({gallery_config_path})!")
            ### TODO: Implement Error Handling
            raise RuntimeError

        # Get the gallery logic
        gallery_logic = get_gallery_logic(gallery_config)

        spg_common.log(f"Generating thumbnails for {self.name}...")
        gallery_logic.create_thumbnails(force_thumbnail_regeneration)

        spg_common.log(
            f"Generating the images_data.json file for {self.name}...")
        gallery_logic.create_images_data_file()

        spg_common.log(f"Creating the index.html for {self.name}...")
        gallery_build.build_html(gallery_config)

        spg_common.log(
            f"The gallery {self.name} was built successfully. Open {self.public_gallery_dir}"
        )

        return True
コード例 #3
0
def main():
    """
    Builds the HTML gallery, generating all required files for display (thumbnails, images_data.json and index.html).
    """

    # Parse the arguments
    args = parse_args()

    # Read the gallery config
    gallery_root = args.path
    gallery_config_path = os.path.join(gallery_root, "gallery.json")
    gallery_config = spg_common.read_gallery_config(gallery_config_path)
    if not gallery_config:
        spg_common.log(
            f"Cannot load the gallery.json file ({gallery_config_path})!")
        sys.exit(1)

    spg_common.log("Building the Simple Photo Gallery...")

    # Get the gallery logic
    gallery_logic = get_gallery_logic(gallery_config)

    # Check if thumbnails exist and generate them if needed or if specified by the user
    try:
        spg_common.log("Generating thumbnails...")
        gallery_logic.create_thumbnails(args.force_thumbnails)
    except spg_common.SPGException as exception:
        spg_common.log(exception.message)
        sys.exit(1)
    except Exception as exception:
        spg_common.log(
            f"Something went wrong while generating the thumbnails: {str(exception)}"
        )
        sys.exit(1)

    # Generate the images_data.json
    try:
        spg_common.log("Generating the images_data.json file...")
        gallery_logic.create_images_data_file()
        spg_common.log(
            "The image descriptions are stored in images_data.json. You can edit the file to add more "
            "descriptions and build the gallery again.")
    except spg_common.SPGException as exception:
        spg_common.log(exception.message)
        sys.exit(1)
    except Exception as exception:
        spg_common.log(
            f"Something went wrong while generating the images_data.json file: {str(exception)}"
        )
        sys.exit(1)

    # Build the HTML from the templates
    try:
        spg_common.log("Creating the index.html...")
        build_html(gallery_config)
    except Exception as exception:
        spg_common.log(
            f"Something went wrong while generating the gallery HTML: {str(exception)}"
        )
        sys.exit(1)

    spg_common.log(
        "The gallery was built successfully. Open public/index.html to view it."
    )