<s> import os <EOL> import sys <EOL> from xml . etree import cElementTree as ElementTree <EOL> def run ( filename , account = None ) : <EOL> root = ElementTree . parse ( filename ) <EOL> node_id = <NUM_LIT:0> <EOL> lookup = { } <EOL> error_edges = [ ] <EOL> def should_include ( obj ) : <EOL> if account is None : <EOL> return True <EOL> else : <EOL> for an_account in obj . getiterator ( '<STR_LIT>' ) : <EOL> if an_account . get ( '<STR_LIT:id>' ) == account : <EOL> return True <EOL> return False <EOL> print '<STR_LIT>' <EOL> print '<STR_LIT>' <EOL> for process in root . getiterator ( '<STR_LIT>' ) . next ( ) . getiterator ( '<STR_LIT>' ) : <EOL> if not should_include ( process ) : <EOL> continue <EOL> process_id = process . get ( '<STR_LIT:id>' ) <EOL> error = None <EOL> for child in process . getiterator ( '<STR_LIT:value>' ) . next ( ) . getchildren ( ) : <EOL> if child . tag == '<STR_LIT>' : <EOL> process_label = child . get ( '<STR_LIT>' ) <EOL> if child . get ( '<STR_LIT>' ) == '<STR_LIT>' : <EOL> error = child . get ( '<STR_LIT:error>' ) <EOL> elif child . tag == '<STR_LIT>' : <EOL> process_label = child . get ( '<STR_LIT>' ) <EOL> if child . get ( '<STR_LIT>' ) == '<STR_LIT>' : <EOL> error = child . get ( '<STR_LIT:error>' ) <EOL> if child . tag == '<STR_LIT>' : <EOL> shape = '<STR_LIT>' <EOL> elif child . tag == '<STR_LIT>' and child . get ( '<STR_LIT>' ) == '<STR_LIT>' : <EOL> shape = '<STR_LIT>' <EOL> else : <EOL> shape = '<STR_LIT>' <EOL> print '<STR_LIT>' % ( node_id , process_label , shape ) <EOL> lookup [ process_id ] = node_id <EOL> node_id += <NUM_LIT:1> <EOL> if error is not None : <EOL> print '<STR_LIT>' % ( node_id , <EOL> error ) <EOL> error_edges . append ( ( node_id - <NUM_LIT:1> , node_id ) ) <EOL> node_id += <NUM_LIT:1> <EOL> for artifact in root . getiterator ( '<STR_LIT>' ) . next ( ) . getiterator ( '<STR_LIT>' ) : <EOL> if not should_include ( artifact ) : <EOL> continue <EOL> artifact_id = artifact . get ( '<STR_LIT:id>' ) <EOL> for child in artifact . getiterator ( '<STR_LIT:value>' ) . next ( ) . getchildren ( ) : <EOL> if child . tag == '<STR_LIT>' : <EOL> port_name = str ( child . get ( '<STR_LIT:name>' ) ) <EOL> spec = str ( child . get ( '<STR_LIT>' ) ) <EOL> if spec : <EOL> artifact_label = port_name + '<STR_LIT>' + spec [ spec . index ( '<STR_LIT::>' ) + <NUM_LIT:1> : spec . index ( '<STR_LIT:)>' ) ] + '<STR_LIT:]>' <EOL> else : <EOL> artifact_label = port_name <EOL> elif child . tag == '<STR_LIT>' : <EOL> artifact_label = str ( child . get ( '<STR_LIT:name>' ) ) + '<STR_LIT>' <EOL> comma = '<STR_LIT>' <EOL> for param in child . getiterator ( '<STR_LIT>' ) : <EOL> param_val = param . get ( '<STR_LIT>' ) <EOL> if len ( param_val ) > <NUM_LIT:32> : <EOL> if param . get ( '<STR_LIT:type>' ) == '<STR_LIT>' : <EOL> print >> sys . stderr , "<STR_LIT>" <EOL> dir_names = [ ] <EOL> dir_name = param_val <EOL> while os . path . split ( dir_name ) [ <NUM_LIT:1> ] : <EOL> ( dir_name , next_name ) = os . path . split ( dir_name ) <EOL> dir_names . append ( next_name ) <EOL> dir_names . append ( '<STR_LIT:/>' ) <EOL> if len ( dir_names ) <= <NUM_LIT:1> : <EOL> param_val = param_val <EOL> dir_names . reverse ( ) <EOL> if len ( dir_names [ - <NUM_LIT:1> ] ) > <NUM_LIT> : <EOL> i = <NUM_LIT:1> <EOL> j = <NUM_LIT:1> <EOL> arr = dir_names [ - <NUM_LIT:1> ] . split ( '<STR_LIT:_>' ) <EOL> while len ( '<STR_LIT:_>' . join ( arr [ : i ] + [ '<STR_LIT>' ] + arr [ - j : ] ) ) < <NUM_LIT> : <EOL> if i == j : <EOL> i += <NUM_LIT:1> <EOL> else : <EOL> j += <NUM_LIT:1> <EOL> dir_names [ - <NUM_LIT:1> ] = '<STR_LIT:_>' . join ( arr [ : i ] + [ '<STR_LIT>' ] + arr [ - j : ] ) <EOL> print >> sys . stderr , dir_names <EOL> i = <NUM_LIT:1> <EOL> while ( len ( os . path . join ( dir_names [ <NUM_LIT:0> ] , dir_names [ <NUM_LIT:1> ] , <EOL> '<STR_LIT>' , <EOL> * dir_names [ - i : ] ) ) < <NUM_LIT:32> and <EOL> i + <NUM_LIT:1> < len ( dir_names ) ) : <EOL> print >> sys . stderr , len ( os . path . join ( dir_names [ <NUM_LIT:0> ] , <EOL> dir_names [ <NUM_LIT:1> ] , <EOL> '<STR_LIT>' , <EOL> * dir_names [ - i : ] ) ) <EOL> i += <NUM_LIT:1> <EOL> print >> sys . stderr , i <EOL> param_val = os . path . join ( dir_names [ <NUM_LIT:0> ] , <EOL> dir_names [ <NUM_LIT:1> ] , '<STR_LIT>' , <EOL> * dir_names [ - i : ] ) <EOL> else : <EOL> param_val = param_val [ : <NUM_LIT> ] + '<STR_LIT>' + param_val [ - <NUM_LIT:8> : ] <EOL> artifact_label += comma + param_val <EOL> comma = '<STR_LIT:U+002CU+0020>' <EOL> artifact_label += '<STR_LIT:)>' <EOL> else : <EOL> print >> sys . stderr , "<STR_LIT>" , child . tag <EOL> artifact_label = artifact . get ( '<STR_LIT:id>' ) <EOL> print '<STR_LIT>' % ( node_id , artifact_label ) <EOL> lookup [ artifact_id ] = node_id <EOL> node_id += <NUM_LIT:1> <EOL> for used in root . getiterator ( '<STR_LIT>' ) . next ( ) . getiterator ( '<STR_LIT>' ) : <EOL> if not should_include ( used ) : <EOL> continue <EOL> print "<STR_LIT>" % ( lookup [ used . getiterator ( '<STR_LIT>' ) . next ( ) . get ( '<STR_LIT:id>' ) ] , <EOL> lookup [ used . getiterator ( '<STR_LIT>' ) . next ( ) . get ( '<STR_LIT:id>' ) ] ) <EOL> for wgb in root . getiterator ( '<STR_LIT>' ) . next ( ) . getiterator ( '<STR_LIT>' ) : <EOL> if not should_include ( wgb ) : <EOL> continue <EOL> print "<STR_LIT>" % ( lookup [ wgb . getiterator ( '<STR_LIT>' ) . next ( ) . get ( '<STR_LIT:id>' ) ] , <EOL> lookup [ wgb . getiterator ( '<STR_LIT>' ) . next ( ) . get ( '<STR_LIT:id>' ) ] ) <EOL> for wtb in root . getiterator ( '<STR_LIT>' ) . next ( ) . getiterator ( '<STR_LIT>' ) : <EOL> if not should_include ( wtb ) : <EOL> continue <EOL> print "<STR_LIT>" % ( lookup [ wtb . getiterator ( '<STR_LIT>' ) . next ( ) . get ( '<STR_LIT:id>' ) ] , <EOL> lookup [ wtb . getiterator ( '<STR_LIT>' ) . next ( ) . get ( '<STR_LIT:id>' ) ] ) <EOL> for error_edge in error_edges : <EOL> print "<STR_LIT>" % error_edge <EOL> print "<STR_LIT:}>" <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> if len ( sys . argv ) < <NUM_LIT:2> : <EOL> print "<STR_LIT>" % sys . argv [ <NUM_LIT:0> ] <EOL> sys . exit ( <NUM_LIT> ) <EOL> account = sys . argv [ <NUM_LIT:2> ] if len ( sys . argv ) > <NUM_LIT:2> else None <EOL> run ( sys . argv [ <NUM_LIT:1> ] , account ) </s>
