old_contents: import sys, pickle
  
  
  def main():
      statistics = pickle.load(file(sys.argv[1]))
  
      if len(sys.argv) == 2:
          print 'Available benchmarks'
          print '\t' + '\n\t'.join(statistics.keys())
          return
  
      statistics = statistics[sys.argv[2]]
  
      if len(sys.argv) == 3:
          print 'Available parameters'
          print '\t' + '\n\t'.join(map(str, statistics.keys()))
          return
  
      statistics = statistics[int(sys.argv[3])]
  
      if len(sys.argv) == 4:
          print 'Available statistics'
          print '\t' + '\n\t'.join([s.name for s in statistics])
          return
  
      for stat in statistics:
          if stat.name == sys.argv[4]:
              samples = statistics[stat]
              break
  
      if len(sys.argv) == 5:
          print 'Samples'
          print '\t' + '\n\t'.join(map(str, samples))
          print 'Commands'
          print '\t' + '\n\t'.join(stat.commands)
          return
  
      getattr(stat, sys.argv[5])(samples)
  
  
new_contents: import sys, pickle
  
  from benchlib import select
  
  def main():
      if len(sys.argv) < 5:
          print 'Usage: %s <datafile> <benchmark name> <parameter value> <metric> [command]' % (sys.argv[0],)
      else:
          stat, samples = select(pickle.load(file(sys.argv[1])), *sys.argv[2:5])
          if len(sys.argv) == 5:
              print 'Samples'
              print '\t' + '\n\t'.join(map(str, samples))
              print 'Commands'
              print '\t' + '\n\t'.join(stat.commands)
          else:
              getattr(stat, sys.argv[5])(samples)
  
  
subject: Use stats.select() instead of re-implementing all of this.