<s> from django . core . management . base import NoArgsCommand , CommandError <EOL> class Command ( NoArgsCommand ) : <EOL> help = "<STR_LIT>" <EOL> requires_model_validation = False <EOL> def handle_noargs ( self , ** options ) : <EOL> try : <EOL> for line in self . handle_inspection ( ) : <EOL> print line <EOL> except NotImplementedError : <EOL> raise CommandError ( "<STR_LIT>" ) <EOL> def handle_inspection ( self ) : <EOL> from django . db import connection <EOL> import keyword <EOL> table2model = lambda table_name : table_name . title ( ) . replace ( '<STR_LIT:_>' , '<STR_LIT>' ) . replace ( '<STR_LIT:U+0020>' , '<STR_LIT>' ) . replace ( '<STR_LIT:->' , '<STR_LIT>' ) <EOL> cursor = connection . cursor ( ) <EOL> yield "<STR_LIT>" <EOL> yield "<STR_LIT>" <EOL> yield "<STR_LIT>" <EOL> yield "<STR_LIT>" <EOL> yield "<STR_LIT>" <EOL> yield "<STR_LIT:#>" <EOL> yield "<STR_LIT>" <EOL> yield "<STR_LIT>" <EOL> yield '<STR_LIT>' <EOL> yield '<STR_LIT>' <EOL> yield '<STR_LIT>' <EOL> for table_name in connection . introspection . get_table_list ( cursor ) : <EOL> yield '<STR_LIT>' % table2model ( table_name ) <EOL> try : <EOL> relations = connection . introspection . get_relations ( cursor , table_name ) <EOL> except NotImplementedError : <EOL> relations = { } <EOL> try : <EOL> indexes = connection . introspection . get_indexes ( cursor , table_name ) <EOL> except NotImplementedError : <EOL> indexes = { } <EOL> for i , row in enumerate ( connection . introspection . get_table_description ( cursor , table_name ) ) : <EOL> column_name = row [ <NUM_LIT:0> ] <EOL> att_name = column_name . lower ( ) <EOL> comment_notes = [ ] <EOL> extra_params = { } <EOL> if '<STR_LIT:U+0020>' in att_name or '<STR_LIT:->' in att_name or keyword . iskeyword ( att_name ) or column_name != att_name : <EOL> extra_params [ '<STR_LIT>' ] = column_name <EOL> if '<STR_LIT:U+0020>' in att_name : <EOL> att_name = att_name . replace ( '<STR_LIT:U+0020>' , '<STR_LIT:_>' ) <EOL> comment_notes . append ( '<STR_LIT>' ) <EOL> if '<STR_LIT:->' in att_name : <EOL> att_name = att_name . replace ( '<STR_LIT:->' , '<STR_LIT:_>' ) <EOL> comment_notes . append ( '<STR_LIT>' ) <EOL> if keyword . iskeyword ( att_name ) : <EOL> att_name += '<STR_LIT>' <EOL> comment_notes . append ( '<STR_LIT>' ) <EOL> if column_name != att_name : <EOL> comment_notes . append ( '<STR_LIT>' ) <EOL> if i in relations : <EOL> rel_to = relations [ i ] [ <NUM_LIT:1> ] == table_name and "<STR_LIT>" or table2model ( relations [ i ] [ <NUM_LIT:1> ] ) <EOL> field_type = '<STR_LIT>' % rel_to <EOL> if att_name . endswith ( '<STR_LIT>' ) : <EOL> att_name = att_name [ : - <NUM_LIT:3> ] <EOL> else : <EOL> extra_params [ '<STR_LIT>' ] = column_name <EOL> else : <EOL> try : <EOL> field_type = connection . introspection . data_types_reverse [ row [ <NUM_LIT:1> ] ] <EOL> except KeyError : <EOL> field_type = '<STR_LIT>' <EOL> comment_notes . append ( '<STR_LIT>' ) <EOL> if type ( field_type ) is tuple : <EOL> field_type , new_params = field_type <EOL> extra_params . update ( new_params ) <EOL> if field_type == '<STR_LIT>' and row [ <NUM_LIT:3> ] : <EOL> extra_params [ '<STR_LIT:max_length>' ] = row [ <NUM_LIT:3> ] <EOL> if field_type == '<STR_LIT>' : <EOL> extra_params [ '<STR_LIT>' ] = row [ <NUM_LIT:4> ] <EOL> extra_params [ '<STR_LIT>' ] = row [ <NUM_LIT:5> ] <EOL> if column_name in indexes : <EOL> if indexes [ column_name ] [ '<STR_LIT:primary_key>' ] : <EOL> extra_params [ '<STR_LIT:primary_key>' ] = True <EOL> elif indexes [ column_name ] [ '<STR_LIT>' ] : <EOL> extra_params [ '<STR_LIT>' ] = True <EOL> field_type += '<STR_LIT:(>' <EOL> if att_name == '<STR_LIT:id>' and field_type == '<STR_LIT>' and extra_params == { '<STR_LIT:primary_key>' : True } : <EOL> continue <EOL> if row [ <NUM_LIT:6> ] : <EOL> extra_params [ '<STR_LIT:blank>' ] = True <EOL> if not field_type in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> extra_params [ '<STR_LIT:null>' ] = True <EOL> field_desc = '<STR_LIT>' % ( att_name , field_type ) <EOL> if extra_params : <EOL> if not field_desc . endswith ( '<STR_LIT:(>' ) : <EOL> field_desc += '<STR_LIT:U+002CU+0020>' <EOL> field_desc += '<STR_LIT:U+002CU+0020>' . join ( [ '<STR_LIT>' % ( k , v ) for k , v in extra_params . items ( ) ] ) <EOL> field_desc += '<STR_LIT:)>' <EOL> if comment_notes : <EOL> field_desc += '<STR_LIT>' + '<STR_LIT:U+0020>' . join ( comment_notes ) <EOL> yield '<STR_LIT>' % field_desc <EOL> yield '<STR_LIT>' <EOL> yield '<STR_LIT>' % table_name <EOL> yield '<STR_LIT>' </s>
