<s> import qisys . error <EOL> import qisys . sh <EOL> import qisys . parsers <EOL> import qilinguist . builder <EOL> from qilinguist . worktree import LinguistWorkTree , new_linguist_project <EOL> from qilinguist . pml_translator import new_pml_translator <EOL> def get_linguist_worktree ( args ) : <EOL> worktree = qisys . parsers . get_worktree ( args , raises = False ) <EOL> if worktree : <EOL> return LinguistWorkTree ( worktree ) <EOL> else : <EOL> return None <EOL> def get_linguist_projects ( args , default_all = False ) : <EOL> worktree = get_linguist_worktree ( args ) <EOL> project_args = args . projects <EOL> pml_paths = list ( ) <EOL> project_names = list ( ) <EOL> for arg in project_args : <EOL> if arg . endswith ( "<STR_LIT>" ) : <EOL> pml_paths . append ( qisys . sh . to_native_path ( arg ) ) <EOL> else : <EOL> if worktree : <EOL> project_names . append ( arg ) <EOL> else : <EOL> raise qisys . error . Error ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> if not worktree and not pml_paths : <EOL> raise qisys . error . Error ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> res = list ( ) <EOL> if worktree : <EOL> args . projects = project_names <EOL> parser = LinguistProjectParser ( worktree ) <EOL> try : <EOL> res . extend ( parser . parse_args ( args , default_all = default_all ) ) <EOL> except CouldNotGuessProjectName : <EOL> pass <EOL> res . extend ( get_pml_projects ( pml_paths ) ) <EOL> return res <EOL> def get_pml_projects ( pml_paths ) : <EOL> res = list ( ) <EOL> for pml_path in pml_paths : <EOL> res . append ( new_pml_translator ( pml_path ) ) <EOL> return res <EOL> def get_linguist_builder ( args , with_projects = True ) : <EOL> worktree = get_linguist_worktree ( args ) <EOL> builder = qilinguist . builder . QiLinguistBuilder ( ) <EOL> if with_projects : <EOL> projects = get_linguist_projects ( args ) <EOL> builder . projects = projects <EOL> return builder <EOL> class LinguistProjectParser ( qisys . parsers . AbstractProjectParser ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , linguist_worktree ) : <EOL> self . linguist_worktree = linguist_worktree <EOL> self . linguist_projects = linguist_worktree . linguist_projects <EOL> def all_projects ( self , args ) : <EOL> return self . linguist_projects <EOL> def parse_no_project ( self , args ) : <EOL> """<STR_LIT>""" <EOL> worktree = self . linguist_worktree . worktree <EOL> parser = qisys . parsers . WorkTreeProjectParser ( worktree ) <EOL> worktree_projects = parser . parse_no_project ( args ) <EOL> if not worktree_projects : <EOL> raise CouldNotGuessProjectName ( ) <EOL> worktree_project = worktree_projects [ <NUM_LIT:0> ] <EOL> linguist_project = new_linguist_project ( self . linguist_worktree , <EOL> worktree_project ) <EOL> if not linguist_project : <EOL> raise CouldNotGuessProjectName ( ) <EOL> return self . parse_one_project ( args , linguist_project . name ) <EOL> def parse_one_project ( self , args , project_arg ) : <EOL> """<STR_LIT>""" <EOL> project = self . linguist_worktree . get_linguist_project ( project_arg , <EOL> raises = True ) <EOL> return [ project ] <EOL> class CouldNotGuessProjectName ( qisys . error . Error ) : <EOL> def __str__ ( self ) : <EOL> return """<STR_LIT>""" </s>
