<s> """<STR_LIT>""" <EOL> import os <EOL> import json <EOL> import tempfile <EOL> import contextlib <EOL> import borg <EOL> logger = borg . get_logger ( __name__ ) <EOL> def parse_clasp_json_output ( stdout ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> output = json . loads ( stdout ) <EOL> except ValueError : <EOL> return None <EOL> if output [ "<STR_LIT>" ] == "<STR_LIT>" : <EOL> return None <EOL> else : <EOL> return output [ "<STR_LIT>" ] <EOL> class ClaspSolverFactory ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , root , command ) : <EOL> self . _root = root <EOL> self . _command = command <EOL> def __call__ ( self , task , stm_queue = None , solver_id = None ) : <EOL> return borg . solver_io . RunningSolver ( <EOL> parse_clasp_json_output , <EOL> self . _command + [ "<STR_LIT>" ] , <EOL> self . _root , <EOL> task . path , <EOL> stm_queue = stm_queue , <EOL> solver_id = solver_id , <EOL> ) <EOL> def with_args ( self , args ) : <EOL> """<STR_LIT>""" <EOL> return ClaspSolverFactory ( self . _root , self . _command + list ( args ) ) <EOL> def parse_clasp_human_output ( stdout ) : <EOL> for line in stdout . splitlines ( ) : <EOL> if line in [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] : <EOL> return line <EOL> return None <EOL> class ClaspfolioSolverFactory ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , root , command , cwd ) : <EOL> self . _root = root <EOL> self . _command = command <EOL> self . _cwd = cwd <EOL> def __call__ ( self , task , stm_queue = None , solver_id = None ) : <EOL> return borg . solver_io . RunningSolver ( <EOL> parse_clasp_human_output , <EOL> self . _command + [ "<STR_LIT>" ] , <EOL> self . _root , <EOL> task . path , <EOL> stm_queue = stm_queue , <EOL> solver_id = solver_id , <EOL> cwd = self . _cwd . format ( root = self . _root ) , <EOL> ) <EOL> def parse_yuliya_output ( stdout ) : <EOL> for line in stdout . splitlines ( ) : <EOL> stripped = line . strip ( ) <EOL> if stripped in [ "<STR_LIT>" , "<STR_LIT>" ] : <EOL> return stripped <EOL> return None <EOL> class YuliyaSolverFactory ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , root , command ) : <EOL> self . _root = root <EOL> self . _command = command <EOL> def __call__ ( self , task , stm_queue = None , solver_id = None ) : <EOL> return borg . solver_io . RunningSolver ( <EOL> parse_yuliya_output , <EOL> self . _command , <EOL> self . _root , <EOL> task . path , <EOL> stm_queue = stm_queue , <EOL> solver_id = solver_id , <EOL> ) <EOL> class LP2SAT_SolverFactory ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , root , sat_factory , domain ) : <EOL> self . _root = root <EOL> self . _sat_factory = sat_factory <EOL> self . _domain = domain <EOL> def __call__ ( self , task , stm_queue = None , solver_id = None ) : <EOL> try : <EOL> cnf_path = task . support_paths . get ( "<STR_LIT>" ) <EOL> if cnf_path is None : <EOL> ( fd , cnf_path ) = tempfile . mkstemp ( suffix = "<STR_LIT>" ) <EOL> task . support_paths [ "<STR_LIT>" ] = cnf_path <EOL> with contextlib . closing ( os . fdopen ( fd ) ) as cnf_file : <EOL> with open ( task . path , "<STR_LIT:rb>" ) as asp_file : <EOL> borg . domains . asp . run_lp2sat ( self . _domain . binaries_path , asp_file , cnf_file ) <EOL> except borg . domains . asp . LP2SAT_FailedException : <EOL> return borg . solver_io . EmptySolver ( None ) <EOL> else : <EOL> with borg . get_domain ( "<STR_LIT>" ) . task_from_path ( cnf_path ) as sat_task : <EOL> return self . _sat_factory ( sat_task ) </s>
