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
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." )
def main(): """ Uploads the gallery to the specified hosting provider """ # Parse the arguments args = parse_args() # Create the uploader try: uploader = get_uploader(args.hosting) 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 preparing the upload: {str(exception)}" ) sys.exit(1) # 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) # Get the location from the command line or from the gallery.json location = args.location if not location: if "remote_location" in gallery_config: location = gallery_config["remote_location"] # Check if the uploader location is valid if not uploader.check_location(location): spg_common.log(f"The specified location if not valid for this hosting type.") sys.exit(1) # Check if the gallery is built if not os.path.exists( os.path.join(gallery_root, gallery_config["public_path"], "index.html") ): spg_common.log( f"Cannot find index.html. Please build the gallery first with gallery_build.!" ) sys.exit(1) # Upload the gallery try: uploader.upload_gallery( location, os.path.join(gallery_root, gallery_config["public_path"]) ) 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 uploading the gallery: {str(exception)}" ) sys.exit(1)