<s> """<STR_LIT>""" <EOL> from __future__ import print_function <EOL> import argparse <EOL> import getpass <EOL> import locale <EOL> import logging <EOL> import os <EOL> import sys <EOL> from dfvfs . credentials import manager as credentials_manager <EOL> from dfvfs . helpers import source_scanner <EOL> from dfvfs . lib import definitions <EOL> class SourceAnalyzer ( object ) : <EOL> """<STR_LIT>""" <EOL> _READ_BUFFER_SIZE = <NUM_LIT> <EOL> def __init__ ( self , auto_recurse = True ) : <EOL> """<STR_LIT>""" <EOL> super ( SourceAnalyzer , self ) . __init__ ( ) <EOL> self . _auto_recurse = auto_recurse <EOL> self . _encode_errors = u'<STR_LIT:strict>' <EOL> self . _preferred_encoding = locale . getpreferredencoding ( ) <EOL> self . _source_scanner = source_scanner . SourceScanner ( ) <EOL> def _EncodeString ( self , string ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> encoded_string = string . encode ( <EOL> self . _preferred_encoding , errors = self . _encode_errors ) <EOL> except UnicodeEncodeError : <EOL> if self . _encode_errors == u'<STR_LIT:strict>' : <EOL> logging . error ( <EOL> u'<STR_LIT>' <EOL> u'<STR_LIT>' <EOL> u'<STR_LIT>' <EOL> u'<STR_LIT>' ) <EOL> self . _encode_errors = u'<STR_LIT:replace>' <EOL> encoded_string = string . encode ( <EOL> self . _preferred_encoding , errors = self . _encode_errors ) <EOL> return encoded_string <EOL> def _PromptUserForEncryptedVolumeCredential ( <EOL> self , scan_context , locked_scan_node , output_writer ) : <EOL> """<STR_LIT>""" <EOL> credentials = credentials_manager . CredentialsManager . GetCredentials ( <EOL> locked_scan_node . path_spec ) <EOL> if locked_scan_node . type_indicator == definitions . TYPE_INDICATOR_BDE : <EOL> output_writer . WriteLine ( u'<STR_LIT>' ) <EOL> else : <EOL> output_writer . WriteLine ( u'<STR_LIT>' ) <EOL> credentials_list = list ( credentials . CREDENTIALS ) <EOL> credentials_list . append ( u'<STR_LIT>' ) <EOL> output_writer . WriteLine ( u'<STR_LIT>' ) <EOL> output_writer . WriteLine ( u'<STR_LIT>' ) <EOL> for index , name in enumerate ( credentials_list ) : <EOL> output_writer . WriteLine ( u'<STR_LIT>' . format ( index , name ) ) <EOL> output_writer . WriteLine ( u'<STR_LIT>' ) <EOL> result = False <EOL> while not result : <EOL> output_writer . WriteString ( <EOL> u'<STR_LIT>' ) <EOL> input_line = sys . stdin . readline ( ) <EOL> input_line = input_line . strip ( ) <EOL> if input_line in credentials_list : <EOL> credential_identifier = input_line <EOL> else : <EOL> try : <EOL> credential_identifier = int ( input_line , <NUM_LIT:10> ) <EOL> credential_identifier = credentials_list [ credential_identifier ] <EOL> except ( IndexError , ValueError ) : <EOL> output_writer . WriteLine ( <EOL> u'<STR_LIT>' . format ( input_line ) ) <EOL> continue <EOL> if credential_identifier == u'<STR_LIT>' : <EOL> break <EOL> getpass_string = u'<STR_LIT>' <EOL> if sys . platform . startswith ( u'<STR_LIT>' ) and sys . version_info [ <NUM_LIT:0> ] < <NUM_LIT:3> : <EOL> getpass_string = self . _EncodeString ( getpass_string ) <EOL> credential_data = getpass . getpass ( getpass_string ) <EOL> output_writer . WriteLine ( u'<STR_LIT>' ) <EOL> result = self . _source_scanner . Unlock ( <EOL> scan_context , locked_scan_node . path_spec , credential_identifier , <EOL> credential_data ) <EOL> if not result : <EOL> output_writer . WriteLine ( u'<STR_LIT>' ) <EOL> output_writer . WriteLine ( u'<STR_LIT>' ) <EOL> def Analyze ( self , source_path , output_writer ) : <EOL> """<STR_LIT>""" <EOL> if not os . path . exists ( source_path ) : <EOL> raise RuntimeError ( u'<STR_LIT>' . format ( source_path ) ) <EOL> scan_context = source_scanner . SourceScannerContext ( ) <EOL> scan_path_spec = None <EOL> scan_step = <NUM_LIT:0> <EOL> scan_context . OpenSourcePath ( source_path ) <EOL> while True : <EOL> self . _source_scanner . Scan ( <EOL> scan_context , auto_recurse = self . _auto_recurse , <EOL> scan_path_spec = scan_path_spec ) <EOL> if not scan_context . updated : <EOL> break <EOL> if not self . _auto_recurse : <EOL> output_writer . WriteScanContext ( scan_context , scan_step = scan_step ) <EOL> scan_step += <NUM_LIT:1> <EOL> if scan_context . source_type in [ <EOL> definitions . SOURCE_TYPE_DIRECTORY , definitions . SOURCE_TYPE_FILE ] : <EOL> break <EOL> for locked_scan_node in scan_context . locked_scan_nodes : <EOL> self . _PromptUserForEncryptedVolumeCredential ( <EOL> scan_context , locked_scan_node , output_writer ) <EOL> if not self . _auto_recurse : <EOL> scan_node = scan_context . GetUnscannedScanNode ( ) <EOL> if not scan_node : <EOL> return <EOL> scan_path_spec = scan_node . path_spec <EOL> if self . _auto_recurse : <EOL> output_writer . WriteScanContext ( scan_context ) <EOL> class StdoutWriter ( object ) : <EOL> """<STR_LIT>""" <EOL> def Open ( self ) : <EOL> """<STR_LIT>""" <EOL> return True <EOL> def Close ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def WriteLine ( self , line ) : <EOL> """<STR_LIT>""" <EOL> print ( line ) <EOL> def WriteScanContext ( self , scan_context , scan_step = None ) : <EOL> """<STR_LIT>""" <EOL> if scan_step is not None : <EOL> print ( u'<STR_LIT>' . format ( scan_step ) ) <EOL> print ( u'<STR_LIT>' . format ( scan_context . source_type ) ) <EOL> print ( u'<STR_LIT>' ) <EOL> scan_node = scan_context . GetRootScanNode ( ) <EOL> self . WriteScanNode ( scan_node ) <EOL> print ( u'<STR_LIT>' ) <EOL> def WriteScanNode ( self , scan_node , indentation = u'<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> if not scan_node : <EOL> return <EOL> values = [ ] <EOL> part_index = getattr ( scan_node . path_spec , u'<STR_LIT>' , None ) <EOL> if part_index is not None : <EOL> values . append ( u'<STR_LIT>' . format ( part_index ) ) <EOL> store_index = getattr ( scan_node . path_spec , u'<STR_LIT>' , None ) <EOL> if store_index is not None : <EOL> values . append ( u'<STR_LIT>' . format ( store_index ) ) <EOL> start_offset = getattr ( scan_node . path_spec , u'<STR_LIT>' , None ) <EOL> if start_offset is not None : <EOL> values . append ( u'<STR_LIT>' . format ( start_offset ) ) <EOL> location = getattr ( scan_node . path_spec , u'<STR_LIT:location>' , None ) <EOL> if location is not None : <EOL> values . append ( u'<STR_LIT>' . format ( location ) ) <EOL> print ( u'<STR_LIT>' . format ( <EOL> indentation , scan_node . path_spec . type_indicator , u'<STR_LIT:U+002CU+0020>' . join ( values ) ) ) <EOL> indentation = u'<STR_LIT>' . format ( indentation ) <EOL> for sub_scan_node in scan_node . sub_nodes : <EOL> self . WriteScanNode ( sub_scan_node , indentation = indentation ) <EOL> def WriteString ( self , string ) : <EOL> """<STR_LIT>""" <EOL> print ( string , end = u'<STR_LIT>' ) <EOL> def Main ( ) : <EOL> """<STR_LIT>""" <EOL> argument_parser = argparse . ArgumentParser ( description = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> argument_parser . add_argument ( <EOL> '<STR_LIT:source>' , nargs = '<STR_LIT:?>' , action = '<STR_LIT:store>' , metavar = '<STR_LIT>' , <EOL> default = None , help = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> argument_parser . add_argument ( <EOL> u'<STR_LIT>' , u'<STR_LIT>' , dest = u'<STR_LIT>' , <EOL> action = u'<STR_LIT:store_true>' , default = False , help = ( <EOL> u'<STR_LIT>' ) ) <EOL> options = argument_parser . parse_args ( ) <EOL> if not options . source : <EOL> print ( u'<STR_LIT>' ) <EOL> print ( u'<STR_LIT>' ) <EOL> argument_parser . print_help ( ) <EOL> print ( u'<STR_LIT>' ) <EOL> return False <EOL> logging . basicConfig ( <EOL> level = logging . INFO , format = u'<STR_LIT>' ) <EOL> output_writer = StdoutWriter ( ) <EOL> if not output_writer . Open ( ) : <EOL> print ( u'<STR_LIT>' ) <EOL> print ( u'<STR_LIT>' ) <EOL> return False <EOL> return_value = True <EOL> source_analyzer = SourceAnalyzer ( auto_recurse = not options . no_auto_recurse ) <EOL> try : <EOL> source_analyzer . Analyze ( options . source , output_writer ) <EOL> print ( u'<STR_LIT>' ) <EOL> except KeyboardInterrupt : <EOL> return_value = False <EOL> print ( u'<STR_LIT>' ) <EOL> output_writer . Close ( ) <EOL> return return_value <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> if not Main ( ) : <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> else : <EOL> sys . exit ( <NUM_LIT:0> ) </s>
