-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwriters.py
58 lines (54 loc) · 2.16 KB
/
writers.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 shutil, errno
from jinja2 import Template
from jinja2 import Environment, FileSystemLoader
def staticwriter(src, dst):
try:
shutil.copytree(src, dst)
except OSError as exc: # python >2.5
if exc.errno == errno.ENOTDIR:
shutil.copy(src, dst)
else: raise
def defaultwriter(comiclist, theme_path, output_path, settings):
template_strip_abspath = os.path.abspath(os.path.expanduser(os.path.join(theme_path,'strip.html')))
template_author_abspath = os.path.abspath(os.path.expanduser(os.path.join(theme_path,'author.html')))
template_archives_abspath = os.path.abspath(os.path.expanduser(os.path.join(theme_path,'archives.html')))
jinja_env = Environment(loader=FileSystemLoader(theme_path),
trim_blocks=True)
#print comic_map
#format of comic strip: {number, timestamp, extrainfo, title, author, alttext}
#Write Comics
laststrip = comiclist[-1]
lastnumber = int(laststrip[0])
for comicstrip in comiclist:
comicnumber = int(comicstrip[0])
timestamp = comicstrip[1]
imagepath = comicstrip[2]
title = comicstrip[3]
author = comicstrip[4]
alternate = comicstrip[5]
description = comicstrip[6]
comicfile = jinja_env.get_template('comicstrip.html').render(
settings = settings,
number = comicnumber,
comictitle = title,
limit = lastnumber,
alttext = alternate,
imgpath = imagepath,
)
strip_dir = os.path.join(output_path,'%d' % comicnumber)
os.makedirs(strip_dir)
print strip_dir
comic_strip_path = os.path.join(strip_dir,'index.html')
file_writer = open(comic_strip_path,'w')
file_writer.write(comicfile)
file_writer.close()
if comicnumber is lastnumber:
comic_strip_path = os.path.join(output_path,'index.html')
file_writer = open(comic_strip_path,'w')
file_writer.write(comicfile)
file_writer.close()
#write index
#write authors page
#write archives page
pass