<s> import glob <EOL> import os <EOL> import plistlib <EOL> from pprint import pprint <EOL> from firehose . model import Message , Function , Point , Range , File , Location , Issue , Trace , State , Notes <EOL> def parse_scandir ( resultdir ) : <EOL> """<STR_LIT>""" <EOL> for filename in glob . glob ( os . path . join ( resultdir , '<STR_LIT>' ) ) : <EOL> yield parse_plist ( filename ) <EOL> def parse_plist ( pathOrFile ) : <EOL> """<STR_LIT>""" <EOL> plist = plistlib . readPlist ( pathOrFile ) <EOL> if <NUM_LIT:0> : <EOL> pprint ( plist ) <EOL> files = plist [ '<STR_LIT>' ] <EOL> for diagnostic in plist [ '<STR_LIT>' ] : <EOL> if <NUM_LIT:0> : <EOL> pprint ( diagnostic ) <EOL> cwe = None <EOL> message = Message ( text = diagnostic [ '<STR_LIT:description>' ] ) <EOL> loc = diagnostic [ '<STR_LIT:location>' ] <EOL> location = Location ( file = File ( givenpath = files [ loc . file ] , <EOL> abspath = None ) , <EOL> function = None , <EOL> point = Point ( int ( loc . line ) , <EOL> int ( loc . col ) ) ) <EOL> notes = None <EOL> trace = make_trace ( files , diagnostic [ '<STR_LIT:path>' ] ) <EOL> issue = Issue ( cwe , <EOL> None , <EOL> location , message , notes , trace ) <EOL> yield issue <EOL> def make_point_from_plist_point ( loc ) : <EOL> return Point ( int ( loc . line ) , <EOL> int ( loc . col ) ) <EOL> def make_location_from_point ( files , loc ) : <EOL> location = Location ( file = File ( givenpath = files [ loc . file ] , <EOL> abspath = None ) , <EOL> function = Function ( '<STR_LIT>' ) , <EOL> point = make_point_from_plist_point ( loc ) ) <EOL> return location <EOL> def make_location_from_range ( files , range_ ) : <EOL> assert len ( range_ ) == <NUM_LIT:2> <EOL> start = range_ [ <NUM_LIT:0> ] <EOL> end = range_ [ <NUM_LIT:1> ] <EOL> assert start [ '<STR_LIT:file>' ] == end [ '<STR_LIT:file>' ] <EOL> if start == end : <EOL> point = make_point_from_plist_point ( start ) <EOL> range_ = None <EOL> else : <EOL> point = None <EOL> range_ = Range ( start = make_point_from_plist_point ( start ) , <EOL> end = make_point_from_plist_point ( end ) ) <EOL> location = Location ( file = File ( givenpath = files [ start [ '<STR_LIT:file>' ] ] , <EOL> abspath = None ) , <EOL> function = Function ( '<STR_LIT>' ) , <EOL> point = point , <EOL> range_ = range_ ) <EOL> return location <EOL> def make_trace ( files , path ) : <EOL> """<STR_LIT>""" <EOL> trace = Trace ( [ ] ) <EOL> lastlocation = None <EOL> for node in path : <EOL> if <NUM_LIT:0> : <EOL> pprint ( node ) <EOL> kind = node [ '<STR_LIT>' ] <EOL> if kind == '<STR_LIT>' : <EOL> loc = node [ '<STR_LIT:location>' ] <EOL> location = make_location_from_point ( files , loc ) <EOL> notes = Notes ( node [ '<STR_LIT:message>' ] ) <EOL> trace . add_state ( State ( location , notes ) ) <EOL> lastlocation = location <EOL> elif kind == '<STR_LIT>' : <EOL> edges = node [ '<STR_LIT>' ] <EOL> for edge in edges : <EOL> edge_start = edge . start <EOL> edge_end = edge . end <EOL> startloc = make_location_from_range ( files , edge_start ) <EOL> endloc = make_location_from_range ( files , edge_end ) <EOL> if startloc != lastlocation : <EOL> trace . add_state ( State ( startloc , None ) ) <EOL> trace . add_state ( State ( endloc , None ) ) <EOL> lastlocation = endloc <EOL> else : <EOL> raise ValueError ( '<STR_LIT>' % kind ) <EOL> return trace </s>
