<s> import os <EOL> import os . path as op <EOL> from bento . utils . utils import subst_vars <EOL> from bento . installed_package_description import BuildManifest , build_manifest_meta_from_pkg <EOL> from bento . _config import BUILD_MANIFEST_PATH <EOL> from bento . commands . core import Option <EOL> from bento . commands . core import Command <EOL> from bento . utils import cpu_count <EOL> class SectionWriter ( object ) : <EOL> def __init__ ( self ) : <EOL> self . sections = { } <EOL> def store ( self , filename , pkg ) : <EOL> meta = build_manifest_meta_from_pkg ( pkg ) <EOL> p = BuildManifest ( self . sections , meta , pkg . executables ) <EOL> if not op . exists ( op . dirname ( filename ) ) : <EOL> os . makedirs ( op . dirname ( filename ) ) <EOL> p . write ( filename ) <EOL> def jobs_callback ( option , opt , value , parser ) : <EOL> setattr ( parser . values , option . dest , cpu_count ( ) ) <EOL> class BuildCommand ( Command ) : <EOL> long_descr = """<STR_LIT>""" <EOL> short_descr = "<STR_LIT>" <EOL> common_options = Command . common_options + [ Option ( "<STR_LIT>" , "<STR_LIT>" , <EOL> help = "<STR_LIT>" , action = "<STR_LIT:store_true>" ) , <EOL> Option ( "<STR_LIT>" , "<STR_LIT>" , <EOL> help = "<STR_LIT>" , <EOL> dest = "<STR_LIT>" , action = "<STR_LIT>" , callback = jobs_callback ) , <EOL> Option ( "<STR_LIT>" , "<STR_LIT>" , <EOL> help = "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" ) ] <EOL> def run ( self , ctx ) : <EOL> p = ctx . options_context . parser <EOL> o , a = p . parse_args ( ctx . command_argv ) <EOL> if o . help : <EOL> p . print_help ( ) <EOL> return <EOL> ctx . compile ( ) <EOL> ctx . post_compile ( ) <EOL> def finish ( self , ctx ) : <EOL> super ( BuildCommand , self ) . finish ( ctx ) <EOL> n = ctx . build_node . make_node ( BUILD_MANIFEST_PATH ) <EOL> ctx . section_writer . store ( n . abspath ( ) , ctx . pkg ) <EOL> def _config_content ( paths ) : <EOL> keys = sorted ( paths . keys ( ) ) <EOL> n = max ( [ len ( k ) for k in keys ] ) + <NUM_LIT:2> <EOL> content = [ ] <EOL> for name , value in sorted ( paths . items ( ) ) : <EOL> content . append ( '<STR_LIT>' % ( name . upper ( ) . ljust ( n ) , subst_vars ( value , paths ) ) ) <EOL> return "<STR_LIT:\n>" . join ( content ) </s>
