<s> import os <EOL> import re <EOL> import subprocess <EOL> import functools <EOL> import time <EOL> import sublime <EOL> import sublime_plugin <EOL> class LegacyJasmineSwitchCommand ( sublime_plugin . TextCommand ) : <EOL> def window ( self ) : <EOL> return self . view . window ( ) <EOL> class BaseFile ( object ) : <EOL> def __init__ ( self , file_name ) : self . folder_name , self . file_name = os . path . split ( file_name ) <EOL> def possible_alternate_files ( self ) : return [ ] <EOL> class JavascriptFile ( BaseFile ) : <EOL> def possible_alternate_files ( self ) : return [ self . file_name . replace ( "<STR_LIT>" , "<STR_LIT>" ) , self . file_name . replace ( "<STR_LIT>" , "<STR_LIT>" ) ] <EOL> class JasmineFile ( BaseFile ) : <EOL> def possible_alternate_files ( self ) : return [ self . file_name . replace ( "<STR_LIT>" , "<STR_LIT>" ) . replace ( "<STR_LIT>" , "<STR_LIT>" ) ] <EOL> def current_file ( self ) : <EOL> file_name = self . view . file_name ( ) <EOL> if re . search ( '<STR_LIT>' , file_name ) : <EOL> return LegacyJasmineSwitchCommand . JasmineFile ( file_name ) <EOL> elif re . search ( '<STR_LIT>' , file_name ) : <EOL> return LegacyJasmineSwitchCommand . JavascriptFile ( file_name ) <EOL> else : <EOL> return LegacyJasmineSwitchCommand . BaseFile ( file_name ) <EOL> def run ( self , args ) : <EOL> possible_alternates = self . current_file ( ) . possible_alternate_files ( ) <EOL> alternates = self . project_files ( lambda file : file in possible_alternates ) <EOL> if alternates : <EOL> self . window ( ) . open_file ( alternates . pop ( ) ) <EOL> else : <EOL> sublime . error_message ( "<STR_LIT>" + str ( possible_alternates ) ) <EOL> def walk ( self , directory , ignored_directories = [ ] ) : <EOL> ignored_directories = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> for dir , dirnames , files in os . walk ( directory ) : <EOL> dirnames [ : ] = [ dirname for dirname in dirnames if dirname not in ignored_directories ] <EOL> yield dir , dirnames , files <EOL> def project_files ( self , file_matcher ) : <EOL> directories = self . window ( ) . folders ( ) <EOL> return [ os . path . join ( dirname , file ) for directory in directories for dirname , _ , files in self . walk ( directory ) for file in filter ( file_matcher , files ) ] </s>
