<s> import os . path as op <EOL> from six . moves import StringIO <EOL> from bento . backends . yaku_backend import ConfigureYakuContext , BuildYakuContext , YakuBackend <EOL> from bento . commands . build import BuildCommand <EOL> from bento . commands . configure import ConfigureCommand <EOL> from bento . commands . contexts import GlobalContext <EOL> from bento . commands . options import OptionsContext <EOL> from bento . core import PackageDescription , PackageOptions <EOL> from bento . core . testing import create_fake_package_from_bento_info <EOL> def prepare_configure ( run_node , bento_info , context_klass = ConfigureYakuContext , cmd_argv = None ) : <EOL> if cmd_argv is None : <EOL> cmd_argv = [ ] <EOL> return _prepare_command ( run_node , bento_info , ConfigureCommand , context_klass , cmd_argv ) <EOL> def prepare_build ( run_node , bento_info , context_klass = BuildYakuContext , cmd_argv = None ) : <EOL> if cmd_argv is None : <EOL> cmd_argv = [ ] <EOL> return _prepare_command ( run_node , bento_info , BuildCommand , context_klass , cmd_argv ) <EOL> def _prepare_command ( run_node , bento_info , cmd_klass , context_klass , cmd_argv ) : <EOL> top_node = run_node . _ctx . srcnode <EOL> top_node . make_node ( "<STR_LIT>" ) . safe_write ( bento_info ) <EOL> package = PackageDescription . from_string ( bento_info ) <EOL> package_options = PackageOptions . from_string ( bento_info ) <EOL> cmd = cmd_klass ( ) <EOL> options_context = OptionsContext . from_command ( cmd ) <EOL> cmd . register_options ( options_context , package_options ) <EOL> global_context = GlobalContext ( None ) <EOL> global_context . register_package_options ( package_options ) <EOL> context = context_klass ( global_context , cmd_argv , options_context , package , run_node ) <EOL> return context , cmd <EOL> def create_global_context ( package , package_options , backend = None ) : <EOL> if backend is None : <EOL> backend = YakuBackend ( ) <EOL> global_context = GlobalContext ( None ) <EOL> global_context . register_package_options ( package_options ) <EOL> if backend : <EOL> global_context . backend = backend <EOL> build = BuildCommand ( ) <EOL> configure = ConfigureCommand ( ) <EOL> commands = ( ( "<STR_LIT>" , configure ) , ( "<STR_LIT>" , build ) ) <EOL> for cmd_name , cmd in commands : <EOL> global_context . register_command ( cmd_name , cmd ) <EOL> options_context = OptionsContext . from_command ( cmd ) <EOL> global_context . register_options_context ( cmd_name , options_context ) <EOL> global_context . backend . register_command_contexts ( global_context ) <EOL> global_context . backend . register_options_contexts ( global_context ) <EOL> return global_context <EOL> def prepare_package ( top_node , bento_info , backend = None ) : <EOL> package = PackageDescription . from_string ( bento_info ) <EOL> package_options = PackageOptions . from_string ( bento_info ) <EOL> create_fake_package_from_bento_info ( top_node , bento_info ) <EOL> top_node . make_node ( "<STR_LIT>" ) . safe_write ( bento_info ) <EOL> return create_global_context ( package , package_options , backend ) <EOL> def prepare_command ( global_context , cmd_name , cmd_argv , package , run_node ) : <EOL> if cmd_argv is None : <EOL> cmd_argv = [ ] <EOL> def _create_context ( cmd_name ) : <EOL> context_klass = global_context . retrieve_command_context ( cmd_name ) <EOL> options_context = global_context . retrieve_options_context ( cmd_name ) <EOL> context = context_klass ( global_context , cmd_argv , options_context , package , run_node ) <EOL> return context <EOL> return _create_context ( cmd_name ) , global_context . retrieve_command ( cmd_name ) <EOL> class EncodedStringIO ( object ) : <EOL> def __init__ ( self ) : <EOL> self . _data = StringIO ( ) <EOL> self . encoding = "<STR_LIT:ascii>" <EOL> def read ( self ) : <EOL> return self . _data . read ( ) <EOL> def write ( self , data ) : <EOL> return self . _data . write ( data ) <EOL> def flush ( self ) : <EOL> self . _data . flush ( ) <EOL> def comparable_installed_sections ( sections ) : <EOL> class _InstalledSectionProxy ( object ) : <EOL> def __init__ ( self , installed_section ) : <EOL> self . installed_section = installed_section <EOL> def __eq__ ( self , other ) : <EOL> _self = self . installed_section <EOL> _other = other . installed_section <EOL> def are_files_comparables ( ) : <EOL> if len ( _self . files ) != len ( _other . files ) : <EOL> return False <EOL> else : <EOL> for i in range ( len ( _self . files ) ) : <EOL> for j in range ( <NUM_LIT:2> ) : <EOL> if op . dirname ( _self . files [ i ] [ j ] ) != op . dirname ( _other . files [ i ] [ j ] ) : <EOL> return False <EOL> return True <EOL> return _self . name == _other . name and _self . source_dir == _other . source_dir and _self . target_dir == _other . target_dir and are_files_comparables ( ) <EOL> def __repr__ ( self ) : <EOL> return self . installed_section . __repr__ ( ) <EOL> def proxy_categories ( sections ) : <EOL> for category in sections : <EOL> for section_name , section in sections [ category ] . items ( ) : <EOL> sections [ category ] [ section_name ] = _InstalledSectionProxy ( section ) <EOL> return sections <EOL> return proxy_categories ( sections ) </s>
