<s> import sys <EOL> import os <EOL> import re <EOL> from convert_to_vt import ConvertVTKToVT <EOL> def run ( in_dir , out_dir ) : <EOL> def collectFilenames ( dir ) : <EOL> fileNameParser = re . compile ( '<STR_LIT>' ) <EOL> result = [ ] <EOL> for file in os . listdir ( dir ) : <EOL> childDirOrFile = os . path . join ( dir , file ) <EOL> if os . path . isfile ( childDirOrFile ) : <EOL> if fileNameParser . match ( childDirOrFile ) : <EOL> result . append ( childDirOrFile ) <EOL> elif os . path . isdir ( childDirOrFile ) : <EOL> result += collectFilenames ( childDirOrFile ) <EOL> return result <EOL> all_files = collectFilenames ( in_dir ) <EOL> in_base = os . path . basename ( in_dir ) <EOL> for fname in all_files : <EOL> path_before = os . path . dirname ( fname ) <EOL> path_end = '<STR_LIT>' <EOL> while os . path . basename ( path_before ) != in_base : <EOL> if os . path . basename ( path_before ) != '<STR_LIT>' : <EOL> if path_end == '<STR_LIT>' : <EOL> path_end = os . path . basename ( path_before ) <EOL> else : <EOL> path_end = os . path . join ( os . path . basename ( path_before ) , <EOL> path_end ) <EOL> path_before = os . path . dirname ( path_before ) <EOL> out_dirname = os . path . join ( out_dir , path_end ) <EOL> to_make_dirs = [ ] <EOL> a_dirname = out_dirname <EOL> while not os . path . exists ( a_dirname ) : <EOL> to_make_dirs . append ( a_dirname ) <EOL> a_dirname = os . path . dirname ( a_dirname ) <EOL> for a_dirname in reversed ( to_make_dirs ) : <EOL> os . mkdir ( a_dirname ) <EOL> script_name = os . path . basename ( fname ) <EOL> vt_name = os . path . splitext ( script_name ) [ <NUM_LIT:0> ] + '<STR_LIT>' <EOL> out_py_name = os . path . join ( out_dirname , script_name ) <EOL> out_vt_name = os . path . join ( out_dirname , vt_name ) <EOL> converter = ConvertVTKToVT ( fname , out_py_name ) <EOL> converter . run ( ) <EOL> print >> sys . stderr , "<STR_LIT>" % ( out_py_name , <EOL> out_vt_name ) <EOL> os . system ( '<STR_LIT>' % ( out_py_name , out_vt_name ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> if len ( sys . argv ) < <NUM_LIT:3> : <EOL> print '<STR_LIT>' % sys . argv [ <NUM_LIT:0> ] <EOL> sys . exit ( - <NUM_LIT:1> ) <EOL> run ( * sys . argv [ <NUM_LIT:1> : ] ) </s>
