Browse Source

Add support for env var in metadata files

master
Marien Fressinaud 6 years ago
parent
commit
1910f401c5
4 changed files with 23 additions and 1 deletions
  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 View File

/output /output
/.env


__pycache__ __pycache__



+ 19
- 0
boop.py View File



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


from configuration import SITE_TITLE, SITE_AUTHOR, SITE_AUTHOR_WEBSITE, THEME 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" PICTURES_DIR_NAME = "photos"
OUTPUT_DIR_NAME = "output" 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): def list_galleries_in(path):
gallery_dirs = [f for f in os.scandir(path) if f.is_dir()] gallery_dirs = [f for f in os.scandir(path) if f.is_dir()]

+ 2
- 1
photos/2018-06_Moucheraclette/metadata.yml View File

--- ---
name: "9. Moucheraclette"
name: "Moucheraclette"
cover: "DSC04034.JPG" cover: "DSC04034.JPG"
password: ENV['BOOP_MOUCHERACLETTE_PASSWORD']

+ 1
- 0
requirements.txt View File

Jinja2 Jinja2
Pillow Pillow
pyyaml pyyaml
python-dotenv

Loading…
Cancel
Save