#!/usr/bin/env python ############################################### ## ## ## This is a module for *terms tables ## ## related functions for the ## ## web interface to the trigger database ## ## using the trigger dbserver ## ## E.Gallas/R.Wellner Jan 2001 ## ## ## ## These routines apply specifically to Trigger Terms ## Report, Insert, Update, and Delete ## ## MVI: jul 7th,05: when search by OBJECT, do not use the ## instatCurr filled in the form ## since that is meant for the terms; so use all ## Standard/built-in modules. import sys, os, string, time, cgi, whrandom, re ## I need this for FormContent from cgi import * ## import my local modules to help report other import errors from trigdb_aux import * ## I need the trigdb_objects.py function objects_report to make a menu of ## objects from which to choose to make a term from trigdb_objects import * ## ############################################################################### def terms_menu(): "This routine generates the menu for Run II trigger database terms" display_header('Trigger Terms','terms_readmenu') print '' print '' print '' print '
' print 'Choose the action to perform:' form = FormContent() ## get the user if form.has_key("dbname"): dbname = form["dbname"][0] ## display actions specific to this user for this element type error_list = display_sec_menu('TERMS',dbname) if error_list!=[]: display_error(error_list) print '
' display_footer() return print '' ## entry of level and tool/filter print """ Choose the trigger term level/type
for the current entry/report: """ for level in OBJECT_LEVEL_ORDER: if level=='l1' or level=='l2f' or level=='l3f': print '' else: print '
' print '' + OBJECT_LEVELS[level] print '' print '
' + OBJECT_LEVELS[level] if level=='l1': print '
' ## allow entry of a reference element print """ You may reference an existing TERM (the "%" symbol for a wildcard may work):
Term Name: Version: """ ## extra section for terms by reference object print """ TERMS are always based on an OBJECT definition.
So alternatively, should the search by reference TERM fail, you may search by reference OBJECT
(the "%" symbol for a wildcard may work): OBJECT NAME CVS_PACKAGE
(ignored at L1) VERSION""" print 'With STATUS:' print '' display_statcurr_menu(['all']) print '' print '' print """


Report_Format:

""" htopic = 'enterterm' helpme = """Click here for additional help with: """ + \ TDB_Report_Link('helpme',[htopic],HELPDICT_HEADERS[htopic]) print """
  • Definition: A trigger TERM definition is based on a specific trigger OBJECT with values assigned to each of that OBJECT's parameters (an instance of the object).
  • Trigger TERMs and their parameter values are defined (via INSERT), modified (UPDATE), deleted (DELETE) and reported (REPORT) via this menu.
  • If the reference TERM or OBJECT is incomplete, a list of candidate TERM/OBJECTs will be presented which have a status among the STATUS boxes selected.
  • UPDATE means modifying an existing TERM, INSERT means making a new version of an TERM (copying the reference TERM as a starting point).
  • """ + helpme + """
""" display_footer() return ## ############################################################################### def terms_report(tlevel,one_term,elefmt='long'): "This routine prints the (tlevel) trigger term (one_term) and its parameters" ## get/print the term information try: tName = one_term.tName tVersion = one_term.tVersion statCurr = one_term.statCurr statUsed = one_term.statUsed history = one_term.history num_tValues = len(one_term.tValues) cdate = one_term.createDate cuser = one_term.createUser mdate = one_term.modifyDate muser = one_term.modifyUser except: print 'Error reporting on term ' emsg = 'Error reporting on term ' display_exc(emsg,sys.exc_info()) return ## compose direct link to the tdb_report_element interface for this element linkel = TDB_Report_Link('%sTerm'%tlevel,[tName,tVersion]) print '
' % \ ('%',get_stat_color(statCurr)) ## print the 'list' elefmt result, then exit: if elefmt=='list': print_data('name',linkel) print '
' return ## print the element identification print '' if num_tValues==0: print '?? unknown type ' elif tlevel=='l1': print 'Level 1' else: objType = one_term.tValues[0].objType print OBJECT_LEVELS[tlevel] print ' Term Name/Version='; print_data('t_name',linkel) print ', Use_Status='; print_data('stat_used',statUsed) print ', Current_Status='; print_data('stat_curr',statCurr) print 'Created' if muser: print '(Modified)' print ' by '; print_data('cuser',string.capitalize(cuser)) if muser: if muser!=cuser: print_data('muser','('+string.capitalize(muser)+')'); print ' on '; print_data('user',cdate[:16]) if mdate: print_data('user','('+mdate[:16]+')'); ## get/print the parameters if num_tValues==0: print '' print '
This TERM definition is incomplete. ' print 'No OBJECT(s) found.' print '
' return ## get the object name, cvs_package and version name0 = one_term.tValues[0].name cvsPackage0 = one_term.tValues[0].cvsPackage version0 = one_term.tValues[0].version ## print the object identification the term is based on print '
is based on the ' + OBJECT_LEVELS[tlevel] ## compose direct link to the tdb_report_element interface for this trigger list linkname = name0 + ' / ' + version0 if tlevel!='l1': linkname = linkname + ' / ' + cvsPackage0 linkel = TDB_Report_Link('%s_Object'%tlevel,[name0,version0,cvsPackage0],linkname) print ' Object Name / Version ' if tlevel!='l1': print '/ CVS Pkg ' print '=' print_data('name',linkel) if elefmt!='brief' and history: print '
Description: '; print_data('history',history); print '' ## I might need this if there are exceptions printit = tlevel + ' Object (' + name0 if tlevel!='l1': printit = printit + ',' + cvsPackage0 printit = printit + ',' + version0 + ')' ## if this TERM has no parameters, print a message then return if num_tValues==1 and one_term.tValues[0].parName=='none': print '' print '
This term by definition has no parameter/values.' print '
' return if elefmt=='short' or elefmt=='brief': return ## Connect to the CORBA service. server,servant = connect_server() ## get the object definition trig_objs = [] try: trig_objs = servant.GetTObjects(tlevel,name0,cvsPackage0,version0,[]) except: emsg = "Terms_report: error on servant.GetTObjects " + printit + '
' display_exc(emsg,sys.exc_info()) display_footer() return if trig_objs==[]: print '
Unable to find base object: ' + printit + ')' print '
Searching for name match ... ' + name0 + '' print '
' try: trig_objs = servant.GetTObjects(tlevel,name0,'','',[]) except: emsg = "Terms_report: error on servant.GetTObjects " + printit + '
' display_exc(emsg,sys.exc_info()) display_footer() return if trig_objs==[]: print '
No match found !!! This is a serious error !! Please report it !' display_footer() return ## get the leading element returned one_objs = trig_objs[0] ## put object parameters into a dictionary num_params = len(one_objs.params) TOBJ_PARS_VAL = FillTOPDict(one_objs,{}) ## Add reference parameter pvValue, pvTermVersion, pvDesc ## to the above dictionary making sure the parameter names match anydes = 'no' if one_term!=[]: ## loop over parameters with values for tValues in one_term.tValues: ## loop over all parameters, searching for a par_name match to get the par_order for params in one_objs.params: key = 'name' + str(params.order) if TOBJ_PARS_VAL[key]==tValues.parName: TOBJ_PARS_VAL['pvValue'+str(params.order)] = tValues.pvValue TOBJ_PARS_VAL['pvTermVersion'+str(params.order)] = tValues.pvTermVersion TOBJ_PARS_VAL['pvDesc'+str(params.order)] = tValues.pvDesc ## if there are no pvDesc, then don't print the column in the table later if tValues.pvDesc!='': anydes = 'yes' ## loop over parameters to find any of type 'refset', 'tool' or 'filter' ## which require lookups of available refsets, tools and filters. ## If any are found, append the found type values to the lookups list lookups = [] ## if there are no default values, then don't print the column in the table anydef = 'no' for ipar in xrange(1,num_params+1): if not TOBJ_PARS_VAL.has_key('type'+str(ipar)): print '
terms_report: key error on key "' print 'type' + str(ipar) + '"' print '
This report stream has been terminated abnormally.' print '
Please report the TERM at which this error occurred by email.
' return if TOBJ_PARS_VAL['type'+str(ipar)]=='tool' \ or TOBJ_PARS_VAL['type'+str(ipar)]=='filter' \ or TOBJ_PARS_VAL['type'+str(ipar)]=='refset': if lookups.count(TOBJ_PARS_VAL['type'+str(ipar)])==0: lookups.append(TOBJ_PARS_VAL['type'+str(ipar)]) if TOBJ_PARS_VAL['defaultValue'+str(ipar)]!='': anydef = 'yes' ## start the parameter values table, skipping pvTermVersion if lookups is empty print '' print '' for ipar in range(4,len(TTERM_VAL_LIST)): if anydef=='no' and TTERM_VAL_LIST[ipar]=='defaultValue': continue if anydes=='no' and TTERM_VAL_LIST[ipar]=='pvDesc': continue if len(lookups)==0 and TTERM_VAL_LIST[ipar]=='pvTermVersion': continue print '' print '' ## parOrder, parName, parType, pvValue, pvTermVersion, pvDesc, parDefault ith_tValues = 0 for iparam in xrange(num_params): ith_tValues = ith_tValues + 1 print '' ## parOrder parOrder = TOBJ_PARS_VAL['order'+str(ith_tValues)] print '' ## parName parName = TOBJ_PARS_VAL['name'+str(ith_tValues)] print '' ## parType parType = TOBJ_PARS_VAL['type'+str(ith_tValues)] print '' ## get the defaultValue key = 'defaultValue'+str(ith_tValues) defaultValue = '' if TOBJ_PARS_VAL.has_key(key): defaultValue = TOBJ_PARS_VAL[key] ## get the pvDesc key = 'pvDesc'+str(ith_tValues) pvDesc = '' if TOBJ_PARS_VAL.has_key(key): pvDesc = TOBJ_PARS_VAL[key] ## get pvValue and pvTermVersion (only if lookups list contains elements) key = 'pvValue'+str(ith_tValues) pvValue = '' if TOBJ_PARS_VAL.has_key(key): pvValue = TOBJ_PARS_VAL[key] if len(lookups)!=0: pvTermVersion = -1 if TOBJ_PARS_VAL.has_key('pvTermVersion'+str(ith_tValues)): pvTermVersion = long(TOBJ_PARS_VAL['pvTermVersion'+str(ith_tValues)]) ## construct the pvValue/version link to tdb_report to the tool,filter,refset dtermCurr = statCurr if pvValue!='' and (parType=='tool' or parType=='filter' or parType=='refset'): value = pvValue plevel = tlevel if string.find(tlevel,'f')!=-1 and parType=='tool': plevel = tlevel[:2] + 't' if string.find(tlevel,'t')!=-1 and parType=='filter': plevel = tlevel[:2] + 'f' link = TDB_Report_Link('%s_Term'%plevel,[pvValue,pvTermVersion],pvValue) if tlevel=='l1': link = TDB_Report_Link('L1Dialog',[pvValue,pvTermVersion],pvValue) pvValue = link try: if tlevel=='l1': temp_terms = servant.GetTL1Dialogs(value,pvTermVersion,0,[]) else: temp_terms = servant.GetTTerms(tlevel[:2],value,pvTermVersion,[]) dtermCurr = temp_terms[0].statCurr except: print sys.exc_info dtermCurr = 'unknown' ## print the pvValue and pvTermVersion if pvValue=='': print '' else: if anydef=='yes' and defaultValue!='' and (pvValue==defaultValue or \ (parType=='float' and float(pvValue)==float(defaultValue)) or \ (parType=='int' and int(pvValue)==int(defaultValue))): print '' else: print '' if len(lookups)!=0: if parType=='tool' or parType=='filter' or parType=='refset': print '' else: print '' ## pvDesc if anydes=='yes': if TOBJ_PARS_VAL.has_key('pvDesc'+str(ith_tValues)): pvDesc = TOBJ_PARS_VAL['pvDesc'+str(ith_tValues)] if pvDesc=='': print '' else: print '' ## defaultValue if anydef=='yes': defaultValue = TOBJ_PARS_VAL['defaultValue'+str(ith_tValues)] if defaultValue=='': print '' else: print '' print '' print '
' if ipar==7 or ipar==8: print '' + TTERM_VAL_NAMES[TTERM_VAL_LIST[ipar]] + '' else: print TTERM_VAL_NAMES[TTERM_VAL_LIST[ipar]] print '
' + parOrder + '' + parName + '' + parType + 'missing !' + pvValue + '' + pvValue + '' + str(pvTermVersion) + '' + ' - ' + '-' + pvDesc + '-' + defaultValue + '
' # # L2pp # if tlevel[:2]=='l2': l2pps = servant.GetTL2ppToGss(tName,tVersion,'','','') if len(l2pps) > 0: print """

