-
Notifications
You must be signed in to change notification settings - Fork 0
/
posters.py
64 lines (46 loc) · 1.56 KB
/
posters.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
58
59
60
61
62
63
64
import os, sys, cgi, glob
import jinja2 as jinja
from sh import cp
from sh import mkdir
from sh import convert
# n.b. newer sh will support this directly when released
class pushd(object):
def __init__(self, path):
self.path = path
def __enter__(self):
self.cwd = os.getcwd()
os.chdir(self.path)
def __exit__(self, exception_type, exception_val, trace):
os.chdir(self.cwd)
import logger
CONTENT_DIR = os.path.join('content', 'posters')
LOCAL_CONTENT_DIR = os.path.join('docs', CONTENT_DIR)
LOCAL_SPOTLIGHT_DIR = os.path.join('docs', CONTENT_DIR, '__spotlight')
class Poster ():
def __init__ (self, key):
self.key = key
cp(os.path.join('posters', key+'.pdf'), LOCAL_CONTENT_DIR)
with pushd(LOCAL_CONTENT_DIR):
convert('-resize', '320', key+'.pdf', key+'-320px.jpg')
# FIXME
self.venue = key
self.pdf_path = os.path.join(CONTENT_DIR, key+'.pdf')
self.spotlight_img_path = os.path.join(CONTENT_DIR, key+'-320px.jpg')
class Posters ():
def __init__ (self, jinja_env):
self.posters = {}
self.poster_spot_tmpl = jinja_env.get_template('posters_spotlight.html')
def addPoster (self, poster):
self.posters[poster.key] = poster
def generatePosterSidebarHTML (self, key):
try:
return self.poster_spot_tmpl.render(poster=self.posters[key])
except KeyError:
logger.critical('Poster for key {} not found'.format(key))
def init (jinja_env):
mkdir('-p', LOCAL_CONTENT_DIR)
mkdir('-p', LOCAL_SPOTLIGHT_DIR)
posters = Posters(jinja_env)
for poster in glob.glob('posters/*.pdf'):
posters.addPoster(Poster(poster[8:-4]))
return posters