Hi all, wrote a tiny program last night to make sense of a lot of the new code i'm going through. Complements my work style and i'd like to share it. This utility takes the DOM of one or more files and produces a report on the "structure" of the lzx. Makes reports on all nodes with an id, name, or event attribute -- which pretty well covers units of execution. Note it prints all of those attributes for each node, so... x:: this is an id :x: this is a name ::x is an event ...in the simple case of having only one of those attributes. By listing just these nodes and doing indentation, it gives a quick way to scan lzx assets. Written in python (which mac has built-in, or from python.org on windows). Any feature ideas welcome.. one day soon it'll run as a laszlo application.. Enjoy~ (script attached) |
import sys, re from xml.dom.minidom import parseString """ parselzx.py [EMAIL PROTECTED]
Parses the structure of .lzx files into a report of elements
with either name, id, or event attributes.
Usage: parselzx fname.lzx
"""
class parseLZX:
def __init__(self, fname):
self.indent = 4
self.output = []
root = parseString(open(fname).read()).documentElement
self.walk(root)
def walk(self, root):
for node in [x for x in root.childNodes if x.nodeType == x.ELEMENT_NODE]:
id = node.getAttribute('id')
name = node.getAttribute('name')
event = node.getAttribute('event')
if not (event or id or name):
continue
names = "%s:%s:%s"%(id, name, event)
self.output.append("%s%s %s"%(self.indent*" ", node.tagName.upper(), names))
self.indent += 4
self.walk(node)
self.indent -= 4
print "parselzx.py, lzx structure listing"
if len(sys.argv) < 2:
print "Usage: parselzx filename1.lzx filename2.lzx ...\n"
sys.exit(1)
print "[Legend]"
print " TAGNAME id:name:event\n"
for name in sys.argv[1:]:
print "FILE: %s %s"%("-"*(60-len(name)), name)
print '\n'.join(parseLZX(name).output)
print "\n"
USAGE: python parselzx.py file1 file2 ... LEGEND: TAGNAME id:name:event SAMPLE OUTPUT: FILE: ------------------------------------------------- ./lzpix.lzx ATTRIBUTE :anm_multipler: ATTRIBUTE :isopen: VIEW :interior: VIEW :details_bkgnd: VIEW :tools: TEXT gResultsCountLabel:: VIEW :beveled-divider: VIEW photoscontainer:photos: ATTRIBUTE :detailphoto: PIVOTLAYOUT :lyt: METHOD :myreset: ANIMATORGROUP :transitiontolinear_anm: ANIMATORGROUP :grp: ANIMATOR :yspacing: METHOD ::onstop ANIMATORGROUP :transitiontogrid_anm: ANIMATOR :pageNext: ANIMATOR :pagePrev: ATTRIBUTE :initialDone: METHOD :displaytext: METHOD :transitionToDetails: METHOD :transitionToGrid: METHOD ::onstop METHOD :showPhotoDetails: DATAPOINTER :pagecounter_dp: ATTRIBUTE :doneDel: METHOD ::ondata METHOD :watchforlast: METHOD :initialReplicationDone: METHOD :buildResultsString: SELECTIONMANAGER :selman: METHOD :isMultiSelect: ATTRIBUTE :isRectangleSelecting: METHOD :selectInRectangle: PHOTO :ph: METHOD ::onplainclick ATTRIBUTE :selected: METHOD :startDrag: METHOD :stopDrag: ATTRIBUTE :isselected: METHOD :setSelected: METHOD :intersectsRectangle: VIEW :rubberband: ATTRIBUTE :_sx: ATTRIBUTE :_sy: ATTRIBUTE :updel: METHOD :start: METHOD :update: METHOD :stop: ATTRIBUTE :showhandcursor: METHOD ::onmousedown METHOD ::onmouseup VIEW :btm: DETAILSVIEW :details: VIEW :divider: MYBUTTON hdb:hideDetailsButton: METHOD :returnToGridView: VIEW :topview: ANIMATORGROUP :anm: METHOD ::onstop VIEW :large_cam: VIEW :little_cam: VIEW :logo: VIEW :bottom: ANIMATORGROUP agroup:anm: VIEW :links: FAVORITES :fav: SEARCH gSearch:srch: ATTRIBUTE :firsttime: METHOD :sendsearch: SPINNER :spnr: VIEW scrn:: CLIPBOARD gClipboard:: DRAGGEDPHOTOS gDragged:: METHOD :setOpen: |
