<s> import sys <EOL> import os <EOL> def run_command ( cmd , verbose = False ) : <EOL> if verbose : <EOL> print cmd <EOL> result = os . system ( cmd ) <EOL> if result != <NUM_LIT:0> : <EOL> raise Exception ( '<STR_LIT>' % ( cmd , result ) ) <EOL> def internally_compress ( filename , verbose = False ) : <EOL> wrk_file = filename . rsplit ( '<STR_LIT:.>' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] + '<STR_LIT>' <EOL> run_command ( <EOL> '<STR_LIT>' % ( <EOL> filename , <EOL> wrk_file , <EOL> '<STR_LIT>' if verbose else '<STR_LIT>' ) , <EOL> verbose = verbose ) <EOL> os . unlink ( filename ) <EOL> os . rename ( wrk_file , filename ) <EOL> def build_pyramid ( filename , verbose = False ) : <EOL> if '<STR_LIT>' in filename : <EOL> resample_alg = '<STR_LIT>' <EOL> else : <EOL> resample_alg = '<STR_LIT>' <EOL> run_command ( <EOL> '<STR_LIT>' % ( <EOL> '<STR_LIT>' if verbose else '<STR_LIT>' , <EOL> resample_alg , <EOL> filename ) , <EOL> verbose = verbose ) <EOL> def split ( root_scene , filename , verbose = False ) : <EOL> tgt_dir = root_scene <EOL> assert not os . path . exists ( tgt_dir ) <EOL> os . mkdir ( tgt_dir ) <EOL> if open ( filename ) . read ( <NUM_LIT:2> ) == '<STR_LIT>' : <EOL> compress_flag = '<STR_LIT>' <EOL> else : <EOL> compress_flag = '<STR_LIT>' <EOL> run_command ( <EOL> '<STR_LIT>' % ( <EOL> compress_flag , <EOL> '<STR_LIT:v>' if verbose else '<STR_LIT>' , <EOL> filename , tgt_dir ) , <EOL> verbose = verbose ) <EOL> for filename in os . listdir ( tgt_dir ) : <EOL> if filename . endswith ( '<STR_LIT>' ) : <EOL> internally_compress ( os . path . join ( tgt_dir , filename ) , <EOL> verbose = verbose ) <EOL> build_pyramid ( os . path . join ( tgt_dir , filename ) , <EOL> verbose = verbose ) <EOL> return tgt_dir <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> if len ( sys . argv ) < <NUM_LIT:3> : <EOL> print '<STR_LIT>' <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> print split ( sys . argv [ <NUM_LIT:1> ] , sys . argv [ <NUM_LIT:2> ] , verbose = True ) </s>
