PageMaker.py
Go to the documentation of this file.
1 class PageMaker():
2  import os
3  import time
4  import common_tools as tools
5 
6  def __init__(self, name, output_dir, page_base_url, base_html=False, verbose=False):
7  if base_html:
8  self.content = open(base_html,"r").read()
9  else:
10  self.content = open("%s/core/view/template.html"%self.os.environ["NOVAANAVALID_DIR"],"r").read()
11  self.output_dir = output_dir
12  self.page_base_url = page_base_url
13  self.verbose = verbose
14  self.name = name
15  # Run standard methods
16 
17 
18  def addFooter(self):
19  t_string = self.time.strftime("%Y-%m-%d %H:%M:%S (%Z)", self.time.localtime())
20  footer = \
21  """
22  <div id="footer">
23  <div class="container-fluid">
24  <p class="muted credit">Page autogenerated at <font color="#0066CC">%s</font> by Validation's robots.</p>
25  </div>
26  </div>
27  """%t_string
28  self.addContent("<!--FOOTER_HOOK-->",footer)
29 
30  def setNavBarActive(self):
31  in_nav_bar = False
32  in_dropdown = False
33  for line in self.content.split("\n"):
34  if "nav navbar-nav" in line: in_nav_bar = True
35  if 'class="dropdown-menu"' in line: in_dropdown = line
36  if in_dropdown and '</ul>' in line: in_dropdown = False
37  if not in_nav_bar: continue
38  if self.name in line:
39  # This simplistic method can get confused if we're writing in subfolders
40  # and haven't specified this in self.name and instead use self.output_dir.
41  # Really this shouldn't happen, but I'll hack it here for now.
42  index_to_use = -1
43  if self.output_dir[-1] == "/": index_to_use = -2
44  if ("/" in self.output_dir) and (self.output_dir.split("/")[index_to_use] not in line):
45  continue
46  if in_dropdown:
47  new_line = in_dropdown.replace("<li ", '<li class="active" ')
48  self.content = self.content.replace(in_dropdown,new_line)
49  else:
50  new_line = line.replace("<li>",'<li class="active">')
51  self.content = self.content.replace(line,new_line)
52  break
53 
54  def addContent(self,pattern,replacement,destructive=False):
55  if (not destructive) and (pattern not in replacement): replacement = replacement+"\n"+pattern
56  self.content = self.content.replace(pattern,replacement)
57 
58  def write(self):
59  if self.verbose: print "PM : Writing page: %s%s"%(self.output_dir,self.name)
60  self.tools.mkdir(self.output_dir)
61  self.addFooter()
62  self.setNavBarActive()
63  html_file = open("%s/%s"%(self.output_dir,self.name),"wb")
64  html_file.write(self.content)
65  html_file.close()
def write(self)
Definition: PageMaker.py:58
def addFooter(self)
Definition: PageMaker.py:18
def setNavBarActive(self)
Definition: PageMaker.py:30
def __init__(self, name, output_dir, page_base_url, base_html=False, verbose=False)
Definition: PageMaker.py:6
procfile open("FD_BRL_v0.txt")
def addContent(self, pattern, replacement, destructive=False)
Definition: PageMaker.py:54