updated magcms / ppee for newer python infrastructure

This commit is contained in:
Richard Thier 2024-09-09 13:45:12 +02:00
parent dbaf4047b4
commit bfe35a1c5b

View File

@ -296,7 +296,10 @@ def get_settings():
"settings.yaml in the current working directory")
try:
settings = yaml.safe_load(open("settings.yaml", "r"))
# Deprecated:
# settings = yaml.safe_load(open("settings.yaml", "r"))
yamli = yaml.YAML(typ='safe', pure=True)
settings = yamli.load(open("settings.yaml", "r"))
except yaml.YAMLError as exc:
if hasattr(exc, 'problem_mark'):
mark = exc.problem_mark
@ -352,7 +355,9 @@ def get_settings():
def get_gallery_templates(theme, gallery_path="", parent_templates=None):
theme_path = Path(__file__).parent.joinpath("themes", theme).exists()
available_themes = theme, "', '".join(Path(__file__).parent.joinpath("themes").listdir())
# available_themes = theme, "', '".join(Path(__file__).parent.joinpath("themes").listdir())
themesdir = "".join(Path(__file__).parent.joinpath("themes"))
available_themes = theme, "', '".join(os.listdir(themesdir))
error(theme_path, "'%s' is not an existing theme, available themes are '%s'" % available_themes)
@ -387,7 +392,10 @@ def process_directory(gallery_name, settings, parent_templates, parent_gallery_p
gallery_path = gallery_name
try:
gallery_settings = yaml.safe_load(open(Path(".").joinpath(gallery_path, "settings.yaml").abspath(), "r"))
# DEPRECATED:
# gallery_settings = yaml.safe_load(open(Path(".").joinpath(gallery_path, "settings.yaml").abspath(), "r"))
yamli = yaml.YAML(typ='safe', pure=True)
gallery_settings = yamli.load(open(os.path.abspath(Path(".").joinpath(gallery_path, "settings.yaml")), "r"))
except yaml.YAMLError as exc:
if hasattr(exc, 'problem_mark'):
mark = exc.problem_mark
@ -395,14 +403,14 @@ def process_directory(gallery_name, settings, parent_templates, parent_gallery_p
else:
error(False, "There are something wrong in %s/settings.yaml" % (gallery_path))
error(isinstance(gallery_settings, dict), "Your %s should be a dict" % gallery_name.joinpath("settings.yaml"))
error(gallery_settings.get("title"), "You should specify a title in %s" % gallery_name.joinpath("settings.yaml"))
error(isinstance(gallery_settings, dict), "Your %s should be a dict" % os.path.join(gallery_name, "settings.yaml"))
error(gallery_settings.get("title"), "You should specify a title in %s" % os.path.join(gallery_name, "settings.yaml"))
gallery_cover = {}
sub_galleries = [x for x in Path(".").joinpath(gallery_path).listdir() if x.joinpath("settings.yaml").exists()]
sub_galleries = [x for x in os.listdir(os.path.join(Path("."), gallery_path)) if os.path.exists(os.path.join(x, "settings.yaml"))]
Path("build").joinpath(gallery_path).makedirs_p()
os.path.join(Path("build"), gallery_path).makedirs_p()
if not gallery_settings.get("public", True):
build_gallery(settings, gallery_settings, gallery_path, parent_templates)
@ -414,7 +422,7 @@ def process_directory(gallery_name, settings, parent_templates, parent_gallery_p
else:
error(gallery_settings.get("sections") is not False,
"The gallery in %s can't have both sections and subgalleries" % gallery_name.joinpath("settings.yaml"))
"The gallery in %s can't have both sections and subgalleries" % os.path.join(gallery_name, "settings.yaml"))
# Sub galleries found, create index with them instead of a gallery
theme = gallery_settings.get("theme", settings.get("theme", "exposure"))
@ -443,18 +451,18 @@ def process_directory(gallery_name, settings, parent_templates, parent_gallery_p
def create_cover(gallery_name, gallery_settings, gallery_path):
error(gallery_settings.get("title"), "Your gallery describe in %s need to have a "
"title" % gallery_name.joinpath("settings.yaml"))
"title" % os.path.join(gallery_name, "settings.yaml"))
error(gallery_settings.get("cover"), "You should specify a path to a cover picture "
"in %s" % gallery_name.joinpath("settings.yaml"))
"in %s" % os.path.join(gallery_name, "settings.yaml"))
if isinstance(gallery_settings["cover"], dict):
cover_image_path = gallery_path.joinpath(gallery_settings["cover"]["name"])
cover_image_url = gallery_name.joinpath(gallery_settings["cover"]["name"])
cover_image_path = Path(gallery_path).joinpath(gallery_settings["cover"]["name"])
cover_image_url = Path(gallery_name).joinpath(gallery_settings["cover"]["name"])
cover_image_type = gallery_settings["cover"]["type"]
else:
cover_image_path = gallery_path.joinpath(gallery_settings["cover"])
cover_image_url = gallery_name.joinpath(gallery_settings["cover"])
cover_image_path = Path(gallery_path).joinpath(gallery_settings["cover"])
cover_image_url = Path(gallery_name).joinpath(gallery_settings["cover"])
cover_image_type = "image"
error(cover_image_path.exists(), "File for %s cover image doesn't exist at "
@ -625,7 +633,7 @@ def main():
front_page_galleries_cover = []
galleries_dirs = [x for x in Path(".").listdir() if x.joinpath("settings.yaml").exists()]
galleries_dirs = [x for x in os.listdir(Path(".")) if os.path.isfile(os.path.join(x, "settings.yaml"))]
error(galleries_dirs, "I can't find at least one directory with a settings.yaml in the current working "
"directory (NOT the settings.yaml in your current directory, but one INSIDE A "