<s> from __future__ import ( absolute_import , division , generators , nested_scopes , print_function , <EOL> unicode_literals , with_statement ) <EOL> from pants . base . exceptions import TaskError <EOL> from pants . task . console_task import ConsoleTask <EOL> class ListTargets ( ConsoleTask ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def register_options ( cls , register ) : <EOL> super ( ListTargets , cls ) . register_options ( register ) <EOL> register ( '<STR_LIT>' , type = bool , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> register ( '<STR_LIT>' , default = '<STR_LIT>' , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> register ( '<STR_LIT>' , type = bool , <EOL> help = '<STR_LIT>' ) <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( ListTargets , self ) . __init__ ( * args , ** kwargs ) <EOL> self . _provides = self . get_options ( ) . provides <EOL> self . _provides_columns = self . get_options ( ) . provides_columns <EOL> self . _documented = self . get_options ( ) . documented <EOL> def console_output ( self , targets ) : <EOL> if self . _provides : <EOL> def extract_artifact_id ( target ) : <EOL> provided_jar , _ = target . get_artifact_info ( ) <EOL> return '<STR_LIT>' . format ( provided_jar . org , provided_jar . name ) <EOL> extractors = dict ( <EOL> address = lambda target : target . address . spec , <EOL> artifact_id = extract_artifact_id , <EOL> repo_name = lambda target : target . provides . repo . name , <EOL> repo_url = lambda target : target . provides . repo . url , <EOL> push_db_basedir = lambda target : target . provides . repo . push_db_basedir , <EOL> ) <EOL> def print_provides ( column_extractors , target ) : <EOL> if target . is_exported : <EOL> return '<STR_LIT:U+0020>' . join ( extractor ( target ) for extractor in column_extractors ) <EOL> try : <EOL> column_extractors = [ extractors [ col ] for col in ( self . _provides_columns . split ( '<STR_LIT:U+002C>' ) ) ] <EOL> except KeyError : <EOL> raise TaskError ( '<STR_LIT>' <EOL> '<STR_LIT>' . format ( self . _provides_columns ) ) <EOL> print_fn = lambda target : print_provides ( column_extractors , target ) <EOL> elif self . _documented : <EOL> def print_documented ( target ) : <EOL> if target . description : <EOL> return '<STR_LIT>' . format ( target . address . spec , <EOL> '<STR_LIT>' . join ( target . description . strip ( ) . split ( '<STR_LIT:\n>' ) ) ) <EOL> print_fn = print_documented <EOL> else : <EOL> print_fn = lambda target : target . address . spec <EOL> visited = set ( ) <EOL> for target in self . _targets ( ) : <EOL> result = print_fn ( target ) <EOL> if result and result not in visited : <EOL> visited . add ( result ) <EOL> yield result <EOL> def _targets ( self ) : <EOL> if self . context . target_roots : <EOL> return self . context . target_roots <EOL> else : <EOL> return self . context . scan ( ) . targets ( predicate = lambda target : not target . is_synthetic ) </s>
