<s> import os , os . path <EOL> from django . template import Context <EOL> from django . template . loader import select_template <EOL> SIMPLEADMINDOC_PATH = "<STR_LIT>" <EOL> def write ( filename , content ) : <EOL> pathname = os . path . split ( filename ) [ <NUM_LIT:0> ] <EOL> if not os . path . exists ( pathname ) : <EOL> os . makedirs ( pathname ) <EOL> f = open ( filename , "<STR_LIT:w>" ) <EOL> f . write ( content . encode ( '<STR_LIT:utf-8>' ) ) <EOL> f . close ( ) <EOL> def model_doc ( model ) : <EOL> ctx = Context ( ) <EOL> ctx [ '<STR_LIT>' ] = model . _meta <EOL> templates = ( '<STR_LIT>' % ( model . _meta . app_label , <EOL> model . __name__ . lower ( ) ) , <EOL> '<STR_LIT>' % model . _meta . app_label , <EOL> '<STR_LIT>' ) <EOL> tmpl = select_template ( templates ) <EOL> return tmpl . render ( ctx ) <EOL> def generate_model_doc ( model , path = None ) : <EOL> content = model_doc ( model ) <EOL> filename = '<STR_LIT>' % ( path or SIMPLEADMINDOC_PATH , <EOL> model . _meta . app_label , model . __name__ . lower ( ) ) <EOL> write ( filename , content ) <EOL> def app_doc ( app ) : <EOL> app_label = app . __name__ . split ( '<STR_LIT:.>' ) [ - <NUM_LIT:2> ] <EOL> ctx = Context ( ) <EOL> ctx [ '<STR_LIT>' ] = app_label <EOL> templates = ( '<STR_LIT>' % app_label , <EOL> '<STR_LIT>' ) <EOL> tmpl = select_template ( templates ) <EOL> return tmpl . render ( ctx ) <EOL> def generate_app_doc ( app , path = None ) : <EOL> app_label = app . __name__ . split ( '<STR_LIT:.>' ) [ - <NUM_LIT:2> ] <EOL> content = app_doc ( app ) <EOL> filename = '<STR_LIT>' % ( path or SIMPLEADMINDOC_PATH , app_label ) <EOL> write ( filename , content ) </s>