This Level 2 Global Term instance requires the following L2 preprocesor(s): """ for al2pp in l2pps: this_l2pps = servant.GetTTL2Pps(al2pp.ppName,al2pp.ppVersion,\ al2pp.ppCvsPackage,[]) listel = [al2pp.ppName,al2pp.ppVersion,al2pp.ppCvsPackage] linkel = TDB_Report_Link('L2PP',listel) print '' % \ (get_stat_color(this_l2pps[0].statCurr),linkel) print "
Preprocessor Name / Version / CVS Package
%s
" return ## ############################################################################### def FillTTVDict(TTV,TOBJ_PARS_VAL={}): "Fill the Dictionary with keys and values based on the column names" iii = 0 ## loop over the number of parameters ## TOBJ_PARS_VAL = {} for tValues in TTV.tValues: iii = iii + 1 ## object type colName = 'objType' + str(iii) TOBJ_PARS_VAL[colName] = tValues.objType ## name colName = 'name' + str(iii) TOBJ_PARS_VAL[colName] = tValues.name ## cvs_package colName = 'cvsPackage' + str(iii) TOBJ_PARS_VAL[colName] = tValues.cvsPackage ## version colName = 'version' + str(iii) TOBJ_PARS_VAL[colName] = tValues.version ## parName colName = 'parName' + str(iii) TOBJ_PARS_VAL[colName] = tValues.parName ## pvValue colName = 'pvValue' + str(iii) TOBJ_PARS_VAL[colName] = tValues.pvValue ## pvTermVersion colName = 'pvTermVersion' + str(iii) TOBJ_PARS_VAL[colName] = tValues.pvTermVersion ## pvDesc colName = 'pvDesc' + str(iii) TOBJ_PARS_VAL[colName] = tValues.pvDesc return TOBJ_PARS_VAL ## ############################################################################### def terms_readmenu(): """This routine reads the user input from the terms_menu term_uid obj_uid action ----------- ------- -------------------------------------- blank blank only works for report non-% entry blank gives list of all terms matching entry '%' entry entry gives list of terms using objects matching entry blank entry gives list of objects matching entry to insert new term entry entry object entry is ignored unless no terms are found """ ## Connect to the CORBA service. server,servant = connect_server() ## initialize the uid tName = ''; tVersion = 0; name = ''; version = ''; cvsPackage = ''; ## get form content form = FormContent() if form.has_key("tlevel") and form.has_key("taction"): tlevel = form["tlevel"][0] taction = form["taction"][0] else: display_error('terms_readmenu: incomplete input') if form.has_key("name"): name = spacestripfirst(form["name"][0]) if form.has_key("cvsPackage"): cvsPackage = spacestripfirst(form["cvsPackage"][0]) if form.has_key("version"): version = spacestripfirst(form["version"][0]) if form.has_key("tName"): tName = spacestripfirst(form["tName"][0]) try: if form.has_key("tVersion"): tVersion = int(form["tVersion"][0]) except: display_error('terms_readmenu: illegal version input') ## get the list of input status instatCurr,instatForm = read_statcurr_menu(form) ## the elefmt determines the length of the triggername report if form.has_key("elefmt"): elefmt = form["elefmt"][0] else: elefmt = 'long' ##old ## remove all spaces from sName ##old tName = re.sub(" ","",tName) ##old name = re.sub(" ","",name) ##old cvsPackage = re.sub(" ","",cvsPackage) ##old version = re.sub(" ","",version) ##old ## check all information on the input form for double quotes ##old emsg = '' ##old for aString in [tlevel,taction,name,cvsPackage,version,tName]: ##old if string.find(aString,'"')!=-1: ##old emsg = "Double quotes not allowed in the input string '%s'" % \ ##old (aString) ##old display_error(emsg) ##old display_footer() ##old return ## initialize the UID input and some other things ## num_objs = number of objects found matching the input criteria object_uids = [name,cvsPackage,version] trig_objs = [] num_objs = 0 term_uids = [tName,str(tVersion)] trig_terms = [] num_elements = 0 slevel = tlevel[:2] ## on INSERT, UPDATE and DELETE, a reference term or object is required if taction!='REPORT' and term_uids==['','0'] and object_uids==['','','']: emsg = 'Go BACK. A reference TERM or reference OBJECT is required to ' emsg = emsg + taction + ' a TERM definition.' display_error(emsg) ## get the terms matching the input criteria ## first, try to get the TERMS by reference TERM temp_terms = [] ## if ref term, search for terms first by term, if fail: then by object ## if no ref term, search for term only if no ref object if term_uids!=['','0'] or \ (term_uids==['','0'] and object_uids==['','','']): ## if term_uids!=['','0'] or taction=='REPORT' \ ## or (term_uids==['%','0'] and object_uids!=['','','']): try: temp_terms = servant.GetTTerms(slevel,tName,tVersion,instatCurr) except: display_header('GetTTerms ERROR','Main_Menu') emsg = "terms_readmenu: error on servant.GetTTerms(" emsg = emsg + tlevel + ',' + tName + ',' + str(tVersion) + ')
' display_exc(emsg,sys.exc_info()) display_footer() return ## remove temp_terms which correspond to the wrong type of objects: if tlevel!='l1': for term in temp_terms: ## make sure that this is a complete TERM definition num_tValues = len(term.tValues) if num_tValues==0: ## display_header('TERM error found','Main_Menu') ## print 'You have touched on a database data inconsistency.' ## terms_report(tlevel,term) pass else: if string.find(tlevel,'f')!=-1 and term.tValues[0].objType=='tool': pass elif string.find(tlevel,'t')!=-1 and term.tValues[0].objType=='filter': pass else: trig_terms.append(term) else: trig_terms = temp_terms ## get the number of terms returned num_elements = len(trig_terms) ## if no terms found and 'REPORT' and a ref object is input OR ## if no terms found matching input reference and a ref object is input, ## then search for TERMS by reference OBJECT ## MVI: jul 7th,05: when search by OBJECT, do not use the instatCurr filled in the form ## since that is meant for the terms; so use all ##?? - EG notes ##?? - does this enter this loop or not ? ##?? display_header('test','Main_Menu') ##?? print '
num_elements (terms) = %d ' % num_elements ##?? print '
object_uids = %s ' % object_uids ##?? print '
taction = %s ' % taction if (num_elements==0 and taction=='REPORT' and object_uids!=['','','']) \ or (num_elements==0 and object_uids!=['','','']): ##?? or (num_elements==0 and object_uids!=['','',''] and term_uids!=['','0']): ##?? - does this enter this loop or not ? ##?? print 'yes, I am here' temp_terms = [] object = [] try: objects = servant.GetTObjects(\ tlevel,name,cvsPackage,version,[]) ## tlevel,name,cvsPackage,version,instatCurr) for object in objects: ##?? if object.level!=tlevel: display_header('trigdb_terms: GetTObjects returning %s objects as %s'%\ (object.level,tlevel),'Main_Menu') terms = servant.GetTTermsByObject(object) #Before append, make sure we select on the correct instantCurr from the form for term in terms: temp_term_stat = term.statCurr if instatCurr != []: if temp_term_stat in instatCurr: temp_terms.append(term) else: temp_terms.append(term) except: display_header('GetTTermsByObject ERROR','Main_Menu') print "terms_readmenu: error on servant.GetTTermsByObject at level " print tlevel + '
for Object UID = ' print object_uids display_exc('',sys.exc_info()) display_footer() return ## remove temp_terms which correspond to the wrong type of objects: if tlevel!='l1': for term in temp_terms: ## make sure that this is a complete TERM definition num_tValues = len(term.tValues) if num_tValues==0: ## display_header('TERM error found','Main_Menu') ## print 'You have touched on a database data inconsistency.' ## terms_report(tlevel,term) pass else: if string.find(tlevel,'f')!=-1 and term.tValues[0].objType=='tool': pass elif string.find(tlevel,'t')!=-1 and term.tValues[0].objType=='filter': pass else: trig_terms.append(term) # Level 1 now else: trig_terms = temp_terms ## revise the number of terms returned num_elements = len(trig_terms) ##old try: ##old trig_objects = servant.GetTObjects(tlevel,name,cvsPackage,version,[]) ##old for objects in trig_objects: ##old if tlevel=='l1' \ ##old or (string.find(tlevel,'f')!=-1 and string.find(objects.level,'f')!=-1) \ ##old or (string.find(tlevel,'t')!=-1 and string.find(objects.level,'t')!=-1): ##old object = TriggerDbServer.TObjectStruct(tlevel,objects.name,objects.cvsPackage,objects.version,'','','','',[]) ##old temp_terms = servant.GetTTermsByObject(objects) ##old for terms in temp_terms: ##old trig_terms.append(terms) ##old ##old object = TriggerDbServer.TObjectStruct(tlevel,name,cvsPackage,version,'','','','',[]) ##old temp_terms = servant.GetTTermsByObject(object) ##old trigger = TriggerDbServer.TObjectStruct('l3f','L3FEle','dummy_package','v00-00-00','','', '','',[]) ##old trigger = TriggerDbServer.TObjectStruct('l3f','L3FEle','','v00-00-00','','', '','',[]) ##old temp_terms = servant.GetTTermsByObject(trigger) ##old trig_terms = temp_terms ## if REPORT, then report the results then exit if taction=='REPORT': title = 'REPORT: ' + OBJECT_LEVELS[tlevel] + ' Terms: Parameters and Values' display_header(title,'Main_Menu') if num_elements==0: emsg = """No %s TERM(s) matched the input criteria = %s
""" % (OBJECT_LEVELS[tlevel],str(term_uids)) print emsg else: print 'The following %d %s TERM(s) matched the input criteria = %s,%s
'\ % (num_elements,OBJECT_LEVELS[tlevel],str(term_uids),str(object_uids)) if instatCurr!=[]: print 'You selected elements with Current Status among: %s.
' % \ str(instatCurr) if form.has_key("elefmt"): print 'Report format = %s
' % elefmt for terms in trig_terms: ##old if elefmt!='long': print '

' terms_report(tlevel,terms,elefmt) ##old if elefmt=='long': print '


' display_colormap() display_footer() return ## MVI: jul 7th,05: when search by OBJECT, do not use the instatCurr filled in the form ## since that is meant for the terms; so use all ## Get the objects matching the input criteria if num_elements==0 and object_uids!=['','','']: try: trig_objs = servant.GetTObjects(tlevel,name,cvsPackage,version,[]) ## trig_objs = servant.GetTObjects(tlevel,name,cvsPackage,version,instatCurr) ## get the number of objects returned num_objs = len(trig_objs) except: display_header('GetTObjects ERROR','Main_Menu') emsg = "terms_readmenu: error on servant.GetTObjects(" emsg = emsg + tlevel + ',' + name + ',' + cvsPackage + ',' + version + ')' display_exc(emsg,sys.exc_info()) display_footer() return ## MVI :this is in the wrong spot, move up... ## get the number of objects returned ## num_objs = len(trig_objs) ## no TERM or OBJECT found - display error message and return if num_elements==0 and num_objs==0: emsg = """No %s TERM(s) or OBJECT(s) matched the input criteria = %s,%s
""" % (OBJECT_LEVELS[tlevel],str(term_uids),str(object_uids)) display_error(emsg) return title = taction + ': ' + OBJECT_LEVELS[tlevel] + ' Terms' ## if no TERM found, must have a TERM for UPDATE/DELETE ## if one OBJECT found, use that to INSERT for INSERT/UPDATE ## if more than one object, go to INSERT choice menu if num_elements==0 and num_objs==0: ## if DELETE, then print error message and return if taction=='DELETE': display_header(title,'Main_Menu') print 'No ' + OBJECT_LEVELS[tlevel] print ' TERM(s) found matching input criteria:
' display_footer() return if num_elements==0: ## INSERT/UPDATE w/ exactly one object found, go into INSERT mode to insert a new term using it if num_objs==1: taction = 'INSERT' terms_change(taction,tlevel,[],trig_objs[0]) return ## UPDATE failed - no term to update found elif taction=='UPDATE' and num_objs==0: display_header(title,'Main_Menu') print 'No ' + OBJECT_LEVELS[tlevel] print ' TERM(s) found matching input criteria:
' display_footer() return ## one TERM found ## UPDATE/INSERT using found term if (taction=='UPDATE' or taction=='INSERT') and num_elements==1: ## if INSERT look to see if there is a distinct reference object ## which could be different from the term being copied for the INSERT if object_uids!=['','','']: try: trig_objs = servant.GetTObjects(tlevel,name,cvsPackage,version,instatCurr) num_objs = len(trig_objs) except: display_header('GetTObjects ERROR','Main_Menu') emsg = "terms_readmenu: error on servant.GetTObjects(" emsg = emsg + tlevel + ',' + name + ',' + cvsPackage + ',' + version + ')' display_exc(emsg,sys.exc_info()) display_footer() return if num_objs==1: terms_change(taction,tlevel,trig_terms[0],trig_objs[0]) else: terms_change(taction,tlevel,trig_terms[0],[]) else: terms_change(taction,tlevel,trig_terms[0],[]) return ## what we should have left is ## more than one terms found for insert, update or delete or ## no terms but more than 1 object found for insert of term #################################################### list of action / objects ## if DELETE, a checkbox menu is presented ## if INSERT or UPDATE - a menu of submit buttons if taction=='DELETE': input_type=' for Object UID = ' print object_uids display_exc('',sys.exc_info()) display_footer() return else: print '

no objects or terms found matching the input criteria
' display_footer() return ####============= End of new update sectiong ===================== ## print the header, put tlevel, taction, instatCurr, number of elements on the form display_header(title,'terms_change') print '' print '' print '' print '' print '' ## if DELETE or more than one matching elements found (INSERT/UPDATE), ## present a radio/checkbox menu of matching items from which the user can choose ## Allow DELETE or UPDATE only for TERMS with stat_used=='unused' ####================================================================== if num_elements==0 and num_objs==0: ## if num_elements==0: print 'No ' + OBJECT_LEVELS[tlevel] print ' TERM(s) matched the input criteria:
' if num_objs!=0: ## write the table for INSERT based on OBJECTS print '

  • Click on the INSERT button corresponding to the OBJECT ' print 'you wish to use to create a new TERM.
' print '' print '' iobject = 0 for objects in trig_objs: iobject = iobject + 1 print '' print '' print '' print '' print '
' print 'Check here to ' + taction + '
a new TERM
based on this OBJECT
' print input_type + ' name="INSERT' + str(iobject) + '" ' print 'value="INSERT">' print '' objects_report(tlevel,objects,elefmt) print '
' else: ## write the table for INSERT/UPDATE/DELETE based on TERMS if num_objs!=0: print 'Searching for terms based on the %d OBJECT(s) found matching the input criteria

' %num_objs print 'The following %d %s TERM(s) matched the input criteria.
' % \ (num_elements,OBJECT_LEVELS[tlevel]) if instatCurr!=[]: print 'You selected elements with Current Status among: %s.
' % \ str(instatCurr) if form.has_key("elefmt"): print 'Report format = %s
' % elefmt ## print some instructions if taction=='DELETE': print '

  • All Terms with the DELETE box checked will be deleted.' print '
  • Do not click on the SUBMIT button (below) if you are unsure.' elif taction=='INSERT': print '
    • Click on the INSERT button corresponding to the TERM ' print 'you wish to use (copy) to create a new TERM.
    ' else: print '
    • Click on the UPDATE button corresponding to the TERM ' print 'you wish to modify.' if taction!='INSERT': print '
    • A Status = KEEP ' print 'indicates the TERM is not a candidate for ' if taction=='DELETE': print 'deletion.
    ' if taction=='UPDATE': print 'modification.
' ## start the table print '' iterm = 0 printsubmit = 'no' for terms in trig_terms: iterm = iterm + 1 print '' print '' print '' print '
' print 'Check here
to ' + taction + '
TERM Description
' if ((taction=='UPDATE' or taction=='DELETE') \ and terms.statUsed=='unused') or taction=='INSERT': print input_type + ' name="'+ taction + str(iterm) + '" ' print 'value="' + taction + '">' if taction=='DELETE': printsubmit = 'yes' print 'DELETE' else: print 'KEEP' print '' terms_report(tlevel,terms,elefmt) print '
' ## a SUBMIT button is needed for DELETE if there are one/more candidates if taction=='DELETE' and printsubmit=='yes': print '
' print '' print '' print '
  • All TERMs with the DELETE ' print 'box checked will be deleted.' print '
  • Do not SUBMIT if you are unsure.' print '
  • A Status = KEEP ' print 'indicates the TERM is not a candidate for deletion.' print '
' print '
' display_colormap() display_footer() return ## ############################################################################### def terms_change(action='dummy',level='dummy',one_term=[],one_objs=[]): """execute the action (INSERT, UPDATE, or DELETE) on the input term or object or read the radio menu to execute the delete or use the right reference term for INSERT or UPDATE""" ## Connect to the CORBA service. server,servant = connect_server() ## initialize the uid tName = ''; tVersion = 0; name = ''; version = ''; cvsPackage = '' ## no matter what, I still need the instatCurr form = FormContent() instatCurr,instatForm = read_statcurr_menu(form) ## see it there is a non-dummy action (input from form, not from another function): if action=='dummy': ## get form content from the INSERT, UPDATE or DELETE term menu form = FormContent() if form.has_key("tlevel") and form.has_key("taction") \ and form.has_key("num_objs") and form.has_key("num_elements"): tlevel = form["tlevel"][0] taction = form["taction"][0] num_elements = int(form["num_elements"][0]) num_objs = int(form["num_objs"][0]) else: display_error('terms_change: incomplete input',sys.exc_info()) ## the form tells you to dowhatelement to whichelement dowhatelement = {} whichelement = {} slevel = tlevel[:2] for iterm in range(1,num_elements+1): try: key = taction + str(iterm) if form.has_key(key): dowhatelement[key] = form[key][0] else: dowhatelement[key] = 'keep' ktName = 'tName' + str(iterm) if form.has_key(ktName): whichelement[ktName] = form[ktName][0] ktVersion = 'tVersion' + str(iterm) if form.has_key(ktVersion): whichelement[ktVersion] = form[ktVersion][0] except: display_error('terms_change: incomplete term input',sys.exc_info()) if num_elements==0: for iobj in range(1,num_objs+1): try: key = taction + str(iobj) if form.has_key(key): dowhatelement[key] = form[key][0] else: dowhatelement[key] = 'keep' kname = 'name' + str(iobj) if form.has_key(kname): whichelement[kname] = form[kname][0] kcvsPackage = 'cvsPackage' + str(iobj) if tlevel!='l1' and form.has_key(kcvsPackage): whichelement[kcvsPackage] = form[kcvsPackage][0] else: whichelement[kcvsPackage] = '' kversion = 'version' + str(iobj) if form.has_key(kversion): whichelement[kversion] = form[kversion][0] except: display_error('terms_change: incomplete object input',sys.exc_info()) ## take care of INSERT TERM by OBJECT if taction!='DELETE' and num_elements==0 and num_objs!=0: one_objs = [] for iobj in range(1,num_objs+1): key = taction + str(iobj) kname = 'name' + str(iobj) kcvsPackage = 'cvsPackage' + str(iobj) kversion = 'version' + str(iobj) if dowhatelement[key]==taction: name = whichelement[kname] cvsPackage = whichelement[kcvsPackage] version = whichelement[kversion] try: trig_objs = servant.GetTObjects(tlevel,name,cvsPackage,version,[]) except: display_header('GetTObjects ERROR','Main_Menu') emsg = "terms_change: unable to Get reference object using GetTObjects(" emsg = emsg + tlevel + ',' + name + ',' + cvsPackage + ',' + version + ')' display_exc(emsg,sys.exc_info()) display_footer() return one_objs = trig_objs[0] taction = 'INSERT' if one_objs==[]: display_header('terms_change: unable to Get reference object','Main_Menu') display_exc(emsg,sys.exc_info()) display_footer() return break ## take care of DELETE's right here elif taction=="DELETE": display_header('Trigger Term Deletion Report','Main_Menu') ## get the dbname dbname = 'anonymous' if form.has_key("dbname"): dbname = form["dbname"][0] if dbname=='anonymous': display_fatal('Improper identification') return ## loop over number of terms, deleting as we go for iterm in range(1,num_elements+1): key = 'DELETE' + str(iterm) ktName = 'tName' + str(iterm) ktVersion = 'tVersion' + str(iterm) tName = whichelement[ktName] tVersion = int(whichelement[ktVersion]) printit = tlevel + ' TERM (' + tName + ',' + str(tVersion) + ')' ## if request is to delete if dowhatelement[key]=='DELETE': ## re-Get the element to delete try: trig_term = servant.GetTTerms(slevel,tName,tVersion,[]) except: emsg = "terms_change: error on servant.GetTTerms " emsg = emsg + printit + '
' display_exc(emsg,sys.exc_info()) display_footer() return ## if a distinct element not found, don't delete if len(trig_term)!=1: print '

A unique match was not found for ' print printit + '
' ## if unused -- delete it !! elif trig_term[0].statUsed=='unused': print '

The following ' + printit print ' TERM is being deleted:
' terms_report(tlevel,trig_term[0]) try: servant.DelTTerm(trig_term[0]) except: emsg = "Terms_change: error on servant.DeleteTTerm " emsg = emsg + printit + '
' display_exc(emsg,sys.exc_info()) display_footer() return ## if that term is used, don't delete else: print '
' + printit print ' is no longer a candidate for deletion.
' terms_report(tlevel,trig_term[0]) print '


' display_colormap() ## else -- no request to delete else: print '
' + printit + ' remains unaltered.' ## for term in trig_term: ## terms_report(tlevel,term) display_footer() return ## for INSERT and UPDATE, just get the TERM (one_term) involved else: title = taction + ': ' + OBJECT_LEVELS[tlevel] + ' Terms: Parameters and Values' for iterm in range(1,num_elements+1): key = taction + str(iterm) ktName = 'tName' + str(iterm) ktVersion = 'tVersion' + str(iterm) if dowhatelement[key]==taction: tName = whichelement[ktName] tVersion = int(whichelement[ktVersion]) printit = tlevel + ' TERM (' + tName + ',' + str(tVersion) + ')' try: trig_term = servant.GetTTerms(slevel,tName,tVersion,[]) except: display_header('GetTTerms ERROR','Main_Menu') emsg = "terms_change: error on servant.GetTTerms" emsg = emsg + printit + '
' display_exc(emsg,sys.exc_info()) display_footer() return ##?? may be extraneous: this should never be > 1 if len(trig_term)>1: display_header(title,'Main_Menu') print '
' print 'The database record for ' + printit + ' has been altered.
' print 'The database must have been altered since the last query
' for terms in trig_term: terms_report(tlevel,terms) print '
' display_colormap() display_footer() return ## case of another user who deletes the TERM elif len(trig_term)==0: display_header(title,'Main_Menu') print '
' print 'The database record for ' + printit + ' has been deleted.
' print 'The database must have been altered since the last query
' display_footer() return ## case of another user who uses the TERM in a script, so now no modification allowed else: if trig_term[0].statUsed!='unused' and taction=='UPDATE': display_header(title,'Main_Menu') print '
This ' + printit print ' is no longer a candidate for modification.
' terms_report(tlevel,trig_term[0]) print '
' display_colormap() display_footer() return ## ELEMENT is found and is a candidate for insert or modification else: one_term = trig_term[0] break ## simpler case: action, tlevel and element to be used is passed by function argument else: taction = action tlevel = level ##?? if one_objs!=[]: if one_term==[] and one_objs!=[]: taction = 'INSERT' if taction=='UPDATE' and one_term.statUsed!='unused': title = 'Trigger Name Definition' display_header(title,'Main_Menu') print '
This Trigger Term ' print ' is not a candidate for modification.
' terms_report(tlevel,one_term) ##!! this is not really fatal, should I just let them insert a new term ? print '
' print 'Once a Term has been used in a Trigger Script, it cannot be modified.' print '
If you need a new different Trigger Term, go back to create (INSERT) a new one.' print '

' display_colormap() display_footer() return ## print the header title = taction + ': ' + OBJECT_LEVELS[tlevel] + ' Terms and Values' display_header(title,'terms_readchange') ## put the tlevel, taction, instatCurr on the form print '' print '' print '' ## from here, I must have either one_term or one_objs to base a new TERM on ## initialize form values with defaults, overwrite if reference term exists slevel = tlevel[:2] tName0 = '' tVersion0 = 0 statUsed0 = 'unused' statCurr0 = 'local' history0 = '' ## for distinct reference term and reference object if one_term!=[] and one_objs!=[]: tName0 = one_term.tName tVersion0 = one_term.tVersion statUsed0 = one_term.statUsed statCurr0 = one_term.statCurr history0 = one_term.history name0 = one_objs.name cvsPackage0 = one_objs.cvsPackage version0 = one_objs.version ## for reference term, get reference object elif one_term!=[]: tName0 = one_term.tName tVersion0 = one_term.tVersion statUsed0 = one_term.statUsed statCurr0 = one_term.statCurr history0 = one_term.history name0 = one_term.tValues[0].name cvsPackage0 = one_term.tValues[0].cvsPackage version0 = one_term.tValues[0].version ## if there is just a reference object, get its object uid elif one_objs!=[]: name0 = one_objs.name cvsPackage0 = one_objs.cvsPackage version0 = one_objs.version else: print 'terms_change: Fatal error - no reference term or object' display_footer() return ## Get the reference object, its first parameter and number of parameters try: trig_objs = servant.GetTObjects(tlevel,name0,cvsPackage0,version0,[]) except: display_header('GetTObject ERROR','Main_Menu') emsg = "terms_change: error on servant.GetTObjects " emsg = emsg + printit + '
' display_exc(emsg,sys.exc_info()) display_footer() return one_objs = trig_objs[0] num_params = len(one_objs.params) ## make sure that this term is legitimate (is based on a real object) if num_params<=0: print """terms_change: object definition error !
The OBJECT in question is ill-defined. You must correction the object definition before using it to define a TERM.

