summaryrefslogtreecommitdiff
path: root/site_builder/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'site_builder/__init__.py')
-rw-r--r--site_builder/__init__.py39
1 files changed, 20 insertions, 19 deletions
diff --git a/site_builder/__init__.py b/site_builder/__init__.py
index 1ebef36..9478dce 100644
--- a/site_builder/__init__.py
+++ b/site_builder/__init__.py
@@ -7,15 +7,13 @@ Site Builder
7""" 7"""
8 8
9import os 9import os
10from os import path
11import jinja2 10import jinja2
12import pagebuilder
13from datetime import datetime 11from datetime import datetime
14from docutils.core import publish_parts 12from docutils.core import publish_parts
15from docutils.io import FileInput
16 13
17 14
18TEMPLATES = path.join(path.dirname(path.dirname(__file__)), "templates") 15TEMPLATES = os.path.join(
16 os.path.dirname(os.path.dirname(__file__)), "templates")
19 17
20 18
21def get_template(name): 19def get_template(name):
@@ -25,27 +23,27 @@ def get_template(name):
25 23
26 24
27def build_standard_page(filename, output_name): 25def build_standard_page(filename, output_name):
28 parts = publish_parts(open(filename, 'r').read(), writer_name='html') 26 parts = publish_parts(open(filename, "r").read(), writer_name="html")
29 template = get_template('page.html') 27 template = get_template("page.html")
30 28
31 try: 29 try:
32 os.makedirs(path.dirname(output_name)) 30 os.makedirs(os.path.dirname(output_name))
33 except OSError: 31 except OSError:
34 pass # directory exists 32 pass # directory exists
35 33
36 open(output_name, 'w').write(template.render( 34 open(output_name, "w").write(template.render(
37 contents=parts['html_body'], 35 contents=parts["html_body"],
38 build_date=datetime.now().strftime('%B %d, %Y'), 36 build_date=datetime.now().strftime("%B %d, %Y"),
39 source_link=filename)) 37 source_link=filename))
40 38
41 39
42def get_output_name(base_dir, output_dir, filename): 40def get_output_name(base_dir, output_dir, filename):
43 base_depth = len(base_dir.split(path.sep)) 41 base_depth = len(base_dir.split(os.path.sep)) - 1
44 out_name = filename.split(path.sep)[base_depth:] 42 out_name = filename.split(os.path.sep)[base_depth:]
45 new_path = path.join(output_dir, *out_name) 43 new_path = os.path.join(output_dir, *out_name)
46 44
47 if new_path.endswith('.rst'): 45 if new_path.endswith(".rst"):
48 new_path = new_path[:-len('.rst')] + '.html' 46 new_path = new_path[:-len(".rst")] + ".html"
49 47
50 return new_path 48 return new_path
51 49
@@ -53,13 +51,16 @@ def get_output_name(base_dir, output_dir, filename):
53def build_all(base_dir, output_dir): 51def build_all(base_dir, output_dir):
54 for root, dirs, files in os.walk(base_dir): 52 for root, dirs, files in os.walk(base_dir):
55 for filename in files: 53 for filename in files:
56 if ('blog.cfg' in files or 54 if ("blog.cfg" in files or
57 not filename.endswith('.rst')): 55 not filename.endswith(".rst")):
58 continue 56 continue
59 57
60 old_path = path.join(root, filename) 58 old_path = os.path.join(root, filename)
61 new_path = get_output_name(base_dir, output_dir, old_path) 59 new_path = get_output_name(base_dir, output_dir, old_path)
62 60
63 print "BUILDING: ", old_path 61 if not os.path.exists(os.path.dirname(new_path)):
62 os.makedirs(os.path.dirname(new_path))
63
64 print("BUILDING: ", old_path, " to ", new_path)
64 65
65 build_standard_page(old_path, new_path) 66 build_standard_page(old_path, new_path)