<s> import os <EOL> import inflection <EOL> from cleo import Command <EOL> from . stubs import MODEL_DEFAULT_STUB <EOL> from ... utils import mkdir_p <EOL> class ModelMakeCommand ( Command ) : <EOL> """<STR_LIT>""" <EOL> def handle ( self ) : <EOL> name = self . argument ( '<STR_LIT:name>' ) <EOL> singular = inflection . singularize ( inflection . tableize ( name ) ) <EOL> directory = self . _get_path ( ) <EOL> filepath = self . _get_path ( singular + '<STR_LIT>' ) <EOL> if os . path . exists ( filepath ) : <EOL> raise RuntimeError ( '<STR_LIT>' ) <EOL> mkdir_p ( directory ) <EOL> parent = os . path . join ( directory , '<STR_LIT>' ) <EOL> if not os . path . exists ( parent ) : <EOL> with open ( parent , '<STR_LIT:w>' ) : <EOL> pass <EOL> stub = self . _get_stub ( ) <EOL> stub = self . _populate_stub ( name , stub ) <EOL> with open ( filepath , '<STR_LIT:w>' ) as f : <EOL> f . write ( stub ) <EOL> self . info ( '<STR_LIT>' % name ) <EOL> if self . option ( '<STR_LIT>' ) : <EOL> table = inflection . tableize ( name ) <EOL> self . call ( <EOL> '<STR_LIT>' , <EOL> [ <EOL> ( '<STR_LIT:name>' , '<STR_LIT>' % table ) , <EOL> ( '<STR_LIT>' , table ) , <EOL> ( '<STR_LIT>' , True ) <EOL> ] <EOL> ) <EOL> def _get_stub ( self ) : <EOL> """<STR_LIT>""" <EOL> return MODEL_DEFAULT_STUB <EOL> def _populate_stub ( self , name , stub ) : <EOL> """<STR_LIT>""" <EOL> stub = stub . replace ( '<STR_LIT>' , name ) <EOL> return stub <EOL> def _get_path ( self , name = None ) : <EOL> if self . option ( '<STR_LIT:path>' ) : <EOL> directory = self . option ( '<STR_LIT:path>' ) <EOL> else : <EOL> directory = os . path . join ( os . getcwd ( ) , '<STR_LIT>' ) <EOL> if name : <EOL> return os . path . join ( directory , name ) <EOL> return directory </s>
