-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbuild_single.py
executable file
·57 lines (46 loc) · 1.46 KB
/
build_single.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
47
48
49
50
51
52
53
54
55
56
57
import os
import sys
try:
import yaml
except ImportError:
raise SystemExit('PyYAML python module is missing')
# Allow specification of a path to look for YAML files
# Fallback to dirname of this script itself
try:
path = sys.argv[1]
except IndexError:
path = os.path.dirname(os.path.abspath(__file__))
allfiles = os.listdir(path)
# Find all YAML chapter files. Files should have "chapter" in the name
chapter_files = []
for f in allfiles:
root, ext = os.path.splitext(f)
if ('chapter' in root.lower() and 'template' not in root.lower() and
ext.lower() in ['.yml', '.yaml']):
chapter_files.append(f)
chapter_files.sort()
# Open the root.yml file that is the root of the slides
try:
with open(os.path.join(path, 'root.yml')) as f:
root = yaml.load(f)
except:
raise SystemExit('root.yml file not found')
if 'slides' not in root:
root['slides'] = []
errors = []
for chapter_file in chapter_files:
try:
with open(os.path.join(path, chapter_file)) as f:
chapter = yaml.load(f)
except:
errors.append('*** Could not load/parse %s ***\n' % chapter_file)
else:
try:
root['slides'].extend(chapter['slides'])
except:
errors.append('*** Could not find slides in %s ***\n' % chapter_file)
print yaml.dump(root, indent=4, allow_unicode=True, default_flow_style=False)
if errors:
sys.stderr.write('\n'.join(errors))
sys.exit(len(errors))
sys.exit(0)