<s> import os <EOL> import servi . config as c <EOL> from servi . command import Command <EOL> from servi . exceptions import ForceError , ServiError <EOL> from servi . template_mgr import TemplateManager <EOL> from servi . config import set_master_dir , load_user_config , servi_file_exists_in , global_servi_file_exists <EOL> class InitCommand ( Command ) : <EOL> def __init__ ( self ) : <EOL> super ( ) . __init__ ( ) <EOL> self . special = { "<STR_LIT>" : True } <EOL> def register_command_line ( self , sub_parsers ) : <EOL> parser = sub_parsers . add_parser ( '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , action = '<STR_LIT:store_true>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' ) <EOL> parser . set_defaults ( command_func = self . run ) <EOL> def run ( self , args , extra_args ) : <EOL> """<STR_LIT>""" <EOL> def assert_doit ( ) : <EOL> if args . force : <EOL> return True <EOL> else : <EOL> if servi_file_exists_in ( args . dir ) : <EOL> raise ForceError ( <EOL> '<STR_LIT>' <EOL> . format ( os . path . abspath ( args . dir ) ) ) <EOL> if ( not args . skip_servifile_globals and <EOL> global_servi_file_exists ( ) ) : <EOL> raise ForceError ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> . format ( c . SERVIFILE_GLOBAL_FULL ) ) <EOL> assert_doit ( ) <EOL> if not os . path . exists ( args . dir ) : <EOL> os . mkdir ( args . dir ) <EOL> else : <EOL> if not os . path . isdir ( args . dir ) : <EOL> raise ServiError ( <EOL> "<STR_LIT>" <EOL> . format ( args . dir ) ) <EOL> set_master_dir ( set_dir_to = os . path . abspath ( args . dir ) ) <EOL> os . chdir ( c . MASTER_DIR ) <EOL> tmgr = TemplateManager ( ) <EOL> tmgr . init_master ( exclude_files = [ c . SERVIFILE_GLOBAL ] <EOL> if args . skip_servifile_globals else [ ] ) <EOL> load_user_config ( ) <EOL> return True <EOL> command = InitCommand ( ) </s>
