def doScope(self): response_headers = list() noCache(response_headers) overallShot = None if 'user' in self.args: user = self.args['user'][-1] response_headers.append(('Content-type', 'text/html')) outStr = '<html><head><title>Scope Selection</title><body>' subdir = '' if 'dir' in self.args and '..' not in self.args['dir'][-1]: file_list = getConfigFiles(user, 'jScope' in self.args, self.args['dir'][-1]) else: file_list = getConfigFiles(user, True, '') file_list.extend(getConfigFiles(user, False, '')) if (len(file_list) == 0): outStr = outStr + 'No Scope configuration file found</body></html>' status = '200 OK' return (status, response_headers, outStr) file_list.sort(file_list_cmp) last_is_dir = False for f in file_list: if not f['notdir']: last_is_dir = True if f['jScope']: jscope = '&jScope=yes' else: jscope = '' outStr = outStr + '<a href="?user='******'&dir=' + f[ 'subdir'] + '/' + f['file'] + jscope + '">' + f[ 'filespec'] + '</a><br>' else: if last_is_dir: outStr = outStr + '<br>' last_is_dir = False outStr = outStr + '<a href="scope?config=' + f[ 'filespec'] + '" target="_blank">' + f[ 'filespec'] + '</a><br>' outStr = outStr + '</body></html>' status = '200 OK' return (status, response_headers, outStr) elif 'configxml' in self.args: #Handle direct configuration response_headers.append(('IS_CONFIG', 'YES')) response_headers.append(('Content-type', 'text/xml')) if 'shot' in self.args: overallShot = self.args['shot'][-1] f = open(self.args['configxml'][-1], 'r') lines = f.readlines() f.close() outStr = '<scope>' title = getValue(lines, 'Scope.title') if title: outStr = outStr + '<title><expression>' + encodeUrl( title) + '</expression>' event = getValue(lines, 'Scope.update_event') if event: outStr = outStr + '<event>' + event + '</event>' outStr = outStr + '</title>' outStr = outStr + '<palette>' idx = 0 GLOBAL_SHOT_IDX = 8 GLOBAL_TREE_IDX = 7 GLOBAL_XMIN_IDX = 12 GLOBAL_XMAX_IDX = 13 GLOBAL_YMIN_IDX = 14 GLOBAL_YMAX_IDX = 15 while True: color = getValue(lines, 'Scope.color_' + str(idx)) if (color == None): break color = color.split(',')[0] if color == 'Blak': color = 'Black' outStr = outStr + '<color>' + color + '</color>' idx = idx + 1 #Handle missing color palette if (idx == 0): outStr = outStr + '<color>Black</color>' outStr = outStr + '</palette>' globalTree = getValue(lines, 'Scope.global_1_1.experiment') globalShot = getValue(lines, 'Scope.global_1_1.shot') globalXMin = getValue(lines, 'Scope.global_1_1.xmin') globalXMax = getValue(lines, 'Scope.global_1_1.xmax') globalYMin = getValue(lines, 'Scope.global_1_1.ymin') globalYMax = getValue(lines, 'Scope.global_1_1.ymax') globalXLabel = getValue(lines, 'Scope.global_1_1.x_label') globalYLabel = getValue(lines, 'Scope.global_1_1.y_label') globalEvent = getValue(lines, 'Scope.global_1_1.event') numCols = int(getValue(lines, 'Scope.columns')) outStr = outStr + '<columns>' for colIdx in range(1, numCols + 1): outStr = outStr + '<column>' numRows = int( getValue(lines, 'Scope.rows_in_column_' + str(colIdx))) for rowIdx in range(1, numRows + 1): outStr = outStr + '<panel ' globalDefs = int( getValue( lines, 'Scope.plot_' + str(rowIdx) + '_' + str(colIdx) + '.global_defaults')) if (globalDefs & (1 << GLOBAL_TREE_IDX)): tree = globalTree else: tree = getValue( lines, 'Scope.plot_' + str(rowIdx) + '_' + str(colIdx) + '.experiment') if (tree != None): outStr = outStr + ' tree = "' + tree + '" ' if overallShot != None: outStr = outStr + ' shot = "' + overallShot + '" ' else: if (globalDefs & (1 << GLOBAL_SHOT_IDX)): shotNum = globalShot else: shotNum = getValue( lines, 'Scope.plot_' + str(rowIdx) + '_' + str(colIdx) + '.shot') if (shotNum != None): outStr = outStr + ' shot = "' + shotNum + '" ' if (globalDefs & (1 << GLOBAL_XMIN_IDX)): xmin = globalXMin else: xmin = getValue( lines, 'Scope.plot_' + str(rowIdx) + '_' + str(colIdx) + '.xmin') if (xmin != None): outStr = outStr + ' xmin = "' + encodeUrl(xmin) + '" ' if (globalDefs & (1 << GLOBAL_XMAX_IDX)): xmax = globalXMax else: xmax = getValue( lines, 'Scope.plot_' + str(rowIdx) + '_' + str(colIdx) + '.xmax') if (xmax != None): outStr = outStr + ' xmax = "' + encodeUrl(xmax) + '" ' if (globalDefs & (1 << GLOBAL_YMIN_IDX)): ymin = globalYMin else: ymin = getValue( lines, 'Scope.plot_' + str(rowIdx) + '_' + str(colIdx) + '.ymin') if (ymin != None): outStr = outStr + ' ymin = "' + encodeUrl(ymin) + '" ' if (globalDefs & (1 << GLOBAL_YMAX_IDX)): ymax = globalYMax else: ymax = getValue( lines, 'Scope.plot_' + str(rowIdx) + '_' + str(colIdx) + '.ymax') if (ymax != None): outStr = outStr + ' ymax = "' + encodeUrl(ymax) + '" ' title = getValue( lines, 'Scope.plot_' + str(rowIdx) + '_' + str(colIdx) + '.title') if (title != None): title = encodeUrl(title) title = title.replace('"', "'") outStr = outStr + ' title = "' + title + '"' xlabel = getValue( lines, 'Scope.plot_' + str(rowIdx) + '_' + str(colIdx) + '.x_label') if (xlabel == None): xlabel = globalXLabel if (xlabel != None): xlabel = encodeUrl(xlabel) xlabel = xlabel.replace('"', "'") outStr = outStr + ' xlabel = "' + xlabel + '"' ylabel = getValue( lines, 'Scope.plot_' + str(rowIdx) + '_' + str(colIdx) + '.y_label') if (ylabel == None): ylabel = globalYLabel if (ylabel != None): ylabel = encodeUrl(ylabel) ylabel = ylabel.replace('"', "'") outStr = outStr + ' ylabel = "' + ylabel + '"' event = getValue( lines, 'Scope.plot_' + str(rowIdx) + '_' + str(colIdx) + '.event') if (event == None): event = globalEvent if (event != None): outStr = outStr + ' event = "' + event + '"' continuous_update = getValue( lines, 'Scope.plot_' + str(rowIdx) + '_' + str(colIdx) + '.continuous_update') if (continuous_update != None): outStr = outStr + ' continuous_update = "' + continuous_update + '"' is_image = getValue( lines, 'Scope.plot_' + str(rowIdx) + '_' + str(colIdx) + '.is_image') if (is_image != None and is_image == 'true'): outStr = outStr + ' is_image = "true"' keep_ratio = getValue( lines, 'Scope.plot_' + str(rowIdx) + '_' + str(colIdx) + '.keep_ratio') if (keep_ratio != None): outStr = outStr + ' keep_ratio = "' + keep_ratio + '"' horizontal_flip = getValue( lines, 'Scope.plot_' + str(rowIdx) + '_' + str(colIdx) + '.horizontal_flip') if (horizontal_flip != None): outStr = outStr + ' horizontal_flip = "' + horizontal_flip + '"' vertical_flip = getValue( lines, 'Scope.plot_' + str(rowIdx) + '_' + str(colIdx) + '.vertical_flip') if (vertical_flip != None): outStr = outStr + ' vertical_flip = "' + vertical_flip + '"' palette = getValue( lines, 'Scope.plot_' + str(rowIdx) + '_' + str(colIdx) + '.palette') if (palette != None): outStr = outStr + ' palette = "' + palette + '"' bitShift = getValue( lines, 'Scope.plot_' + str(rowIdx) + '_' + str(colIdx) + '.bitShift') if (bitShift != None): outStr = outStr + ' bitShift = "' + bitShift + '"' bitClip = getValue( lines, 'Scope.plot_' + str(rowIdx) + '_' + str(colIdx) + '.bitClip') if (bitClip != None): outStr = outStr + ' bitClip = "' + bitClip + '"' outStr = outStr + '>' numExprStr = getValue( lines, 'Scope.plot_' + str(rowIdx) + '_' + str(colIdx) + '.num_expr') if (numExprStr == None): numExpr = 1 else: numExpr = int(numExprStr) for exprIdx in range(1, numExpr + 1): outStr = outStr + '<signal' color = getValue( lines, 'Scope.plot_' + str(rowIdx) + '_' + str(colIdx) + '.color_' + str(exprIdx) + '_1') if (color != None): if color == 'Blak': color = 'Black' #fix old config file typo outStr = outStr + ' color="' + color + '"' else: outStr = outStr + ' color="Black"' mode = getValue( lines, 'Scope.plot_' + str(rowIdx) + '_' + str(colIdx) + '.mode_1D_' + str(exprIdx) + '_1') marker = getValue( lines, 'Scope.plot_' + str(rowIdx) + '_' + str(colIdx) + '.marker_' + str(exprIdx) + '_1') if (mode == 'Line' and marker == '0'): outStr = outStr + ' mode="1"' elif (mode == 'Line' and marker != '0'): outStr = outStr + ' mode="3"' elif (mode == 'Noline' and marker != '0'): outStr = outStr + ' mode="2"' outStr = outStr + '>' yExpr = getValue( lines, 'Scope.plot_' + str(rowIdx) + '_' + str(colIdx) + '.y_expr_' + str(exprIdx)) if (yExpr == None): yExpr = getValue( lines, 'Scope.plot_' + str(rowIdx) + '_' + str(colIdx) + '.y') xExpr = getValue( lines, 'Scope.plot_' + str(rowIdx) + '_' + str(colIdx) + '.x_expr_' + str(exprIdx)) if (xExpr == None): xExpr = getValue( lines, 'Scope.plot_' + str(rowIdx) + '_' + str(colIdx) + '.x') if (xExpr == None): outStr = outStr + encodeUrl(yExpr) + '</signal>' else: outStr = outStr + 'BUILD_SIGNAL(' + encodeUrl( yExpr) + ',,' + encodeUrl(xExpr) + ')</signal>' outStr = outStr + '</panel>\n' outStr = outStr + '</column>\n\n' outStr = outStr + '</columns></scope>' output = str(outStr) status = '200 OK' return (status, response_headers, output) elif 'panel' in self.args: return doScopepanel(self) elif 'title' in self.args: response_headers.append(('Content-type', 'text/text')) try: output = str(Data.execute(self.args['title'][0])) except Exception: output = str( sys.exc_info()) + ' expression was ' + self.args['title'][0] return ('200 OK', response_headers, output) elif 'colortables' in self.args: response_headers.append(('Content-type', 'application/octet-stream')) try: f = open(os.path.dirname(__file__) + '/colors1.tbl', "r") output = f.read() f.close() except: response_headers.append(('ERROR', str(sys.exc_info()))) output = '' return ('200 OK', response_headers, output) else: ans = ('400 NOT FOUND', [ ('Content-type', 'text/text'), ], '') try: f = open(os.path.dirname(__file__) + '/../html/scope.html', "r") contents = f.read() f.close() ans = ('200 OK', [ ('Content-type', 'text/html'), ], contents) except: pass return ans
def doScope(self): response_headers=list() noCache(response_headers) if 'user' in self.args: user=self.args['user'][-1] response_headers.append(('Content-type','text/html')) outStr='<html><head><title>Scope Selection</title><body>' subdir='' if 'dir' in self.args and '..' not in self.args['dir'][-1]: file_list=getConfigFiles(user,'jScope' in self.args,self.args['dir'][-1]) else: file_list=getConfigFiles(user,True,'') file_list.extend(getConfigFiles(user,False,'')) if(len(file_list) == 0): outStr = outStr+'No Scope configuration file found</body></html>' status = '200 OK' return (status, response_headers, outStr) file_list.sort(file_list_cmp) last_is_dir=False for f in file_list: if not f['notdir']: last_is_dir=True if f['jScope']: jscope='&jScope=yes' else: jscope='' outStr = outStr + '<a href="?user='******'&dir='+f['subdir']+'/'+f['file']+jscope+'">'+f['filespec']+'</a><br>' else: if last_is_dir: outStr = outStr + '<br>' last_is_dir=False outStr = outStr + '<a href="scope?config='+f['filespec'] +'" target="_blank">'+f['filespec']+'</a><br>' outStr = outStr + '</body></html>' status = '200 OK' return (status, response_headers, outStr) elif 'configxml' in self.args: #Handle direct configuration response_headers.append(('IS_CONFIG','YES')) response_headers.append(('Content-type','text/xml')) f = open(self.args['configxml'][-1],'r') lines = f.readlines() f.close() outStr = '<scope>' title=getValue(lines, 'Scope.title') if title: outStr = outStr + '<title><expression>'+encodeUrl(title)+'</expression>' event=getValue(lines,'Scope.update_event') if event: outStr = outStr + '<event>'+event+'</event>' outStr = outStr + '</title>' outStr = outStr + '<palette>' idx = 0 GLOBAL_SHOT_IDX = 8 GLOBAL_TREE_IDX = 7 GLOBAL_XMIN_IDX = 12 GLOBAL_XMAX_IDX = 13 GLOBAL_YMIN_IDX = 14 GLOBAL_YMAX_IDX = 15 while True: color = getValue(lines, 'Scope.color_'+str(idx)) if(color == None): break color = color.split(',')[0] if color == 'Blak': color = 'Black' outStr = outStr+'<color>'+color+'</color>' idx = idx + 1 #Handle missing color palette if (idx == 0): outStr = outStr+'<color>Black</color>' outStr = outStr+'</palette>' globalTree = getValue(lines, 'Scope.global_1_1.experiment') globalShot = getValue(lines, 'Scope.global_1_1.shot') globalXMin = getValue(lines, 'Scope.global_1_1.xmin') globalXMax = getValue(lines, 'Scope.global_1_1.xmax') globalYMin = getValue(lines, 'Scope.global_1_1.ymin') globalYMax = getValue(lines, 'Scope.global_1_1.ymax') globalXLabel = getValue(lines, 'Scope.global_1_1.x_label') globalYLabel = getValue(lines, 'Scope.global_1_1.y_label') globalEvent = getValue(lines, 'Scope.global_1_1.event') numCols = int(getValue(lines, 'Scope.columns')) outStr = outStr+'<columns>' for colIdx in range(1, numCols+1): outStr = outStr+'<column>' numRows = int(getValue(lines, 'Scope.rows_in_column_'+str(colIdx))) for rowIdx in range(1, numRows+1): outStr = outStr + '<panel ' globalDefs = int(getValue(lines, 'Scope.plot_'+str(rowIdx)+'_'+str(colIdx)+'.global_defaults')) if(globalDefs & (1 << GLOBAL_TREE_IDX)): tree = globalTree else: tree = getValue(lines, 'Scope.plot_'+str(rowIdx)+'_'+str(colIdx)+'.experiment') if(tree != None): outStr = outStr+' tree = "'+tree+'" '; if(globalDefs & (1 << GLOBAL_SHOT_IDX)): shotNum = '-2' else: shotNum = getValue(lines, 'Scope.plot_'+str(rowIdx)+'_'+str(colIdx)+'.shot') if(shotNum != None): outStr = outStr+' shot = "'+shotNum+'" ' if(globalDefs & (1 << GLOBAL_XMIN_IDX)): xmin = globalXMin else: xmin = getValue(lines, 'Scope.plot_'+str(rowIdx)+'_'+str(colIdx)+'.xmin') if(xmin != None): outStr = outStr+' xmin = "'+encodeUrl(xmin)+'" ' if(globalDefs & (1 << GLOBAL_XMAX_IDX)): xmax = globalXMax else: xmax = getValue(lines, 'Scope.plot_'+str(rowIdx)+'_'+str(colIdx)+'.xmax') if(xmax != None): outStr = outStr+' xmax = "'+encodeUrl(xmax)+'" ' if(globalDefs & (1 << GLOBAL_YMIN_IDX)): ymin = globalYMin else: ymin = getValue(lines, 'Scope.plot_'+str(rowIdx)+'_'+str(colIdx)+'.ymin') if(ymin != None): outStr = outStr+' ymin = "'+encodeUrl(ymin)+'" ' if(globalDefs & (1 << GLOBAL_YMAX_IDX)): ymax = globalYMax else: ymax = getValue(lines, 'Scope.plot_'+str(rowIdx)+'_'+str(colIdx)+'.ymax') if(ymax != None): outStr = outStr+' ymax = "'+encodeUrl(ymax)+'" ' title = getValue(lines, 'Scope.plot_'+str(rowIdx)+'_'+str(colIdx)+'.title') if(title != None): title = encodeUrl(title) title = title.replace('"', "'") outStr = outStr+' title = "'+title+'"' xlabel = getValue(lines,'Scope.plot_'+str(rowIdx)+'_'+str(colIdx)+'.x_label') if (xlabel == None): xlabel = globalXLabel if (xlabel != None): xlabel = encodeUrl(xlabel) xlabel = xlabel.replace('"',"'") outStr = outStr+' xlabel = "'+xlabel+'"' ylabel = getValue(lines,'Scope.plot_'+str(rowIdx)+'_'+str(colIdx)+'.y_label') if (ylabel == None): ylabel = globalYLabel if (ylabel != None): ylabel = encodeUrl(ylabel) ylabel = ylabel.replace('"',"'") outStr = outStr+' ylabel = "'+ylabel+'"' event = getValue(lines,'Scope.plot_'+str(rowIdx)+'_'+str(colIdx)+'.event') if (event == None): event = globalEvent if (event != None): outStr = outStr+' event = "'+event+'"' outStr = outStr + '>' numExprStr = getValue(lines, 'Scope.plot_'+str(rowIdx)+'_'+str(colIdx)+'.num_expr') if(numExprStr == None): numExpr = 1 else: numExpr = int(numExprStr) for exprIdx in range(1, numExpr+1): outStr = outStr+'<signal' color = getValue(lines, 'Scope.plot_'+str(rowIdx)+'_'+str(colIdx)+'.color_'+str(exprIdx)+'_1') if(color != None): if color == 'Blak': color = 'Black' #fix old config file typo outStr = outStr+' color="'+color+'"' else: outStr = outStr + ' color="Black"' mode = getValue(lines, 'Scope.plot_'+str(rowIdx)+'_'+str(colIdx)+'.mode_1D_'+str(exprIdx)+'_1') marker = getValue(lines, 'Scope.plot_'+str(rowIdx)+'_'+str(colIdx)+'.marker_'+str(exprIdx)+'_1') if(mode == 'Line' and marker == '0'): outStr = outStr+ ' mode="1"' elif(mode == 'Line' and marker != '0'): outStr = outStr+ ' mode="3"' elif(mode == 'Noline' and marker != '0'): outStr = outStr+ ' mode="2"' outStr = outStr+'>' yExpr = getValue(lines, 'Scope.plot_'+str(rowIdx)+'_'+str(colIdx)+'.y_expr_'+str(exprIdx)) if(yExpr == None): yExpr = getValue(lines, 'Scope.plot_'+str(rowIdx)+'_'+str(colIdx)+'.y') xExpr = getValue(lines, 'Scope.plot_'+str(rowIdx)+'_'+str(colIdx)+'.x_expr_'+str(exprIdx)) if(xExpr == None): xExpr = getValue(lines, 'Scope.plot_'+str(rowIdx)+'_'+str(colIdx)+'.x') if(xExpr == None): outStr = outStr+encodeUrl(yExpr)+'</signal>' else: outStr = outStr+'BUILD_SIGNAL('+encodeUrl(yExpr)+',,'+encodeUrl(xExpr)+')</signal>' outStr = outStr+'</panel>\n' outStr = outStr+'</column>\n\n' outStr = outStr+'</columns></scope>' output=str(outStr) status = '200 OK' return (status, response_headers, output) elif 'panel' in self.args: return doScopepanel(self) elif 'title' in self.args: response_headers.append(('Content-type','text/text')) try: output = str(Data.execute(self.args['title'][0])) except Exception: output = str(sys.exc_info())+' expression was '+self.args['title'][0] return ('200 OK',response_headers, output) else: ans=('400 NOT FOUND',[('Content-type','text/text'),],'') try: f=open(os.path.dirname(__file__)+'/../html/scope.html',"r") contents=f.read() f.close() ans = ('200 OK',[('Content-type','text/html'),],contents) except: pass return ans