""" objects_report(tlevel,one_objs) display_footer() return firstpar = one_objs.params[0].name ## place the lead element uid on the form and its number of parameters print '' print '' print '' ## write the ELEMENT UID, allowing the name to be changed for INSERT ## and UPDATE (in case the autonaming would be different) print '' namesize = 60 if tlevel=='l1': print """""" elif tlevel=='l2f' or tlevel=='l3f': print """""" elif tlevel=='l3t': print """""" namesize = 25 elif tlevel=='l2t': print """""" if taction=='INSERT': ## by default, the term name is determined by the client/server, so leave blank ## print '' print '' print '' print '' print '' print '
Suggestion for TERM Name: Use the automatic naming convention !! Leave the Term Name blank !!
Suggestion for FILTER TERM Name: Use the automatic naming convention !! Leave the Term Name blank !!
For Level 3 TERMs: You must enter a TERM name that conforms to ScriptRunner parsing rules (only alpha, numeric or underscores are allowed in the L3 TOOL TERM name. Shorter names are preferred.).
Suggestion for TERM Name: The automatic naming convention may be used (leave Term Name blank).
If not, be sure to use a naming convention agreed to by the Level 2 group.
Term Name:' print '' % namesize print ', Version:' print ' * ' else: print '
Modifying Term Name:' print ''+tName0+'' print ', Version:' print ''+str(tVersion0)+'
New Term Name:' print '' % namesize print ', Version:' print ' * ' ## write the description box print '
' print 'Description:
' ## print '
' ## write the TERM name and the OBJECT it is based on if tName0!='': termlink = TDB_Report_Link('%s_Term'%slevel,[tName0,tVersion0]) print 'Reference Term ' + \ '' + termlink + '' print ' is based on OBJECT: ' + \ TDB_Report_Link('%s_Object'%tlevel,[one_term.tValues[0].name,\ one_term.tValues[0].version,\ one_term.tValues[0].cvsPackage,tlevel]\ ) + '' ## print the object identification the term is based on and save on the form print '
Current term is based on ' + \ OBJECT_LEVELS[tlevel] + ' OBJECT: ' print TDB_Report_Link('%s_Object'%tlevel,[name0,version0,cvsPackage0,tlevel],\ '%s'%name0) print '' print '' if tlevel!='l1': length = len(cvsPackage0)+2 print ' / ' length = len(version0)+2 print ' / ' ## if the object has no parameters, end the form right here if firstpar=='none': print '' print '
This term by definition has no parameter/values.

' print '
' print '' print '' print '
  • This TERM needs no parameter values.' print '
  • To create this TERM, enter a description and click on SUBMIT.' print '
' display_footer() return ## I always have an object definition - put the object parameters into a dictionary ## fill the dictionary containing all the parameter values TOBJ_PARS_VAL = {} TOBJ_PARS_VAL = FillTOPDict(one_objs) ## Add reference parameter pvValue, pvTermVersion, pvDesc to the above dictionary ## making sure the parameter names match, even if out of order if one_term!=[]: ## loop over parameters of the reference object for numPar in range(1,num_params+1): if not TOBJ_PARS_VAL.has_key('order'+str(numPar)): print '
terms_report: key error on key "' print 'order' + str(numPar) + '"' print '
This action has been terminated abnormally.' print '
Please report the offending OBJECT to the email link below.

' objects_report(tlevel,one_objs) display_footer() return parOrder = TOBJ_PARS_VAL['order'+str(numPar)] parName = TOBJ_PARS_VAL['name'+parOrder] ## loop over parameters of the reference term for tValues in one_term.tValues: if parName==tValues.parName: TOBJ_PARS_VAL['pvValue'+parOrder] = tValues.pvValue TOBJ_PARS_VAL['pvTermVersion'+parOrder] = tValues.pvTermVersion TOBJ_PARS_VAL['pvDesc'+parOrder] = tValues.pvDesc continue ## loop over parameters to find any of type 'refset', 'tool' or 'filter' ## which require lookups of available refsets, tools and filters. ## If any are found, append the found type values to the lookups list lookups = [] keynames = [] ## if there are no default values, then don't print the column in the table anydef = 'no' for ipar in xrange(1,num_params+1): if TOBJ_PARS_VAL['type'+str(ipar)]=='tool' \ or TOBJ_PARS_VAL['type'+str(ipar)]=='filter' \ or TOBJ_PARS_VAL['type'+str(ipar)]=='refset': if tlevel=='l1': parName = TOBJ_PARS_VAL['name'+str(ipar)] if keynames.count(parName)==0: keynames.append(parName) if lookups.count(TOBJ_PARS_VAL['type'+str(ipar)])==0: lookups.append(TOBJ_PARS_VAL['type'+str(ipar)]) if TOBJ_PARS_VAL['defaultValue'+str(ipar)]!='': anydef = 'yes' ## start the parameter values table, skipping pvTermVersion if lookups is empty print '' print '' for ipar in range(4,len(TTERM_VAL_LIST)): if anydef=='no' and TTERM_VAL_LIST[ipar]=='defaultValue': continue if len(lookups)==0 and TTERM_VAL_LIST[ipar]=='pvTermVersion': continue print '' print '' ## parOrder, parName, parType, pvValue, pvTermVersion, pvDesc, parDefault ith_tValues = 0 for iparam in xrange(num_params): ith_tValues = ith_tValues + 1 print '' ## parOrder parOrder = TOBJ_PARS_VAL['order'+str(ith_tValues)] print '' ## parName parName = TOBJ_PARS_VAL['name'+parOrder] print '' print '' ## parType parType = TOBJ_PARS_VAL['type'+parOrder] if parType=='refset' or parType=='tool' or parType=='filter': print '' else: print '' ## get the defaultValue key = 'defaultValue'+parOrder defaultValue = '' if TOBJ_PARS_VAL.has_key(key): defaultValue = TOBJ_PARS_VAL[key] ## pvValue key = 'pvValue'+parOrder pvValue = '' if TOBJ_PARS_VAL.has_key(key): pvValue = TOBJ_PARS_VAL[key] print '' ## pvTermVersion (only if lookups list contains elements) if len(lookups)!=0: pvTermVersion = -1 if TOBJ_PARS_VAL.has_key('pvTermVersion'+parOrder): pvTermVersion = long(TOBJ_PARS_VAL['pvTermVersion'+parOrder]) if parType=='tool' or parType=='filter' or parType=='refset': print '' else: print '' print '' else: print '' ## pvDesc pvDesc = '' if TOBJ_PARS_VAL.has_key('pvDesc'+parOrder): pvDesc = TOBJ_PARS_VAL['pvDesc'+parOrder] print '' ## defaultValue if anydef=='yes': defaultValue = TOBJ_PARS_VAL['defaultValue'+parOrder] if defaultValue=='': print '' else: print '' print '' ## end of parameter table print '
' if ipar==7 or ipar==8: print '' + TTERM_VAL_NAMES[TTERM_VAL_LIST[ipar]] + '' else: print TTERM_VAL_NAMES[TTERM_VAL_LIST[ipar]] print '
' + parOrder + '' + parName + '' + parType + '' + parType + '' print '' + 'NA' + '-' + defaultValue + '
' if L2PP_SWITCH!='off' and tlevel in ['l2t','l2f']: #print "" % (tName0,tVersion0) ## get all L2 preprocessors for this reference L2 term this_l2pps = [] if tName0!='': this_l2pps = servant.GetTL2ppToGss(tName0,tVersion0,'','','') ## get all L2 preprocessors all_l2pps = servant.GetTTL2Pps('','','','') print """
""" % (L2PP_KEYS[0],L2PP_KEYS[1],L2PP_KEYS[2]) i = 0 if len(this_l2pps) > 0: for aL2pp in this_l2pps: ## get the current status of this l2pp L2pp = servant.GetTTL2Pps(aL2pp.ppName,aL2pp.ppVersion,\ aL2pp.ppCvsPackage,[]) statCurr = L2pp[0].statCurr ## get the TDB report link for this l2pp listel = [aL2pp.ppName,aL2pp.ppVersion,aL2pp.ppCvsPackage] linkel = TDB_Report_Link('L2PP',listel) ## start this row of the table and print the first column with the link: print '' % \ (get_stat_color(statCurr),linkel) ## loop over all l2pp and print the second column with the pull down print '' i = i + 1 x = i + 2 while i < x: print '' i = i + 1 print '' % i print "
Enter all L2 PreProcessors required by this Global Term:
%s / %s / %s (Current Status)
%s
" ## add the submit button here with some instructions print """
""" htopic = 'enterterm' helpme = """Click here for additional help with: """ + \ TDB_Report_Link('helpme',[htopic],HELPDICT_HEADERS[htopic]) print '' % helpme print """
%s
""" ## if lookups are needed, print them. if len(lookups)!=0: print '
' for types in lookups: if types=='refset': print '' print 'Click here for a list of available* ' print ' Level 1 Calorimeter Reference Sets with parameter key name
    ' for keys in keynames: a_list = ['',0,keys] printit = ' %s ' % (keys) links = TDB_Report_Link('l1dialog',a_list,printit) print """
    %s
    """ % (links) print '
' if types=='tool': linkt = TDB_Report_Link('%stTerms'%(slevel),[],'L%s_TOOL_Terms'%slevel[1]) linkt = TDB_Report_Link_Add(linkt,[],instatCurr) print """ Click here for a complete list of available* """ + linkt + '' if types=='filter': linkt = TDB_Report_Link('%sfTerms'%(slevel),[],'L%s_FILTER_Terms'%slevel[1]) linkt = TDB_Report_Link_Add(linkt,[],instatCurr) if len(lookups)>1: print '
' print """ Click here for a complete list of available* """ + linkt + '' print '
' print 'NOTE !! right mouse click will list available* elements in a new window.' print '
* You have chosen elements with Current Status among: ' print instatCurr print 'on the previous form
' print '' display_footer() return ## ############################################################################### def terms_readchange(): """Read the form written by terms_change, to INSERT or UPDATE a TERM""" ## ------------------------------------------------------------------------------- ## Connect to the CORBA service. server,servant = connect_server() ## to get form content form = FormContent() ## I'll need the dbname dbname = 'anonymous' if form.has_key("dbname"): dbname = form["dbname"][0] if dbname=='anonymous': display_fatal('Improper identification') return dbdate = get_local_datetime() ## read in the preliminaries try: tlevel = form["tlevel"][0] taction = form["taction"][0] except: emsg = 'terms_readchange: incomplete instructions.' display_error(emsg,sys.exc_info()) return instatCurr,instatForm = read_statcurr_menu(form) ## only INSERT and UPDATE beyond this point if taction!='INSERT' and taction!='UPDATE': display_error('terms_readchange: incorrect action') return ## read in the new term uid, history if available ## num_tValues must be identical even if the user chose to change the reference object tName = history = ''; tVersion = 0; num_tValues = 0 if form.has_key("tName"): tName = form["tName"][0] if form.has_key("tVersion"): tVersion = int(form["tVersion"][0]) if form.has_key("history"): history = form["history"][0] if form.has_key("num_tValues"): num_tValues = int(form["num_tValues"][0]) ## initialize status flags statCurr = 'local' statUsed = 'unused' oldterm = [] slevel = tlevel[:2] tName0 = '' tVersion0 = 0 ## an 'unused' reference term is required for an UPDATE if taction=='UPDATE': try: tName0 = form["tName0"][0] tVersion0 = int(form["tVersion0"][0]) except: emsg = 'terms_readchange: incomplete reference term input' display_error(emsg,sys.exc_info()) return ## re-Get the reference term, make sure it exists and is unused try: oldterm = servant.GetTTerms(slevel,tName0,tVersion0,[]) oldname = oldterm[0].createUser olddate = oldterm[0].createDate except: display_header('GetTTerms Error') emsg = 'terms_readchange error: error getting reference term' display_exc(emsg,sys.exc_info()) ##?? display_footer() ##?? return emsg = '

Attempting to continue in INSERT mode - \ report problems immediately !!! ' display_exc(emsg) taction = 'INSERT' oldterm = [] ## if still UPDATE, see if the oldterm can still be modified if taction=='UPDATE': if oldterm==[]: display_header('UPDATE Terms Error','Main_Menu') print 'The TERM indicated no longer exists.
' print '
Term Name = ' + tName0 + ', Version = ' + str(tVersion0) display_footer() return if oldterm[0].statUsed!='unused': display_header('UPDATE Terms Error','Main_Menu') print 'The TERM listed below is no longer a candidate for modification.
' terms_report(tlevel,oldterm[0]) print '


' display_colormap() display_footer() return ## A reference object is required -- Read in and Get it ## Also get the reference object stat_curr value to use to determine the term stat refobject = [] name1 = '' if form.has_key("name1"): name1 = form["name1"][0] try: name0 = form["name0"][0] if tlevel!='l1': cvsPackage0 = form["cvsPackage0"][0] else: cvsPackage0 = '' version0 = form["version0"][0] refobject = servant.GetTObjects(tlevel,name0,cvsPackage0,version0,[]) statCurr = refobject[0].statCurr except: display_header('Get Reference Object ERROR','Main_Menu') emsg = 'terms_readchange: reference object input incomplete or dne.
' display_exc(emsg,sys.exc_info()) display_footer() return ## make sure that a reference object was found if refobject==[]: emsg = 'terms_readchange ERROR: ' emsg = emsg + 'reference Object not found in database' display_error(emsg) return ## user has been allowed to change the cvs_package and version ## make sure the number of parameters is the same as num_tValues num_params = len(refobject[0].params) if num_params!=num_tValues: emsg = 'terms_readchange ERROR: ' emsg = emsg + 'inconsistent number of parameters btwn new & reference Object.' display_error(emsg) return ## make sure there is at least one parameter with a name if num_params<=0: emsg = 'terms_readchange ERROR: minimal parameter input required.' display_error(emsg) return ## in any case, print the header at this point since some info messages may be needed ##old display_header('Trigger Term ' + taction + ' Report','Main_Menu') display_header('Trigger Term ' + taction + ' Report','terms_change') ##?? ## put the reference object in a dictionary TOBJ_PARS_VAL = {} TOBJ_PARS_VAL = FillTOPDict(refobject[0]) ##?? ## read input parameter values into the same dictionary, print '
' ## --------------------------- START LOOP ON PARAMETERS ---------------------------- insert_Params = 'PVAL,PV_VERS: ' insert_list = [] for npar in range(1,num_params+1): if name1=='none': break for column in ['parName','pvValue','pvTermVersion','pvDesc']: colName = column + str(npar) if form.has_key(colName): if column=='pvDesc': TOBJ_PARS_VAL[colName] = form_history(form,colName) else: TOBJ_PARS_VAL[colName] = spacestripfirst(form[colName][0]) else: TOBJ_PARS_VAL[colName] = '' ## make sure mandatory parameter values are entered if column=='parName' or column=='pvValue' or column=='pvTermVersion': if TOBJ_PARS_VAL[colName]=='': print '
Form is missing a mandatory entry in column ' print column + ' for index ' + str(npar) display_footer() return ## make sure the parameter names match or return an error message if column=='parName': if TOBJ_PARS_VAL[colName]!=TOBJ_PARS_VAL['name'+str(npar)]: print 'terms_readchange error: incompatible reference object names.
' print '
Reference Trigger OBJECT names are:
' for npar2 in range(1,num_params+1): for tlist in TOBJ_PARS_LIST: if TOBJ_PARS_VAL[tlist + str(npar2)]!='': print ', ' + tlist + str(npar2) + ' = ' + TOBJ_PARS_VAL[tlist + str(npar2)] print '
' print '
Trouble finding TTERM parName = ' + TOBJ_PARS_VAL['parName' + str(npar)] for npar2 in range(1,num_params+1): for tlist in ['parName','pvValue','pvTermVersion','pvDesc']: if TOBJ_PARS_VAL.has_key(tlist + str(npar2)): if TOBJ_PARS_VAL[tlist + str(npar2)]!='': print ', ' + tlist + str(npar2) + ' = ' + TOBJ_PARS_VAL[tlist + str(npar2)] display_footer() return ##?? ## get the parameter name parName = TOBJ_PARS_VAL['parName' + str(npar)] ## get the input pvValue pvValue = TOBJ_PARS_VAL['pvValue' + str(npar)] ## for any type, remove leading or trailing spaces while pvValue[:1]==' ': print '' pvTemp = pvValue[1:] pvValue = pvTemp while pvValue[len(pvValue)-1:]==' ': print '' pvTemp = pvValue[:len(pvValue)-1] pvValue = pvTemp ## if type is int, convert the string to an int, then convert back type = TOBJ_PARS_VAL['type' + str(npar)] if type=='int': try: ipvValue = int(pvValue) except: print 'terms_readchange Error: integer required for parameter ' + parName + '
' for errors in sys.exc_info(): print '
'; print errors display_footer() return pvValue = str(ipvValue) pvTermVersion = -1 ##?? ## make sure that pvValue is not an empty string if pvValue=='': print '
terms_readchange error: values for all parameters are required' display_footer() return ##?? if DEBUG!=0: print '
DEBUG: parameter type = "%s"' % type if type=='refset' or type=='tool' or type=='filter': print '
DEBUG: parameter term version = "%s"' % \ TOBJ_PARS_VAL['pvTermVersion' + str(npar)] ## if type is tool, filter or refset, then pvTermVersion is required (also req to be int) pvTermVersion = -1 if type=='refset' or type=='tool' or type=='filter': pvTermVersion = long(TOBJ_PARS_VAL['pvTermVersion' + str(npar)]) try: ipvTermVersion = int(pvTermVersion) except: print 'terms_readchange Error: integer required for PVTVersion
' for errors in sys.exc_info(): print errors; print '
' display_footer() return if ipvTermVersion<0: ##!! print ipvTermVersion emsg = 'terms_readchange error:\
A non negative version is required for all parameters of type %s.\
Go BACK and find the version of the %s you wish to use.' % \ (string.upper(type),string.upper(type)) display_exc(emsg) display_footer() return pvTermVersion = ipvTermVersion ## make sure that refset, tool or filter exists ## and get the correct name and version (if incomplete) ## and get the current status to update statCurr refterm = [] ##?? if DEBUG!=0: print '
DEBUG: Make sure the tool, filter or refset exists. ' print 'tlevel,pvValue,pvTermVersion = ' if tlevel!='l1': try: refterm = servant.GetTTerms(slevel,pvValue,pvTermVersion,[]) ## get the expected type to check the type of the refterm against the expected type if refterm!=[]: thisType = refterm[0].tValues[0].objType except: emsg = 'Unable to find valid reference TERM for ' + \ pvValue + str(pvTermVersion) display_exc(emsg,sys.exc_info()) display_footer() return else: try: refterm = servant.GetTL1Dialogs(pvValue,pvTermVersion,0,[]) thisType = 'refset' except: emsg = 'Unable to find valid L1 Calorimeter Dialog for ' + \ pvValue + str(pvTermVersion) display_exc(emsg,sys.exc_info()) display_footer() return if refterm==[]: ##?? if DEBUG!=0: print '
DEBUG: No refterm found' if tlevel!='l1': what = string.upper(type) + ' type TERM' else: what = ' Calorimeter REFSET definition' linkt = TDB_Report_Link('%sTerm'%slevel,[pvValue,pvTermVersion]) emsg = 'The %s %s is not in the database.' % (what,linkt) display_exc(emsg) emsg = 'terms_readchange error: the %s type name/version = %s\
for parameter name = "%s" does not exist in the database.\
Go BACK and use the %s link at the bottom\ of the previous page to list available %ss.\
Then enter an existing %s from the list.' % \ (type,linkt,parName,string.upper(type),what,type) print '
    %s
' % emsg display_footer() return else: ##?? if DEBUG!=0: print '
DEBUG: refterm found' try: num_refterms = len(refterm) ##!! print num_refterms if num_refterms>1: linkt = TDB_Report_Link('%sTerm'%slevel,[pvValue,pvTermVersion]) emsg = '
Warning: more than one term matches entry %s.\
The leading term will be used.
' % linkt print '%s' % emsg if tlevel=='l1': TOBJ_PARS_VAL['pvValue' + str(npar)] = refterm[0].name TOBJ_PARS_VAL['pvTermVersion' + str(npar)] = refterm[0].version pvValue = refterm[0].name pvTermVersion = long(refterm[0].version) insert_Params = insert_Params + " pval = " + pvValue + " pvers = " + str(pvTermVersion) else: if type!=thisType: linkel = TDB_Report_Link('%sTerm'%slevel,[pvValue,pvTermVersion]) emsg = 'Parameter type mismatch !!! %s is a %s. A %s is required.' %\ (linkel,thisType,string.capitalize(type)) display_exc(emsg) display_footer() return TOBJ_PARS_VAL['pvValue' + str(npar)] = refterm[0].tName TOBJ_PARS_VAL['pvTermVersion' + str(npar)] = refterm[0].tVersion pvValue = refterm[0].tName pvTermVersion = long(refterm[0].tVersion) statCurr = max([statCurr,refterm[0].statCurr]) insert_Params = insert_Params + " pval = " + pvValue + " pvers = " + str(pvTermVersion) except: emsg = '*** Error getting %s elements ' % thisType display_exc(emsg,sys.exc_info()) display_footer() return ##?? if DEBUG!=0: print str(tlevel) + ' / ' + str(pvValue) + ' / ' + str(pvTermVersion) ##?? if DEBUG!=0: print '
DEBUG: check for parameter type = %s' %type ## if type is float, make sure it can be converted to a float, ## has decimal, and no leading/trailing 0 before/after decimal if type=='float': try: fpvValue = float(pvValue) except: print 'terms_readchange Error: floating point value required for parameter ' + parName + '
' for errors in sys.exc_info(): print errors; print '
' display_footer() return if string.find(pvValue,'.')==-1: pvValue = pvValue + '.' print '' while pvValue[:2]=='-0': print '' pvTemp = '-' + pvValue[2:] pvValue = pvTemp while pvValue[:1]=='0': print '' pvTemp = pvValue[1:] pvValue = pvTemp while pvValue[len(pvValue)-1:]=='0': print '' pvTemp = pvValue[:len(pvValue)-1] pvValue = pvTemp if pvValue=='.': pvValue = '0.' if pvValue=='-0.' or pvValue=='-.': pvValue = '0.' if type=='float': pvTermVersion = -1 insert_Params = insert_Params + " pval = " + pvValue + " pvers = " + str(pvTermVersion) ## replace the entered pvValue with the reworked one if TOBJ_PARS_VAL['pvValue' + str(npar)]!=pvValue: print '' del TOBJ_PARS_VAL['pvValue' + str(npar)] TOBJ_PARS_VAL['pvValue' + str(npar)] = pvValue insert_list.append(pvValue) insert_list.append(str(pvTermVersion)) ## --------------------------- DONE LOOP ON PARAMETERS ---------------------------- ##?? if DEBUG!=0: print '
DEBUG: working on tName' ## if a term name is entered, get rid of leading or trailing spaces while tName[:1]==' ': print '' tTemp = tName[1:] tName = tTemp while tName[len(tName)-1:]==' ': print '' tTemp = tName[:len(tName)-1] tName = tTemp ## construct the term name if one is not entered, looping over pvValues again if tName=='' and name1=='none': if name0=='none': tName = 'none' else: tName = name0 if tName=='': newName = name0 + '(' for npar in range(1,num_params+1): pvValue = TOBJ_PARS_VAL['pvValue' + str(npar)] if npar==1: newName = newName + pvValue else: newName = newName + ',' + pvValue newName = newName + ')' else: newName = tName tName = re.sub(' ','_',newName) print '' ##!!If I wanted to print out the dictionary with all parameters/values ##!! for npar in range(1,num_params+1): ##!! for tlist in TTERM_VAL_LIST: ##!! if TOBJ_PARS_VAL[tlist + str(npar)]!='': ##!! print '
' + tlist + str(npar) + ' = ' + TOBJ_PARS_VAL[tlist + str(npar)] ##!! print '
' ##?? if DEBUG!=0: print '
DEBUG: fill TTermValueStruct' ## fill the TTermValueStruct with the parameter values tValues = [] objType = '' if string.find(tlevel,'f')!=-1: objType = 'filter' if string.find(tlevel,'t')!=-1: objType = 'tool' name = name0 cvsPackage = cvsPackage0 version = version0 ## check all object level keys for double quotes before inserting into struct emsg = '' for aString in [name,cvsPackage,version,dbname,objType]: if string.find(aString,'"')!=-1: emsg = "Double quotes not allowed in the input string '%s'" % \ (aString) display_exc(emsg) display_footer() return ## okay, there is at least one parameter, loop over parameters for npar in range(1,num_params+1): ## look for any parameter name = 'none' if name1=='none': print '
This TERM is based on an OBJECT with no parameters.


' tValues = [] if taction=='INSERT': tValues.append(TriggerDbServer.TTermValueStruct(\ objType,name,cvsPackage,version,'none','NA',-1,'no parameters',\ dbdate,dbname, '','' )) else: tValues.append(TriggerDbServer.TTermValueStruct(\ objType,name,cvsPackage,version,'none','NA',-1,'no parameters',\ olddate,oldname, dbdate,dbname )) break ## okay, there is at least one real parameter. ## column values must be entered in order (objType,name,cvsPackage,version,parName,pvValue,pvTermVersion,pvDesc) parName = TOBJ_PARS_VAL['parName' + str(npar)] pvValue = TOBJ_PARS_VAL['pvValue' + str(npar)] pvTermVersion = long(TOBJ_PARS_VAL['pvTermVersion' + str(npar)]) pvDesc = TOBJ_PARS_VAL['pvDesc' + str(npar)] ## check all parameters for double quotes before inserting into struct emsg = '' for aString in [parName,pvValue,pvDesc]: if string.find(aString,'"')!=-1: emsg = "Double quotes not allowed in the input string '%s'" % \ (aString) display_exc(emsg) display_footer() return ## append this parameter value set to the list if taction=='INSERT': tValues.append(TriggerDbServer.TTermValueStruct(\ objType,name,cvsPackage,version,parName,pvValue,pvTermVersion,pvDesc,\ dbdate,dbname, '','' )) else: tValues.append(TriggerDbServer.TTermValueStruct(\ objType,name,cvsPackage,version,parName,pvValue,pvTermVersion,pvDesc,\ olddate,oldname, dbdate,dbname )) ##?? if DEBUG!=0: print '
DEBUG: check key parameters' ## check key parameters for double quotes before inserting into struct emsg = '' for aString in [slevel,tName,statCurr,statUsed,history,dbname]: if string.find(aString,'"')!=-1: emsg = "Double quotes not allowed in the input string '%s'" % \ (aString) display_exc(emsg) display_footer() return ## any final warnings should come here if tlevel=='l3t': if string.find(tName,',')!=-1 or string.find(tName,'.')!=-1 or \ string.find(tName,'(')!=-1 or string.find(tName,')')!=-1: emsg = """
  • The Level 3 tool you have defined contains characters that may violate Level 3 tool parsing rules (use only alpha, numeric or underscores in L3 TOOL names). Please check the rules before continuing to follow this naming convention. Update this tool name NOW before using it.""" display_exc(emsg) ##?? if DEBUG!=0: print '
    DEBUG: look for unbalanced html tags in history' ## look for unbalanced < in description temp_hist = check_html_history(history) if temp_hist!='': display_exc(temp_hist) ##?? if DEBUG!=0: print '
    ' print '*'*80 print '

    DEBUG: fill the TTermStruct with following args' print '

    slevel = %s, tName = %s, -1,statCurr = %s, statUsed = %s ' %(slevel,tName,statCurr,statUsed) print '

    history=%s ' %history print '

    dbdate= %s,dbname=%s, blank,blank, tValues' %(dbdate,dbname) print '

    ' ## fill the TTermStruct if taction=='INSERT': term = TriggerDbServer.TTermStruct(slevel,tName,-1,\ statCurr,statUsed,history, dbdate,dbname, '','', tValues) else: term = TriggerDbServer.TTermStruct(slevel,tName,tVersion0,\ statCurr,statUsed,history, olddate,oldname, dbdate,dbname, tValues) ## check to see if there is any identical term: ## make a database connection aconn = getcon_read() ##?? if DEBUG!=0: print '
    ' print '*'*80 print '
    DEBUG: check for duplicate terms, calling GetTTermMatch' print '

    Passing the following parameters list for %d parameters' %(num_params) print '

    %s

    ' %(insert_list) ## term_list will contain term name and version; info_list will return the query try: term_list,info_list,error_list = GetTTermMatch(aconn,term,num_params,insert_list) ## term_list,info_list,error_list = GetTTermMatch(aconn,term) except: display_error('GetTTermMatch fatal error',sys.exc_info(),'') return ## if any messages were returned looking for a term match, then print: if DEBUG != 0 and info_list != []: print '

    DEBUG: printing query in info list only in html source

    ' print '' ## if any errors were encountered in looking for a term match, then abort: if error_list != []: display_exc('
    Errors found looking for duplicate terms:') for errors in error_list: display_exc(errors) print '
    ' display_footer() return else: print '

    ' ## if any terms found, look for an exact match including all attributes unless ## this is an object with no parameters (name1==none) where skip this check t_version_out = -1 if term_list != [] and name1!='none': for t_name,t_version in term_list: ## don't compare a term to itself for update if taction=='UPDATE': if t_name==tName0 and t_version==tVersion0: continue try: temp_terms = servant.GetTTerms(slevel,t_name,t_version,[]) except: print '' print 'GetTTerms Error: Failure to find Term:' print '
    ' emsg = 'Final Check Error' display_exc(emsg,sys.exc_info()) display_footer() return if len(temp_terms)>=1: for temp_term in temp_terms: #### this routine CompareTerms does not exist at this point ##compare_s = CompareTerms(term,temp_term) ## assume this is an exact match compare_t = 1 if compare_t: listel = [t_name,t_version] printit = ' %s / %d ' % (t_name,t_version ) linkel = TDB_Report_Link('%sTerm'%slevel,listel,printit) if t_version_out == -1: t_name_out = temp_term.tName t_version_out = temp_term.tVersion print """
    Found existing Term meeting all %s Term criteria:
    %s
    """ % (TRIGGER_LEVELS[slevel],linkel) else: print """

    Warning ! Another identical term found meeting all %s Term criteria:
    %s
    """ % (TRIGGER_LEVELS[slevel],linkel) if len(t_name_out)>len(temp_term.tName): t_name_out = temp_term.tName t_version_out = temp_term.tVersion ## if a matching l1 script is found, print a warning. ## create a new one only if authorization is found if t_version_out != -1: print """

    It is generally misguided to create a new Trigger Term just to rename it.
    Always consider using existing terms instead of defining news ones.

    """ ## look for authorization to make a duplicate element error_list = VerifyAuthorization(dbname,\ ['triggermeister','simulatormeister']) if error_list != []: for errors in error_list: emsg = 'Abort %s of this term. A duplicate was found. '%taction display_exc(emsg + errors) print '
    ' display_footer() return else: print """

    Security override condition detected. Continuing to create new term ...

    """ ##?? if DEBUG!=0: print 'This is the term before I am entering it
    ' terms_report(tlevel,term) ##?? if DEBUG!=0: print '
    DEBUG: make the database entry' ## make the database entry if taction=='INSERT': try: ##?? if DEBUG!=0: print '
    line before InsertTTerm' newVersion = servant.InsertTTerm(term) ##?? if DEBUG!=0: print '
    line after InsertTTerm' print '' print 'The new version number is ' print newVersion print '
    ' print 'InsertTTerm: the Term was successfully entered into the database:
    ' print '
    ' ## terms_report(tlevel,term) except: emsg = 'InsertTTerm Error: Failure to INSERT Term:' display_exc(emsg,sys.exc_info()) display_footer() return elif taction=='UPDATE': try: oterm = oldterm[0] newVersion = servant.UpdateTTerm(oterm,term) print '' print 'The new version number is ' print newVersion print '
    UpdateTTerm: The Term ' + oterm.tName + '/' + str(oterm.tVersion) print ' has been deleted.' print '
    ' ## terms_report(tlevel,oterm) print '
    It was replaced by this Term in the database:
    ' ## terms_report(tlevel,term) except: emsg = 'UpdateTTerm Error: Failure to UPDATE Term:
    ' display_exc(emsg,sys.exc_info()) print '

    The existing database record:
    ' terms_report(tlevel,oterm) print '

    was NOT replaced with
    ' terms_report(tlevel,term) print '


    ' display_colormap() display_footer() return ## build l2preprocessor ## ## input from form: name=ppx value=some:l2:pp ## loop over all ppx's split value on : ## insert l2pp into mapping table ## ## ## ## ## print "" if form.has_key('numofpp'): print "" try: numofpp = form['numofpp'][0] print "" % numofpp pps = {} for i in range(0,int(numofpp)): if form.has_key('pp%s' % i): print "" % form['pp%s' % i][0] pps['pp%s' % i] = form['pp%s' % i][0] print "" % pps.items() ## ## example pps = {'pp0' : 'cal:testpackage:v0_0', ## 'pp1' : 'cal:testpackage:v1_0'} ## npps = {} for app in pps.keys(): x = string.split(pps[app],':') print "" % x npps[app] = {} npps[app]['ppName'] = x[0] npps[app]['ppCvsPackage'] = x[1] npps[app]['ppVersion'] = x[2] print "" % npps.items() ## ## example npps = {'pp0' : {'ppName' : 'cal', ## 'ppCvsPackage' : 'testpackage', ## 'ppVersion' : 'v0_0' ## }, ## 'pp1' : {'ppName' : 'cal', ## 'ppCvsPackage' : 'testpackage', ## 'ppVersion' : 'v1_0' ## } ## } i = 1 for ak in npps.keys(): if taction=='INSERT': print "" #is this pp already mapped rows = servant.GetTL2ppToGss(term.tName,1,npps[ak]['ppName'],npps[ak]['ppVersion'],npps[ak]['ppCvsPackage']) print "" % al2pp print "" servant.InsertTL2ppToGs(al2pp) i = i + 1 elif taction=='UPDATE': print "" #find any pp rows = servant.GetTL2ppToGss(term.tName,term.tVersion,npps[ak]['ppName'],'','','') #delete all found for app in rows: servant.DelTL2ppToGs(app) #now replace them al2pp = TriggerDbServer.TL2ppToGs(term.tName,term.tVersion,i,npps[ak]['ppName'],npps[ak]['ppVersion'],npps[ak]['ppCvsPackage']) servant.InsertTL2ppToGs(al2pp) i = i + 1 except: print "" % sys.exc_value emsg = 'InsertTTerm Error: Failure to INSERT Term:' display_exc(emsg,sys.exc_info()) display_footer() return ## look for lack of new version if not newVersion or newVersion<=0: newVersion = 0 print '
    WARNING!!! The new version was not returned by Insert/UpdateTTerm' print '
    Getting all versions, using highest ranked version:
    ' ##?? if DEBUG!=0: print '
    DEBUG: get the new entry' ## get the new entry trig_terms = [] try: trig_terms = servant.GetTTerms(slevel,tName,newVersion,[]) except: print '' print 'GetTTerms Error: Failure to find new Term:' print '
    ' emsg = 'Final Check Error' display_exc(emsg,sys.exc_info()) display_footer() return if trig_terms==[]: print 'Final Check Error
    ' print 'The new TERM cannot be found in the database. Something is wrong.
    ' print '
    Term Name = ' + tName + ', Version = ' + str(newVersion) display_footer() return one_term = trig_terms[0] if trig_terms!=[]: print '
    Database Report:
    ' terms_report(tlevel,one_term) ## Make a quick update submit button for INSERT and UPDATE, which needs ## the following information on the form (in addition to function name in header) ## (assumes action='dummy' in %_change function) print '' print '' % tlevel print '' print '' print '' % one_term.tName print '' % one_term.tName print '' % one_term.tVersion print '' % one_term.tVersion print '

    Click here to launch an immediate UPDATE to this Term: ' print '' print '


    ' display_colormap() else: printit = tlevel + ' Term (' + name if tlevel!='l1': printit = printit + ',' + cvsPackage printit = printit + ',' + version + ')' print '

    Final check failed.' print '
    Unable to Get ' + printit display_footer() return ## ############################################################################### def terms_report_text(one_term): "This routine prints the (tlevel) trigger term (one_term) and its parameters" ## get/print the term information tName = one_term.tName tVersion = one_term.tVersion statCurr = one_term.statCurr statUsed = one_term.statUsed history = one_term.history ## initialize the returned list outtext = [] ## add the element identification outtext.append('tName,tVersion,stat_used,stat_curr,history') out = '' for element in tName,str(tVersion),statUsed,statCurr,history: if element==tName: out = out + element elif element==history: out = out + ', "' + element + '"' else: out = out + ', ' + element outtext.append(out) ## add the object it is based on objType = one_term.tValues[0].objType name = one_term.tValues[0].name cvsPackage = one_term.tValues[0].cvsPackage version = one_term.tValues[0].version outtext.append('This Term is based on objType,name,cvsPackage,version') out = '"' + objType + '"' for element in name,cvsPackage,version: out = out + ', "' + element + '"' outtext.append(out) ## list column names, if any (order, name, type, default, min, max, description) num_tValues = len(one_term.tValues) if num_tValues==0: out = 'This term definition is incomplete. No OBJECT definition found.' outtext.append(out) return outtext if num_tValues==1 and one_term.tValues[0].parName=='none': out = 'This object has no parameters' outtext.append(out) return outtext out = 'parName,pvValue,pvTermVersion,pvDesc' outtext.append(out) ## now the parameter values themselves for tValues in one_term.tValues: out = '' out = out + tValues.parName + ', ' out = out + '"' + tValues.pvValue + '", ' if tValues.pvTermVersion: out = out + str(tValues.pvTermVersion) + ', ' else: out = out + '"", ' if tValues.pvDesc: out = out + '"' + tValues.pvDesc + '", ' else: out = out + '""' outtext.append(out) return outtext ## ############################################################################### def terms_print(aterm): "print out the term information in the TTermStruct aterm" ## Usage: ## terms_print(term) print '
    Level: ' print aterm.level print '
    Term_Name: ' print aterm.tName print '
    tVersion: ' print aterm.tVersion print '
    Current Status: ' print aterm.statCurr print '
    Usage Status: ' print aterm.statUsed print '
    History: ' print aterm.history print '
    Number of parameter/value pairs = ' print len(aterm.tValues) print '
    The following parameters were found' print '
    ' TTERM_PARS_VALz = {} TTERM_PARS_VALz = FillTTVDict(aterm) for keys in TTERM_PARS_VALz.keys(): print keys + ' = ' print TTERM_PARS_VALz[keys] print '
    ' print '
    ' return ## display_print('test',tlevel,taction, instatCurr) ## ############################################################################### ##def GetTTermMatch(aconn,thisterm): def GetTTermMatch(aconn,thisterm,num_params,insert_list): """Return a list of Term Name/Version pairs which share an identical set of parameters/values/pvtermversion conditions as in the input TTermStruct thisterm. Also return a list of informational messages and a list of any errors encountered.""" ## ------------------------------------------------------------------------------- ## initialize the output terms_out = [] info_out = [] error_out = [] ## other initialization: counter for parameters, sql list, par list iorder = 0 tsql_list = [] par_list = [] records_out =[] ## see if the struct can be unpacked try: num_tValues = len(thisterm.tValues) if num_tValues==0: error_out.append('GetTTermMatch error: no values found') level = thisterm.level tName = thisterm.tName tVersion = thisterm.tVersion except: error_out.append('GetTTermMatch error: unable to unpack term') for err in sys.exc_info(): errors_out.append(err) ## get the object basis for this term name = thisterm.tValues[0].name if level!='l1': cvsPackage = thisterm.tValues[0].cvsPackage version = thisterm.tValues[0].version if level!='l1': objType = thisterm.tValues[0].objType ## the SELECT part of the query: aview = 'v_%s_terms' % level qstring = 'SELECT unique t_name,t_version FROM %s tview' % (aview) ##start new mvi code qstring = 'SELECT t_name,t_version,PV_VALUE,PV_TERM_VERSION,PAR_ORDER FROM %s tview ' % (aview) ostring = """ WHERE o_name='%s'""" % (name) if level!='l1': andstring = """ AND o_version='%s' AND OBJ_TYPE = '%s' AND cvs_package='%s'""" % (version,objType,cvsPackage) else: andstring = """ AND o_version='%s'""" %(version) orderby = 'order by T_NAME,T_VERSION,PAR_ORDER' qstring = qstring + ostring + andstring + orderby try: records_out = getdata(aconn, qstring) info_out.append('Query string was = "' + qstring + '"') except: for err in sys.exc_info(): errors_out.append(err) info_out.append('Query string was = "' + qstring + '"') new_term = '' par_list = 'START PARAMS : ' npar=num_params ## hardcoded for test cur_par_list=[] full_par_list=[] cur_terms =[] full_terms_list=[] iterm = 1 ipar =1 for t_name,t_version,pv_value,pv_term_version,par_order in records_out: this_term = t_name + str(t_version) if this_term!=new_term: new_term = this_term par_list = 'LIST %d ' %(iterm) par_list = par_list + " val = " + pv_value + " ver = " + str(pv_term_version) + "," ipar=1 cur_terms=[] cur_terms = [t_name,t_version] if DEBUG!=0: print '

    terms+version = %s ' %cur_terms cur_par_list=[] ## reset par list cur_par_list.append(pv_value) cur_par_list.append(str(pv_term_version)) iterm+=1 else: par_list = par_list + " val = " + pv_value + " ver = " + str(pv_term_version) + "," ipar+=1 cur_par_list.append(pv_value) cur_par_list.append(str(pv_term_version)) if ipar==npar: full_par_list.append(cur_par_list) full_terms_list.append(cur_terms) if DEBUG!=0: print '

    ***** ADDING TO FULL list ,iterm = %d, ==== %s ' %(iterm,cur_par_list) ntot_terms = iterm-1 len_flist = len(full_terms_list) if DEBUG!=0: print '

    Found %d terms based on same object' %len_flist print '


    ' for aterm_p in range(0,len_flist): print '

    index = %d term= %s ' %(aterm_p,full_terms_list[aterm_p]) print '

    index = %d pars= %s ' %(aterm_p,full_par_list[aterm_p]) print '

    COMPARING with candidate term = %s ' %insert_list ndups=0 for aterm in range(0,len_flist): if insert_list == full_par_list[aterm]: ndups+=1 print '

    DUPLICATE found !! %s' %(full_terms_list[aterm]) if DEBUG!=0: print '

    candidate = %s ' %insert_list print '

    duplicate = %s ' %full_par_list[aterm] terms_out.append(full_terms_list[aterm]) info_out.append('Query string was = "' + qstring + '"') return terms_out,info_out,error_out ## -------------------------------------------------------------------------------