Quellcode durchsuchen

Add support for env var in metadata files

master
Marien Fressinaud vor 6 Jahren
Ursprung
Commit
1910f401c5
4 geänderte Dateien mit 23 neuen und 1 gelöschten Zeilen
  1. 1
    0
      .gitignore
  2. 19
    0
      boop.py
  3. 2
    1
      photos/2018-06_Moucheraclette/metadata.yml
  4. 1
    0
      requirements.txt

+ 1
- 0
.gitignore Datei anzeigen

@@ -1,4 +1,5 @@
/output
/.env

__pycache__


+ 19
- 0
boop.py Datei anzeigen

@@ -9,13 +9,32 @@ from operator import itemgetter

from jinja2 import Environment, PackageLoader, select_autoescape
from PIL import Image, ExifTags
from dotenv import load_dotenv

from configuration import SITE_TITLE, SITE_AUTHOR, SITE_AUTHOR_WEBSITE, THEME


# Load env var from .env file
load_dotenv(dotenv_path=".env")


PICTURES_DIR_NAME = "photos"
OUTPUT_DIR_NAME = "output"

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


def pathex_constructor(loader, node):
value = loader.construct_scalar(node)
env_var, = pattern.match(value).groups()
return os.getenv(env_var)


yaml.add_constructor("!pathex", pathex_constructor)


def list_galleries_in(path):
gallery_dirs = [f for f in os.scandir(path) if f.is_dir()]

+ 2
- 1
photos/2018-06_Moucheraclette/metadata.yml Datei anzeigen

@@ -1,3 +1,4 @@
---
name: "9. Moucheraclette"
name: "Moucheraclette"
cover: "DSC04034.JPG"
password: ENV['BOOP_MOUCHERACLETTE_PASSWORD']

+ 1
- 0
requirements.txt Datei anzeigen

@@ -1,3 +1,4 @@
Jinja2
Pillow
pyyaml
python-dotenv

Laden…
Abbrechen
Speichern