<s> """<STR_LIT>""" <EOL> __author__ = '<STR_LIT>' <EOL> import csv <EOL> import os . path <EOL> from pyon . core . registry import getextends , isenum <EOL> from pyon . public import RT , OT <EOL> import interface . objects <EOL> class ObjectGenerator ( object ) : <EOL> @ staticmethod <EOL> def get_extends ( obj_class ) : <EOL> parents = [ parent for parent in obj_class . __mro__ if parent . __name__ not in { '<STR_LIT>' , '<STR_LIT:object>' , obj_class . __name__ } ] <EOL> return parents <EOL> def export_objects ( self , filename = None ) : <EOL> sub_types = { } <EOL> for obj_type in OT . keys ( ) : <EOL> ot_class = getattr ( interface . objects , obj_type ) <EOL> base_type = ot_class . __mro__ [ <NUM_LIT:1> ] . __name__ <EOL> sub_types . setdefault ( base_type , set ( ) ) . add ( obj_type ) <EOL> res_rows = [ ] <EOL> for obj_type in sorted ( OT . keys ( ) ) : <EOL> is_leaf = str ( not bool ( sub_types . get ( obj_type , None ) ) ) <EOL> ot_class = getattr ( interface . objects , obj_type ) <EOL> if not hasattr ( ot_class , "<STR_LIT>" ) : <EOL> continue <EOL> base_types_list = [ bc . __name__ for bc in reversed ( self . get_extends ( ot_class ) ) ] <EOL> base_type = base_types_list [ - <NUM_LIT:1> ] if base_types_list else "<STR_LIT>" <EOL> base_types = "<STR_LIT:/>" . join ( base_types_list [ : - <NUM_LIT:1> ] ) <EOL> oschema = ot_class . _schema <EOL> if obj_type in RT : <EOL> group = "<STR_LIT>" <EOL> elif isenum ( obj_type ) : <EOL> group = "<STR_LIT>" <EOL> elif "<STR_LIT>" in oschema and "<STR_LIT>" in oschema : <EOL> group = "<STR_LIT>" <EOL> else : <EOL> group = "<STR_LIT:object>" <EOL> res_rows . append ( [ "<STR_LIT:type>" , base_types , base_type , obj_type , "<STR_LIT>" , group , is_leaf , "<STR_LIT:True>" , "<STR_LIT>" , "<STR_LIT>" , ot_class . _class_info . get ( "<STR_LIT>" , "<STR_LIT>" ) . replace ( "<STR_LIT:\\>" , "<STR_LIT>" ) . strip ( ) , "<STR_LIT>" ] ) <EOL> if group == "<STR_LIT>" or group == "<STR_LIT:object>" : <EOL> res_rows . append ( [ group , base_types , base_type , obj_type , "<STR_LIT>" , "<STR_LIT>" , is_leaf , "<STR_LIT:True>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> for att in sorted ( oschema . keys ( ) ) : <EOL> if group == "<STR_LIT>" and att in { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:name>" , "<STR_LIT:description>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } : <EOL> continue <EOL> att_obj = oschema [ att ] <EOL> ot , odef , odeco , odesc = att_obj [ "<STR_LIT:type>" ] , att_obj [ "<STR_LIT:default>" ] , att_obj [ "<STR_LIT>" ] , att_obj [ "<STR_LIT:description>" ] <EOL> if group == "<STR_LIT>" and att == "<STR_LIT:name>" : <EOL> odesc = "<STR_LIT>" <EOL> att_def = obj_type <EOL> leaf_attr = True <EOL> for base_class in self . get_extends ( ot_class ) : <EOL> if hasattr ( base_class , "<STR_LIT>" ) and att in base_class . _schema : <EOL> att_def = base_class . __name__ <EOL> leaf_attr = False <EOL> is_internal = "<STR_LIT>" <EOL> attr_desc = odesc . replace ( "<STR_LIT:\\>" , "<STR_LIT>" ) . strip ( ) <EOL> if "<STR_LIT>" in attr_desc : <EOL> is_internal = "<STR_LIT>" <EOL> res_rows . append ( [ group , base_types , base_type , obj_type , att , ot , is_leaf , leaf_attr , att_def , odef , attr_desc , is_internal ] ) <EOL> if not filename : <EOL> csvfile_name = os . path . join ( "<STR_LIT>" , '<STR_LIT>' ) <EOL> try : <EOL> os . unlink ( csvfile_name ) <EOL> except : <EOL> pass <EOL> else : <EOL> csvfile_name = filename <EOL> print "<STR_LIT>" + csvfile_name + "<STR_LIT:'>" <EOL> csvfile = csv . writer ( open ( csvfile_name , '<STR_LIT:wb>' ) , delimiter = '<STR_LIT:U+002C>' , <EOL> quotechar = '<STR_LIT:">' , quoting = csv . QUOTE_ALL ) <EOL> csvfile . writerow ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> csvfile . writerows ( res_rows ) </s>
