-
Notifications
You must be signed in to change notification settings - Fork 83
/
Copy pathAnnotation Export.py
executable file
·37 lines (31 loc) · 1.21 KB
/
Annotation Export.py
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
# vim: tabstop=4:softtabstop=4:shiftwidth=4:noexpandtab:
# Copyright: (c)2015 Chris Kuethe <[email protected]>
# License: Perl Artistic <http://dev.perl.org/licenses/artistic.html>
# Description: save document labels and comments to a file
import json
from datetime import datetime
doc = Document.getCurrentDocument()
symtab = dict()
nsegs = doc.getSegmentCount()
for segnum in range(nsegs):
doc.log('processing segment %d/%d' % (segnum+1,nsegs))
seg = doc.getSegment(segnum)
for label in seg.getLabelsList():
addr = doc.getAddressForName(label)
addr_comm = seg.getCommentAtAddress(addr)
addr_icom = seg.getInlineCommentAtAddress(addr)
generic_name = "sub_%x" % addr
if (label != generic_name) or (addr_comm is not None) or (addr_comm is not None):
doc.log(label)
symtab[addr] = {'seg': segnum, 'comm': addr_comm, 'icom': addr_icom, 'name': label}
t = datetime.strftime(datetime.now(), 'annotation-%Y%m%d%H%M%S.json')
outfile = doc.askFile('file to save?', t, t)
if outfile is not None:
try:
f = open(outfile, "a+")
f.write(json.dumps(symtab, sort_keys=True, indent=4))
f.close()
doc.log("saved to %s" % outfile)
except Exception as e:
doc.log("failed to save %s" % outfile)
doc.log(e)