src/admin_toolbelt/utils.py
def human_numeric_sort(lines, column=0):
    """Sorts the given lines numerically on the chosen column, supports suffixes 
    such as '15k' or '1G'. 
    """
    def key_func(line):
        items = line.split()
        try:
            item = items[column]
        except:
            return -1
        
        if re.search(r'^\d+$', item):
            return int(item)
            
        m = re.search(r'(\d+)([kmgtpKMGTP])', item)
        if m:
            v, s = int(m.group(1)), m.group(2)
            if s in 'kK':
                v *= 1000
            if s in 'mM':
                v *= 1000000
            if s in 'gG':
                v *= 1000000000
            if s in 'tT':
                v *= 1000000000000
            if s in 'pP':
                v *= 1000000000000000
            return v
        return -1
        
    return sorted(lines, key=key_func)
Sorts the given lines numerically on the chosen column, supports suffixes 
    such as '15k' or '1G'. 
    
Sorts the given lines numerically on the chosen column, supports suffixes
such as '15k' or '1G'.
Sorts the given lines numerically on the chosen column supports suffixes such as ' 15k ' or ' 1G ' .
def human_numeric_sort(lines, column=0):
    def key_func(line):
        items = line.split()
        try:
            item = items[column]
        except:
            return -1
        if re.search(r'^\d+$', item):
            return int(item)
        m = re.search(r'(\d+)([kmgtpKMGTP])', item)
        if m:
            v, s = int(m.group(1)), m.group(2)
            if s in 'kK':
                v *= 1000
            if s in 'mM':
                v *= 1000000
            if s in 'gG':
                v *= 1000000000
            if s in 'tT':
                v *= 1000000000000
            if s in 'pP':
                v *= 1000000000000000
            return v
        return -1
    return sorted(lines, key=key_func)
def human_numeric_sort ( lines , column = 0 ) : def key_func ( line ) : items = line . split ( ) try : item = items [ column ] except : return - 1 if re . search ( r'^\d+$' , item ) : return int ( item ) m = re . search ( r'(\d+)([kmgtpKMGTP])' , item ) if m : v , s = int ( m . group ( 1 ) ) , m . group ( 2 ) if s in 'kK' : v *= 1000 if s in 'mM' : v *= 1000000 if s in 'gG' : v *= 1000000000 if s in 'tT' : v *= 1000000000000 if s in 'pP' : v *= 1000000000000000 return v return - 1 return sorted ( lines , key = key_func )
Sorts the given lines numerically on the chosen column, supports suffixes
such as '15k' or '1G'.
Sorts the given lines numerically on the chosen column supports suffixes such as ' 15k ' or ' 1G ' .
"""Sorts the given lines numerically on the chosen column, supports suffixes 
    such as '15k' or '1G'. 
    """
lines
column