1
1
import re
2
+ import os
3
+ import shutil
2
4
3
5
class HTMLVisualizer (object ):
4
6
5
- def __init__ (self , src_lines , vis_lines ):
7
+ def __init__ (self , src_lines , vis_lines , keywords_file , script_dir ):
6
8
self .src_lines = src_lines
7
9
self .vis_lines = vis_lines
10
+ self .keywords_file = keywords_file
11
+ self .layout_dir = "%s/layout" % script_dir
8
12
self .keywords = self .getKeywords ()
9
13
14
+ def copyLayout (self , layout_dir , destination ):
15
+ # copy css
16
+ #shutil.copyfile("%s/vis.css" % layout_dir, "%s/vis.css" % destination)
17
+ #shutil.copyfile("%s/vis.js" % layout_dir, "%s/js.css" % destination)
18
+ #shutil.copyfile("%s/jquery-1.9.1.js" % layout_dir, "%s/jquery-1.9.1.js" % destination)
19
+ if os .path .exists ("%s/layout" % destination ):
20
+ shutil .rmtree ("%s/layout" % destination )
21
+
22
+ shutil .copytree (layout_dir , "%s/layout" % destination )
23
+
10
24
def getKeywords (self ):
11
25
content = ""
12
- with open ('keywords' , 'r' ) as file :
26
+ with open (self . keywords_file , 'r' ) as file :
13
27
content = file .read ()
14
28
15
29
keywords = {}
@@ -26,10 +40,16 @@ def getKeywords(self):
26
40
27
41
return keywords
28
42
29
- def parseKeywordDB (self ):
43
+ def parseKeywordDB (self , destination ):
30
44
content = ""
31
45
self .keyworddb = {}
32
- with open ('examples/keyworddb' , 'r' ) as file :
46
+
47
+ # keyworddb exists?
48
+ if not os .path .exists ('%s/keyworddb' % destination ):
49
+ open ('%s/keyworddb' % destination , 'a' ).close ()
50
+ return
51
+
52
+ with open ('%s/keyworddb' % destination , 'r' ) as file :
33
53
content = file .read ()
34
54
35
55
for line in content .split ("\n " ):
@@ -74,21 +94,22 @@ def needinfoKeyword(self, line, keyword, value):
74
94
line = line .replace (keyword , "<span class='needinfo'>%s</span>" % keyword )
75
95
return line + "<span class='needinfo_text'><b>NEEDINFO:</b> %s</span>" % value
76
96
77
- def printPage (self , file ):
97
+ def printPage (self , file , destination ):
78
98
with open (file , 'w' ) as file :
79
99
file .write ("<!DOCTYPE html PUBLIC \" -//W3C//DTD XHTML 1.0 Strict//EN\" \" http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\" >\n " )
80
100
file .write ("<html>\n " )
81
101
file .write ("<head>\n " )
82
- file .write ("<link rel=\" stylesheet\" type=\" text/css\" href=\" ../ layout/vis.css\" />\n " )
83
- file .write ("<script type=\" text/javascript\" src=\" ../ layout/jquery-1.9.1.js\" ></script>\n " )
84
- file .write ("<script type=\" text/javascript\" src=\" ../ layout/vis.js\" ></script>\n " )
102
+ file .write ("<link rel=\" stylesheet\" type=\" text/css\" href=\" layout/vis.css\" />\n " )
103
+ file .write ("<script type=\" text/javascript\" src=\" layout/jquery-1.9.1.js\" ></script>\n " )
104
+ file .write ("<script type=\" text/javascript\" src=\" layout/vis.js\" ></script>\n " )
85
105
file .write ("<script type=\" text/javascript\" >\n <!--\n " )
86
106
file .write ("$(document).ready(function() { $('span.fold_off').hide(); })\n " )
87
107
file .write ("// -->\n </script>\n " )
88
108
file .write ("</head>\n " )
89
109
file .write ("<body>\n " )
90
110
91
- self .parseKeywordDB ()
111
+ self .copyLayout (self .layout_dir , destination )
112
+ self .parseKeywordDB (destination )
92
113
93
114
count = len (self .src_lines )
94
115
fold_id = 1
0 commit comments