<s> import sublime <EOL> try : <EOL> from . sbtsettings import SBTSettings <EOL> from . errorreport import ErrorReport <EOL> from . errorreporter import ErrorReporter <EOL> from . util import maybe , OnePerWindow <EOL> except ( ValueError ) : <EOL> from sbtsettings import SBTSettings <EOL> from errorreport import ErrorReport <EOL> from errorreporter import ErrorReporter <EOL> from util import maybe , OnePerWindow <EOL> import os <EOL> import re <EOL> from glob import glob <EOL> class Project ( OnePerWindow ) : <EOL> def __init__ ( self , window ) : <EOL> self . window = window <EOL> self . settings = SBTSettings ( window ) <EOL> self . error_report = ErrorReport ( ) <EOL> self . error_reporter = ErrorReporter ( window , <EOL> self . error_report , <EOL> self . settings ) <EOL> def project_root ( self ) : <EOL> for folder in self . window . folders ( ) : <EOL> if self . _is_sbt_folder ( folder ) : <EOL> return folder <EOL> def is_sbt_project ( self ) : <EOL> return self . project_root ( ) is not None <EOL> def is_play_project ( self ) : <EOL> for root in maybe ( self . project_root ( ) ) : <EOL> if self . _play_build_files ( root ) : <EOL> return True <EOL> def sbt_command ( self ) : <EOL> if self . is_play_project ( ) : <EOL> return self . settings . play_command ( ) <EOL> else : <EOL> return self . settings . sbt_command ( ) <EOL> def setting ( self , name ) : <EOL> return self . settings . get ( name ) <EOL> def expand_filename ( self , filename ) : <EOL> if len ( os . path . dirname ( filename ) ) > <NUM_LIT:0> : <EOL> return filename <EOL> else : <EOL> return self . _find_in_project ( filename ) <EOL> def relative_path ( self , filename ) : <EOL> return os . path . relpath ( filename , self . project_root ( ) ) <EOL> def open_project_file ( self , filename , line ) : <EOL> full_path = os . path . join ( self . project_root ( ) , filename ) <EOL> self . window . open_file ( '<STR_LIT>' % ( full_path , line ) , <EOL> sublime . ENCODED_POSITION ) <EOL> def _is_sbt_folder ( self , folder ) : <EOL> if self . _sbt_build_files ( folder ) or self . _scala_build_files ( folder ) : <EOL> return True <EOL> def _sbt_build_files ( self , folder ) : <EOL> return glob ( os . path . join ( folder , '<STR_LIT>' ) ) <EOL> def _scala_build_files ( self , folder ) : <EOL> return glob ( os . path . join ( folder , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> def _play_build_files ( self , folder ) : <EOL> return list ( filter ( self . _is_play_build , self . _scala_build_files ( folder ) ) ) <EOL> def _is_play_build ( self , build_path ) : <EOL> try : <EOL> with open ( build_path , '<STR_LIT:r>' ) as build_file : <EOL> for line in build_file . readlines ( ) : <EOL> if re . search ( r'<STR_LIT>' , line ) : <EOL> return True <EOL> except : <EOL> return False <EOL> def _find_in_project ( self , filename ) : <EOL> for path , _ , files in os . walk ( self . project_root ( ) ) : <EOL> if filename in files : <EOL> return os . path . join ( path , filename ) </s>
