<s> """<STR_LIT>""" <EOL> from logging import getLogger <EOL> from mrjob . py2 import to_string <EOL> from . ids import _sort_by_recency <EOL> log = getLogger ( __name__ ) <EOL> def _cat_log ( fs , path ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> if not fs . exists ( path ) : <EOL> return <EOL> for line in fs . cat ( path ) : <EOL> yield to_string ( line ) <EOL> except IOError as e : <EOL> log . warning ( "<STR_LIT>" % ( path , e ) ) <EOL> def _ls_logs ( fs , log_dir_stream , matcher , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> def _fs_ls ( path ) : <EOL> try : <EOL> if fs . exists ( log_dir ) : <EOL> for path in fs . ls ( log_dir ) : <EOL> yield path <EOL> except IOError as e : <EOL> log . warning ( "<STR_LIT>" % ( log_dir , e ) ) <EOL> for log_dirs in log_dir_stream : <EOL> if isinstance ( log_dirs , str ) : <EOL> raise TypeError <EOL> matches = [ ] <EOL> for log_dir in log_dirs : <EOL> for path in _fs_ls ( log_dir ) : <EOL> m = matcher ( path , ** kwargs ) <EOL> if m is not None : <EOL> m [ '<STR_LIT:path>' ] = path <EOL> matches . append ( m ) <EOL> if matches : <EOL> return _sort_by_recency ( matches ) <EOL> return [ ] </s>
