MCPcopy Index your code
hub / github.com/NVlabs/SPADE / HTML

Class HTML

util/html.py:12–61  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10
11
12class HTML:
13 def __init__(self, web_dir, title, refresh=0):
14 if web_dir.endswith('.html'):
15 web_dir, html_name = os.path.split(web_dir)
16 else:
17 web_dir, html_name = web_dir, 'index.html'
18 self.title = title
19 self.web_dir = web_dir
20 self.html_name = html_name
21 self.img_dir = os.path.join(self.web_dir, 'images')
22 if len(self.web_dir) > 0 and not os.path.exists(self.web_dir):
23 os.makedirs(self.web_dir)
24 if len(self.web_dir) > 0 and not os.path.exists(self.img_dir):
25 os.makedirs(self.img_dir)
26
27 self.doc = dominate.document(title=title)
28 with self.doc:
29 h1(datetime.datetime.now().strftime("%I:%M%p on %B %d, %Y"))
30 if refresh > 0:
31 with self.doc.head:
32 meta(http_equiv="refresh", content=str(refresh))
33
34 def get_image_dir(self):
35 return self.img_dir
36
37 def add_header(self, str):
38 with self.doc:
39 h3(str)
40
41 def add_table(self, border=1):
42 self.t = table(border=border, style="table-layout: fixed;")
43 self.doc.add(self.t)
44
45 def add_images(self, ims, txts, links, width=512):
46 self.add_table()
47 with self.t:
48 with tr():
49 for im, txt, link in zip(ims, txts, links):
50 with td(style="word-wrap: break-word;", halign="center", valign="top"):
51 with p():
52 with a(href=os.path.join('images', link)):
53 img(style="width:%dpx" % (width), src=os.path.join('images', im))
54 br()
55 p(txt.encode('utf-8'))
56
57 def save(self):
58 html_file = os.path.join(self.web_dir, self.html_name)
59 f = open(html_file, 'wt')
60 f.write(self.doc.render())
61 f.close()
62
63
64if __name__ == '__main__':

Callers 1

html.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected