#NEWLINE# def generate_model( args ) : #NEWLINE# #INDENT# 'Generate model.' #NEWLINE# model_name = args . get ( '<model>' ) #NEWLINE# if ( not model_template ) : #NEWLINE# #INDENT# logger . warning ( 'Model name cannot be empty.' ) #NEWLINE# return #NEWLINE# #UNINDENT# logger . info ( 'Start generating model.' ) #NEWLINE# model_template = os . path . join ( dirname ( abspath ( __file__ ) ) , 'templates/model.py' ) #NEWLINE# current_path = os . getcwd ( ) #NEWLINE# with open ( model_template , 'r' ) as template_file : #NEWLINE# #INDENT# model_file_path = os . path . join ( current_path , 'application/models' , ( model_name + '.py' ) ) #NEWLINE# with open ( model_file_path , 'w+' ) as model_file : #NEWLINE# #INDENT# for line in template_file : #NEWLINE# #INDENT# new_line = line . replace ( '#{model|title}' , model_name . title ( ) ) #NEWLINE# model_file . write ( new_line ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# logger . info ( ( 'New: %s' % _relative_path ( model_file_path ) ) ) #NEWLINE# with open ( os . path . join ( current_path , 'application/models/__init__.py' ) , 'a' ) as package_file : #NEWLINE# #INDENT# package_file . write ( ( '\nfrom .%s import *' % model_name ) ) #NEWLINE# #UNINDENT# logger . info ( 'Finish generating model.' )