def to_string_from_fields(item_dict, fields, interface_fields=None):
 buf = ''
 keys = []
 for elem in fields:
  keys.append((elem[0], elem[3], elem[4]))
 keys.sort()
 buf += ('%-30s : %s\n' % ('Name', item_dict['name']))
 for (k, nicename, editable) in keys:
  if (not editable):
   continue
  if (k != 'name'):
   buf += ('%-30s : %s\n' % (nicename, item_dict[k]))
 if (('interfaces' in item_dict) and (interface_fields is not None)):
  keys = []
  for elem in interface_fields:
   keys.append((elem[0], elem[3], elem[4]))
  keys.sort()
  for iname in item_dict['interfaces'].keys():
   buf += ('%-30s : %s\n' % ('Interface ===== ', iname))
   for (k, nicename, editable) in keys:
    if editable:
     buf += ('%-30s : %s\n' % (nicename, item_dict['interfaces'][iname].get(k, '')))
 return buf

def to_string_from_fields ( item_dict , fields , interface_fields = None ) : buf = '' keys = [ ] for elem in fields : keys . append ( ( elem [ 0 ] , elem [ 3 ] , elem [ 4 ] ) ) keys . sort ( ) buf += ( '%-30s : %s\n' % ( 'Name' , item_dict [ 'name' ] ) ) for ( k , nicename , editable ) in keys : if ( not editable ) : continue if ( k != 'name' ) : buf += ( '%-30s : %s\n' % ( nicename , item_dict [ k ] ) ) if ( ( 'interfaces' in item_dict ) and ( interface_fields is not None ) ) : keys = [ ] for elem in interface_fields : keys . append ( ( elem [ 0 ] , elem [ 3 ] , elem [ 4 ] ) ) keys . sort ( ) for iname in item_dict [ 'interfaces' ] . keys ( ) : buf += ( '%-30s : %s\n' % ( 'Interface ===== ' , iname ) ) for ( k , nicename , editable ) in keys : if editable : buf += ( '%-30s : %s\n' % ( nicename , item_dict [ 'interfaces' ] [ iname ] . get ( k , '' ) ) ) return buf
item_dict is a dictionary .