<s> import subprocess <EOL> import os <EOL> from logging import info <EOL> import argparse <EOL> from servi . command import Command <EOL> import servi . config as c <EOL> from servi . utils import timeit <EOL> from servi . template_mgr import TemplateManager <EOL> from servi . commands . buildbox import get_all_boxes <EOL> from servi . exceptions import ServiError , ForceError <EOL> class UseboxCommand ( Command ) : <EOL> def register_command_line ( self , sub_parsers ) : <EOL> parser = sub_parsers . add_parser ( <EOL> '<STR_LIT>' , help = "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> description = <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , action = '<STR_LIT:store_true>' ) <EOL> parser . add_argument ( '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> help = argparse . SUPPRESS ) <EOL> parser . set_defaults ( command_func = self . run ) <EOL> def run ( self , args , extra_args ) : <EOL> all_boxes = get_all_boxes ( ) <EOL> if len ( all_boxes ) is <NUM_LIT:0> : <EOL> raise ServiError ( '<STR_LIT>' ) <EOL> ver = all_boxes [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] <EOL> tmgr = TemplateManager ( ) <EOL> if not args . force and ver < tmgr . m_template . template_version : <EOL> raise ForceError ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> . format ( tmgr . m_template . template_version , <EOL> all_boxes [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] ) ) <EOL> env = os . environ . copy ( ) <EOL> env [ '<STR_LIT>' ] = os . path . join ( c . BOX_DIR , all_boxes [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] ) <EOL> os . chdir ( c . MASTER_DIR ) <EOL> if not args . mock : <EOL> with timeit ( ) : <EOL> subprocess . check_call ( '<STR_LIT>' , env = env , shell = True ) <EOL> else : <EOL> info ( '<STR_LIT>' <EOL> . format ( env [ '<STR_LIT>' ] ) ) <EOL> return True <EOL> command = UseboxCommand ( ) </s>
