#!/usr/bin/python # KCS header start - do not edit from here to KCS header end # # *** DEVELOPMENT Branch *** # # 'pygen.py' revision 1.2.1 in Project 'SGBU/LogUtility' # File ID: 125427, Project ID: 124769 # KCS File Depth: 2 # Last modified by 'leozhang' at 06/13/12 00:33 # # define pygen_py_rev "1.2.1d" # # KCS header end - do not edit above here to KCS header start # ~~~~~~~~-~~~~~~~~~~-~~~~~~~~~~-~~~~~~~~~~-~~~~~~~~~~-~~~~~~~~ # pygen.py - The general Python utility script entry for autotest to record information to CMRC import sys import os import traceback # make sure our common python libs and modules are in the path sys.path.append(os.path.dirname(sys.argv[0])) import atlogutils from atlogutils import Measurement from atlogutils import TestStep from atlogutils import Limit from atlogutils import Sequence def ShowUsage(): ''' To show usage of this program ''' print('usage: ' + os.path.basename(sys.argv[0]) + ' ') print(' ' + os.path.basename(sys.argv[0]) + ' ') print('') print(' function - meas | step | limit | seque') print(' > meas - to record the measurement data to CMRC') print(' > step - to record test step data to CMRC') print(' > limit - to update limit in CPP database') print(' > seque - to update sequence in CPP database') print(' options_file - the file which contains options for the function') print(' the options must be a string organized by key=value pairs separated by ";"') print(' run "' + os.path.basename(sys.argv[0]) + ' " to see more detail arguments information') print(' records_file - the file which contains records for the function') print(' each records must be a string organized by key=value pairs separated by ";"') print(' multi record is separated by "||"') print(' run "' + os.path.basename(sys.argv[0]) + ' " to see more detail arguments information') print('') return def ShowHelpMeas(): ''' show detail information for measurement function ''' print('Detail arguments information for Measurement function') print('options:') print(' > sernum - required. The serial number used to record the measurement data') print(' > uuttype - required. The uuttype of the test') print(' > area - required. The test area') print(' > cell - required. The test cell') print(' > timeid - required. Must be a unix time, in numeric format (like autotest time_num). If not valid, program will use local machine time') print(' This item is used for CMRC to link TST record and Meas record, the value must be the same as TST.majline') print(' > uniqid - optional. numeric between 0 and 20000, if not appear or invalid, program will generate a random value between 1000 and 20000') print(' This is the base uqique id for program to calc ids for different measurement records') print(' > instid - optional. Must be a valid UUID in format {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}. This item is used to link the measurement') print(' data with test step data, if not provided, will use a ZERO') print('records: This function can record multi measurement data to CMRC, each measurement data are separated by "||"') print(' > limitid - required. Must be a valid UUID in format {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}') print(' > limittype - required. Must be one of S (string limit) / N (numeric limit) / B (binary limit)') print(' > value - optional. The value of the measurement data. Default value ""') print(' > passfail - optional. The result of the measurement data. Can be P/F/S. Default value Default "S" (for saved)') print(' > units - optional. Used when the measurement data did not link to a real limit') print(' > msg - optional. The message want to display on CMRC') print(' > loopnumber- optional. Defaule value 1') print(' > limitname - optional. Used when the measurement data did not link to a real limit') print(' > limitrev - optional. Default value 1. Used when the measurement data did not link to a real limit') print(' > filepath - optional. Used when the measurement data is a binary file') print('') return def ShowHelpStep(): ''' show detail information for TestStep function ''' print('Detail arguments information for TestStep function') print('options:') print(' > sernum - required. The serial number used to record the test step data') print(' > uuttype - required. The uuttype of the test') print(' > area - required. The test area') print(' > cell - required. The test cell') print(' > timeid - required. Must be a unix time, in numeric format (like autotest time_num). If not valid, program will use local machine time') print(' This item is used for CMRC to link TST record and test step record, the value must be the same as TST.majline') print(' > uniqid - optional. numeric between 0 and 20000, if not appear or invalid, program will generate a random value between 1000 and 20000') print(' This is the base uqique id for program to calc ids for different test step records') print('records: This function can record multi test step data to CMRC, each test step data are separated by "||"') print(' > instid - requried. Must be a valid UUID in format {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}. This item is used to link the test step') print(' data with test step data, if not provided, will use a ZERO') print(' > starttime - requried. Must be a unix time') print(' > endtime - required. Must be a unix time') print(' > passfail - optional. The result of the test step data. Can be P/F/S. Default value Default "S" (for saved)') print(' > msg - optional. The message want to display on CMRC') print(' > loopnumber- optional. Defaule value 1') print('') return def ShowHelpLimit(): ''' show detail information for limit function ''' print('Detail arguments information for Limit function') print('options:') print(' > dept - required. The department name, like Autotest') print(' > deptid - required. The ID for the department. Must be a valid UUID in format {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}') print(' > bu - required. The BU name, like SGBU') print(' > buid - required. The ID for the BU. Must be a valid UUID in format {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}') print(' > prod - required. The prodct name, like Nellis') print(' > prodid - required. The ID for the product. Must be a valid UUID in format {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}') print(' > area - required. The test area name, like PCBST') print(' > areaid - required. The ID for the test area. Must be a valid UUID in format {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}') print(' > listid - reuqired. The ID for the limit list of the product. Must be a valid UUID in format {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}') print(' > limit - reuqired. The limit name, like GPS_RX_FREQ') print(' > limitid - required. The ID for the limit. Must be a valid UUID in format {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}') print(' > limittype - required. The limit type. Must be one of S (string limit) / N (numeric limit) / B (binary limit)') print('records:') print(' > Unit - optional. The unit for the limit. Default value ""') print(' valid values: A, C, Cel, Deg, dB, dBc, dBV, dBm, dBmV, dBuV, F, Fah, H, hr, Hz, K, m, min, ohm, S, sec, T, V, w, Wb') print(' > LimitStr - optional. For string limit only. Default value ""') print(' > Min - optional. For numeric limit only. The min value of the limit. Default value is 0') print(' > Max - optional. For numeric limit only. The max value of the limit. Default value is 0') print('') return def ShowHelpSeque(): ''' show detail information for sequence function ''' print('Detail arguments information for Sequence function') print('options:') print(' > dept - required. The department name, like Autotest') print(' > deptid - required. The ID for the department. Must be a valid UUID in format {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}') print(' > bu - required. The BU name, like SGBU') print(' > buid - required. The ID for the BU. Must be a valid UUID in format {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}') print(' > prod - required. The prodct name, like Nellis') print(' > prodid - required. The ID for the product. Must be a valid UUID in format {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}') print(' > area - required. The test area name, like PCBST') print(' > areaid - required. The ID for the test area. Must be a valid UUID in format {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}') print(' > listid - reuqired. The ID for the sequence list of the product. Must be a valid UUID in format {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}') print(' > seque - reuqired. The sequence name, like Load IOS image') print(' > sequeid - required. The ID for the sequence. Must be a valid UUID in format {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}') print('records: N/A') print('') return helpdict = { 'meas' : ShowHelpMeas, 'step' : ShowHelpStep, 'limit' : ShowHelpLimit, 'seque' : ShowHelpSeque } funcdict = { 'meas' : Measurement, 'step' : TestStep, 'limit' : Limit, 'seque' : Sequence, 'na' : 'na' } ################################################## # Program enterance here if (__name__ == '__main__'): print('The general Python utility script entry for autotest to record information to CMRC, V2.0') # Check command line arguments if ((len(sys.argv) != 2) and ((len(sys.argv) != 4))): ShowUsage() sys.exit(0) funcname = sys.argv[1] if (not funcname in helpdict): ShowUsage() sys.exit(0) if (len(sys.argv) == 2): helpdict[funcname]() sys.exit(0) if (len(sys.argv) == 4): print('') print('argumrnts:') print(sys.argv) print('') retval = 0 try: fin = open(sys.argv[2], "r") options = fin.read() fin.close() print('options:') print(options) print('') fin = open(sys.argv[3], "r") records = fin.read() fin.close() print('records:') print(records) print('') function = funcdict[funcname](options, records) retval = int(function.InvokeUpdate()) except: print('Runtime exception occured during running Python script!') print('Error type : ' + str(sys.exc_info()[0])) print('Error message: ' + str(sys.exc_info()[1])) print('Traceback :') for msg in traceback.format_tb(sys.exc_info()[2]): print(msg) retval = 0 print('Program exit with value ' + str(retval)) sys.exit(retval) # end of program # KCS history start - do not edit from here to KCS history end # ~~~~~~~~-~~~~~~~~~~-~~~~~~~~~~-~~~~~~~~~~-~~~~~~~~~~-~~~~~~~~ # # Revision history for 'pygen.py' in Project 'SGBU/LogUtility' # # *** DEVELOPMENT Branch *** # # 1.2.1 Checked In by 'leozhang' at 06/13/12 00:33 # Update the routine for disply traceback message # # 1.2.0 Released by 'leozhang' at 03/27/12 23:40 # Add log test step to CMRC # # 1.1.1 Checked In by 'leozhang' at 03/27/12 23:29 # Add log test step to CMRC # # 1.1.0 Released by 'leozhang' at 03/14/12 03:56 # Init sync up # # 1.0.1 Checked In by 'leozhang' at 03/14/12 03:34 # update atlogutils lib package structure # # 1.0.0 Released by 'leozhang' at 03/06/12 01:41 # Init sync # # 0.0.2 Checked In by 'leozhang' at 03/06/12 01:40 # Init check in # # 0.0.1 Checked In by 'leozhang' at 03/02/12 21:35 # The general Python utility script entry for autote # st to record information to CMRC # # 0.0.0 Created by 'leozhang' at 03/02/12 21:35 # The general Python utility script entry for autote # st to record information to CMRC # # KCS history end - do not edit above here to KCS history start