Examples - enumerate.py
Jump to navigation
Jump to search
Enumerate Data for LoadRunner Parameter Data
#!/usr/bin/env python # # $Id:$ # #------------------------------------------------------------------------------- """ Transform CSV data to generate LoadRunner parameter files """ import os import csv import sys import getopt import random import datetime #--------------------------------------------------------------------- debug_flg = False max_flg = False random_flg = False verbose_flg = False __version__ = '1.0.0' source_data = 'orig.csv' #----- Read in source data for transformation ------------------------ def transform(): rows = [] csv_in = open(source_data, "rb") out = open('new.csv', "w+") reader = csv.reader(csv_in) cnt = 0 current_dc = None n = 0 for row in reader: cnt += 1 if (cnt == 1): n = int(row[3]) else: n += 1 print '%s,%s,%s,%d' % (row[0], row[1], row[2], n) csv_in.close() # Explicitly close the file *NOW* #------------------------------------------------------------------------------- USAGE = """\ Usage: $ ./enumerate.py [-d] [-v] [-f <filename>] """ def usage(): sys.stderr.write(USAGE) #------------------------------------------------------------------------------- def main(argv): global debug_flg global verbose_flg global file #----- Process command line arguments ---------------------------- try: opts, args = getopt.getopt(argv, "df:hv", ["debug", "file=", "help", "verbose"]) except getopt.GetoptError: usage() sys.exit(2) else: for opt, arg in opts: if opt in ("-d", "--debug"): debug_flg = True elif opt in ("-f", "--file"): logfile = arg elif opt in ("-h", "--help"): usage() sys.exit(0) elif opt in ("-v", "--verbose"): verbose_flg = True transform() #------------------------------------------------------------------------------- if __name__ == "__main__": main(sys.argv[1:]) #-------------------------------------------------------------------------------