# HG changeset patch # User Razvan Pascanu # Date 1298392802 18000 # Node ID 35b56d794d097fa648ef33e1b4d33f229157fe9b # Parent 3dd64c115657a49dc09622d4727cbe68ab00de11 added option to order descending /ascending the fields acording to their size diff -r 3dd64c115657 -r 35b56d794d09 bin/pkldu.py --- a/bin/pkldu.py Tue Feb 22 11:23:32 2011 -0500 +++ b/bin/pkldu.py Tue Feb 22 11:40:02 2011 -0500 @@ -88,6 +88,7 @@ print 'load time: %6.2f %s'%prettyprint(prev_t, time_units, options.human) + print_entries = [] if isinstance(orig_obj, dict): print 'Object is a dictionary' keys = [ key for key in orig_obj.keys() ] @@ -99,10 +100,15 @@ x = cPickle.loads(s) t2 = time.time() new_t = t2 - t1 - print 'field: %40s %6.2f %s ( loads in %6.2f %s)'%( + print_entry = 'field: %40s %6.2f %s ( loads in %6.2f %s)'%( (key_name,) + prettyprint(new_bytes, space_units, options.human) + prettyprint(new_t, time_units, options.human) ) + if options.order is not 'none': + print 'Processed', key_name + print_entries += [(new_bytes, print_entry)] + else: + print print_entry elif isinstance(orig_obj, (tuple, list)): print 'Object is a list/tuple of ', len(orig_obj), 'elements' @@ -113,10 +119,16 @@ x = cPickle.loads(s) t2 = time.time() new_t = t2 - t1 - print 'entry: %03d \t\t\t\t %6.2f %s ( loads in %6.2f %s)' %( + print_entry = 'entry: %03d \t\t\t\t %6.2f %s ( loads in %6.2f %s)' %( (idx,)+ prettyprint(new_bytes, space_units, options.human) + prettyprint(new_t, time_units, options.human) ) + + if options.order is not 'none': + print 'Processed entry number ', idx + print_entries += [(new_bytes, print_entry)] + else: + print print_entry else: print 'Object is a '+str(type(orig_obj)) for field in dir(orig_obj): @@ -131,12 +143,28 @@ x = cPickle.loads(s) t2 = time.time() new_t = t2 - t1 - print 'field: %40s %6.2f %s ( loads in %6.2f %s)' %( + print_entry ='field: %40s %6.2f %s ( loads in %6.2f %s)' %( (field_name,)+ prettyprint(new_bytes, space_units, options.human) + prettyprint(new_t, time_units, options.human) ) + + if options.order is not 'none': + print 'Processed field ', field_name + print_entries += [(new_bytes, print_entry)] + else: + print print_entry except: print 'Could not pickle field', field_name + if options.order in ('desc','asc'): + reverse = False + if options.order == 'desc': + reverse = True + print_entries = sorted(print_entries + , key = lambda x:x[0] + , reverse = reverse) + for entry in print_entries: + print entry[1] + def process_options(): @@ -160,6 +188,16 @@ ' fields (i.e. starting with `__`) ' ' should be displayed' ) ) + + + parser.add_option( '-o' + , "--order-fields" + , dest = 'order' + , default= 'none' + , help = (' Order fields acording the their size.' + ' Possible values are {none, desc, asc}') + ) + return parser.parse_args()