Skip to content

Commit d9bd08f

Browse files
committed
copying layout files to destination, keyword file update
1 parent 2b00d09 commit d9bd08f

File tree

4 files changed

+45
-13
lines changed

4 files changed

+45
-13
lines changed

HTMLVisualizer.py

+30-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
11
import re
2+
import os
3+
import shutil
24

35
class HTMLVisualizer(object):
46

5-
def __init__(self, src_lines, vis_lines):
7+
def __init__(self, src_lines, vis_lines, keywords_file, script_dir):
68
self.src_lines = src_lines
79
self.vis_lines = vis_lines
10+
self.keywords_file = keywords_file
11+
self.layout_dir = "%s/layout" % script_dir
812
self.keywords = self.getKeywords()
913

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+
1024
def getKeywords(self):
1125
content = ""
12-
with open('keywords', 'r') as file:
26+
with open(self.keywords_file, 'r') as file:
1327
content = file.read()
1428

1529
keywords = {}
@@ -26,10 +40,16 @@ def getKeywords(self):
2640

2741
return keywords
2842

29-
def parseKeywordDB(self):
43+
def parseKeywordDB(self, destination):
3044
content = ""
3145
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:
3353
content = file.read()
3454

3555
for line in content.split("\n"):
@@ -74,21 +94,22 @@ def needinfoKeyword(self, line, keyword, value):
7494
line = line.replace(keyword, "<span class='needinfo'>%s</span>" % keyword)
7595
return line + "<span class='needinfo_text'><b>NEEDINFO:</b> %s</span>" % value
7696

77-
def printPage(self, file):
97+
def printPage(self, file, destination):
7898
with open(file, 'w') as file:
7999
file.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n")
80100
file.write("<html>\n")
81101
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")
85105
file.write("<script type=\"text/javascript\">\n<!--\n")
86106
file.write("$(document).ready(function() { $('span.fold_off').hide(); })\n")
87107
file.write("// -->\n</script>\n")
88108
file.write("</head>\n")
89109
file.write("<body>\n")
90110

91-
self.parseKeywordDB()
111+
self.copyLayout(self.layout_dir, destination)
112+
self.parseKeywordDB(destination)
92113

93114
count = len(self.src_lines)
94115
fold_id = 1

keywords

+2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ float
1919
unsigned
2020
signed
2121
const
22+
void
2223
switch
2324
case
2425
break
2526
continue
2627
return
28+
typedef

layout/vis.css

+3-1
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ span.double,
4040
span.float,
4141
span.signed,
4242
span.unsigned,
43+
span.void,
4344
span.char,
4445
span.const,
45-
span.return
46+
span.return,
47+
span.typedef
4648
{color: blue;}
4749

4850
span.include,

visualize.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
# [ ] - support for multiline comments on a single line (flowing div)
2121
# [ ] - make a call graph for every module (use existing tools)
2222
# [ ] - ignore comments (+color them)
23+
# [ ] - find a suitable dir for keyword file
24+
# [ ] - install css and js files into dest directory
2325

2426
import sys
2527
import os
@@ -116,8 +118,13 @@ def mkdir_p(path):
116118
code_lines = codeParser.getLines()
117119
debug("Source file parser")
118120

121+
dir_parts = os.path.realpath(__file__).split("/")
122+
del(dir_parts[-1])
123+
script_home = "/".join(dir_parts)
124+
keywords_file = script_home + "/keywords"
125+
119126
debug("Initializing html output...")
120-
htmlVis = HTMLVisualizer(code_lines, vis_lines)
127+
htmlVis = HTMLVisualizer(code_lines, vis_lines, keywords_file, script_home)
121128
debug("Html output generated")
122-
htmlVis.printPage(html_file)
123-
129+
htmlVis.printPage(html_file, destination)
130+
debug("Saved to: %s" % html_file)

0 commit comments

Comments
 (0)