def get_sorted_filediffs(filediffs, key=None):
 def cmp_filediffs(x, y):
  if (x[0] != y[0]):
   return cmp(x[0], y[0])
  (x_file, x_ext) = os.path.splitext(x[1])
  (y_file, y_ext) = os.path.splitext(y[1])
  if (x_file == y_file):
   return cmp(y_ext, x_ext)
  else:
   return cmp(x_file, y_file)
 def make_key(filediff):
  if key:
   filediff = key(filediff)
  filename = filediff.dest_file
  i = filename.rfind(u'/')
  if (i == (-1)):
   return (u'', filename)
  else:
   return (filename[:i], filename[(i + 1):])
 return sorted(filediffs, cmp=cmp_filediffs, key=make_key)

def get_sorted_filediffs ( filediffs , key = None ) : def cmp_filediffs ( x , y ) : if ( x [ 0 ] != y [ 0 ] ) : return cmp ( x [ 0 ] , y [ 0 ] ) ( x_file , x_ext ) = os . path . splitext ( x [ 1 ] ) ( y_file , y_ext ) = os . path . splitext ( y [ 1 ] ) if ( x_file == y_file ) : return cmp ( y_ext , x_ext ) else : return cmp ( x_file , y_file ) def make_key ( filediff ) : if key : filediff = key ( filediff ) filename = filediff . dest_file i = filename . rfind ( u'/' ) if ( i == ( - 1 ) ) : return ( u'' , filename ) else : return ( filename [ : i ] , filename [ ( i + 1 ) : ] ) return sorted ( filediffs , cmp = cmp_filediffs , key = make_key )
sorts a list of filediffs .