<s> import os . path as op <EOL> from bento . backends . core import AbstractBackend <EOL> from bento . commands . command_contexts import ConfigureContext , BuildContext <EOL> class DistutilsConfigureContext ( ConfigureContext ) : <EOL> pass <EOL> class DistutilsBuildContext ( BuildContext ) : <EOL> def __init__ ( self , global_context , cmd_argv , options_context , pkg , run_node ) : <EOL> from bento . commands . build_distutils import DistutilsBuilder <EOL> super ( DistutilsBuildContext , self ) . __init__ ( global_context , cmd_argv , options_context , pkg , run_node ) <EOL> o , a = options_context . parser . parse_args ( cmd_argv ) <EOL> if o . jobs : <EOL> jobs = int ( o . jobs ) <EOL> else : <EOL> jobs = <NUM_LIT:1> <EOL> if o . verbose : <EOL> verbose = int ( o . verbose ) <EOL> else : <EOL> verbose = <NUM_LIT:0> <EOL> self . verbose = verbose <EOL> self . jobs = jobs <EOL> build_path = self . build_node . path_from ( self . run_node ) <EOL> self . _distutils_builder = DistutilsBuilder ( verbosity = self . verbose , build_base = build_path ) <EOL> def _builder_factory ( category , builder ) : <EOL> def _build ( extension , ** kw ) : <EOL> outputs = builder ( extension ) <EOL> nodes = [ self . build_node . find_node ( o ) for o in outputs ] <EOL> from_node = self . build_node <EOL> pkg_dir = op . dirname ( extension . name . replace ( '<STR_LIT:.>' , op . sep ) ) <EOL> target_dir = op . join ( '<STR_LIT>' , pkg_dir ) <EOL> self . outputs_registry . register_outputs ( category , extension . name , nodes , <EOL> from_node , target_dir ) <EOL> return _build <EOL> self . builder_registry . register_category ( "<STR_LIT>" , <EOL> _builder_factory ( "<STR_LIT>" , self . _distutils_builder . build_extension ) ) <EOL> self . builder_registry . register_category ( "<STR_LIT>" , <EOL> _builder_factory ( "<STR_LIT>" , self . _distutils_builder . build_compiled_library ) ) <EOL> def compile ( self ) : <EOL> super ( DistutilsBuildContext , self ) . compile ( ) <EOL> reg = self . builder_registry <EOL> for category in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> for name , extension in self . _node_pkg . iter_category ( category ) : <EOL> builder = reg . builder ( category , name ) <EOL> extension = extension . extension_from ( extension . ref_node ) <EOL> builder ( extension ) <EOL> class DistutilsBackend ( AbstractBackend ) : <EOL> def register_command_contexts ( self , context ) : <EOL> context . register_command_context ( "<STR_LIT>" , DistutilsConfigureContext ) <EOL> context . register_command_context ( "<STR_LIT>" , DistutilsBuildContext ) </s>
