-
Notifications
You must be signed in to change notification settings - Fork 1
/
inferscrape
executable file
·54 lines (43 loc) · 1.64 KB
/
inferscrape
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
#!/usr/bin/env python
import os, sys, shutil
from optparse import OptionParser
from string import Template
DATA_PATH = os.path.join(os.path.dirname(__file__), "data")
def scrape(spewfile, verbose):
with open(spewfile, "r") as f:
spew = []
code = []
in_code = False
for line in f:
if line.startswith("[infer]"):
spew.append(line.strip())
elif line.strip() == "<<END_DECOMPILE":
in_code = True
elif line.strip() == "END_DECOMPILE":
in_code = False
elif in_code:
code.append(line.rstrip('\n'))
if not code:
raise Exception("bad spew: couldn't find decompiled code")
if in_code:
raise Exception("bad spew: premature end of decompiled code")
with open(os.path.join(DATA_PATH, "code.html")) as tfile:
template = Template(tfile.read())
with open(spewfile + ".html", "w") as outf:
subst = { 'title': spewfile,
'code': '\n'.join(code),
'spew': '\\n'.join(spew),
'data_path': DATA_PATH }
outf.write(template.safe_substitute(subst))
def main():
op = OptionParser(usage="%prog [-v] spewfile ...")
op.add_option("-v", "--verbose", dest="verbose", action="store_true",
help="display verbose information during scraping")
(options, args) = op.parse_args()
if not args:
op.print_help()
exit(1)
for spewfile in args:
scrape(spewfile, options.verbose)
if __name__ == "__main__":
main()