forked from google/WebFundamentals
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevsiteBuildStatic.py
More file actions
73 lines (63 loc) · 2.11 KB
/
devsiteBuildStatic.py
File metadata and controls
73 lines (63 loc) · 2.11 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import io
import os
import sys
GAE_MAC_BASE = '/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/'
GAE_BASE = os.getenv('GAE_BASE', GAE_MAC_BASE)
sys.path.append(GAE_BASE)
sys.path.append(os.path.join(GAE_BASE, './lib/yaml/lib/'))
sys.path.append(os.path.join(GAE_BASE, './lib/webob-1.2.3/'))
sys.path.append('./gae/lib/')
from google.appengine.dist import use_library
use_library('django', '1.3')
import yaml
import devsitePage
import devsiteIndex
raw = open('_build-me.yaml', 'r').read().decode('utf8')
files = yaml.load(raw)
build_dir = './build'
file_count_good = 0
file_count_total = 0
file_count_expected = len(files)
for source_file in files:
file_count_total += 1
first_forward = source_file.index('/')
lang = source_file[0:first_forward]
kind = 'md'
if source_file.endswith('_index.yaml'):
kind = 'yaml'
source_file = source_file[first_forward + 1:]
source_file = source_file[0:source_file.rindex('.')]
dest_file = os.path.join(build_dir, lang, source_file + '.html')
response = None
if (kind == 'yaml'):
response = devsiteIndex.getPage(source_file.replace('_index', ''), lang)
dest_file = dest_file.replace('_index', 'index')
else:
response = devsitePage.getPage(source_file, lang)
if response:
try:
dest_dir = os.path.dirname(dest_file)
if not os.path.exists(dest_dir):
os.makedirs(dest_dir)
with io.open(dest_file, 'w', encoding='utf8') as rendered_file:
rendered_file.write(response)
rendered_file.close()
msg = 'OK ' + dest_file + ' (' + str(file_count_total) + ' of '
msg += str(file_count_expected) + ')'
print(msg)
sys.stdout.flush()
file_count_good += 1
except:
print('!! ' + dest_file)
sys.stdout.flush()
else:
print('NO ' + dest_file)
sys.stdout.flush()
sys.stdout.flush()
if file_count_good == file_count_expected:
print('Completed: ' + str(file_count_good) + ' generated.')
sys.exit(0)
else:
print('An error occured, only ' + str(file_count_good) + ' were generated')
sys.exit(1)
sys.stdout.flush()