#NEWLINE# def modify_java_target( exercise , old = '1.6' , new = '1.7' ) : #NEWLINE# #INDENT# path = os . path . join ( exercise . path ( ) , 'nbproject' , 'project.properties' ) #NEWLINE# if ( not os . path . isfile ( path ) ) : #NEWLINE# #INDENT# raise WrongExerciseType ( 'java' ) #NEWLINE# #UNINDENT# lines = [ ] #NEWLINE# with open ( path ) as fp : #NEWLINE# #INDENT# lines = fp . readlines ( ) #NEWLINE# #UNINDENT# for ( ind , line ) in enumerate ( lines ) : #NEWLINE# #INDENT# if ( line . startswith ( 'javac' ) and line . endswith ( ( ( '=' + old ) + '\n' ) ) ) : #NEWLINE# #INDENT# lines [ ind ] = line . replace ( old , new ) #NEWLINE# #UNINDENT# #UNINDENT# with open ( path , 'w' ) as fp : #NEWLINE# #INDENT# fp . write ( '' . join ( lines ) ) #NEWLINE# #UNINDENT# print ( 'Changed Java target from {} to {}' . format ( old , new ) )