2
0
mirror of https://github.com/inventree/inventree-docs.git synced 2025-04-27 13:16:43 +00:00
inventree-docs/main.py
Oliver 7233e8c235 Download the latest configuration template file when building
- So we don't have to manually copy it all the time!
2022-01-08 18:08:24 +11:00

45 lines
1.1 KiB
Python

import os
from posixpath import dirname
from urllib import request
def define_env(env):
# Ensure that the config template is always up to date
CFG_URL = "https://raw.githubusercontent.com/inventree/InvenTree/master/InvenTree/config_template.yaml"
response = request.urlopen(CFG_URL)
print(f"Reading config template from GitHub: Response {response.status}")
if response.status == 200:
data = response.read()
if len(data) > 0:
with open("_includes/config.yaml", "w") as f:
f.write(str(data.decode()))
@env.macro
def listimages(subdir):
"""
Return a listing of all asset files in the provided subdir
"""
here = os.path.dirname(__file__)
directory = os.path.join(here, 'docs', 'assets', 'images', subdir)
assets = []
allowed = [
'.png',
'.jpg',
]
for asset in os.listdir(directory):
if any([asset.endswith(x) for x in allowed]):
assets.append(os.path.join(subdir, asset))
return assets