Browse Source

Fix yaml env loading

master
Marien Fressinaud 5 years ago
parent
commit
9a223fa105
1 changed files with 3 additions and 3 deletions
  1. 3
    3
      boop.py

+ 3
- 3
boop.py View File

# Configure YAML to accept environment variables in metadata files # Configure YAML to accept environment variables in metadata files
# Based on https://stackoverflow.com/a/27232341 solution # Based on https://stackoverflow.com/a/27232341 solution
pattern = re.compile(r"^ENV\[\'(.*)\'\]$") pattern = re.compile(r"^ENV\[\'(.*)\'\]$")
yaml.add_implicit_resolver("!pathex", pattern)
yaml.add_implicit_resolver("!pathex", pattern, Loader=yaml.SafeLoader)




def pathex_constructor(loader, node): def pathex_constructor(loader, node):
return os.getenv(env_var) return os.getenv(env_var)




yaml.add_constructor("!pathex", pathex_constructor)
yaml.add_constructor("!pathex", pathex_constructor, yaml.SafeLoader)




def list_galleries_in(path): def list_galleries_in(path):
metadata_path = os.path.join(gallery_dir.path, "metadata.yml") metadata_path = os.path.join(gallery_dir.path, "metadata.yml")
if os.path.exists(metadata_path): if os.path.exists(metadata_path):
with open(metadata_path, "r") as metadata_file: with open(metadata_path, "r") as metadata_file:
metadata = yaml.load(metadata_file)
metadata = yaml.safe_load(metadata_file)


private = False private = False
url = f"{gallery_dir.name}.html" url = f"{gallery_dir.name}.html"

Loading…
Cancel
Save