forked from inventree/inventree-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
46 lines (31 loc) · 1.21 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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"
# Only perform this step if we are building on RTD server
if os.environ.get('READTHEDOCS', False):
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