3 from optparse
import OptionParser
12 newModsNames,oldMods,allMods=[],[],[]
22 rest= html.rsplit(
'/',1)
32 <li class="expand %(className)s" data-name="%(nameID)s">%(nameID)s:</li>
34 self.
cfg = imp.load_source(
"cfg", cfgFile)
36 psetTypes = open(
"%sparamTypes.js"%(self.
theDir),
'w')
38 print "Starting print out of psets."
40 print "Finished finding psets. Now onto paths..."
45 modHTMLName=
"%sparamTypes.js"%(self.
theDir)
46 modToPathName =
"%smodToPath.js" %(self.
theDir)
47 tempFile =
"%stemp.js"%(self.
theDir)
48 f={modHTMLName:
"params",modToPathName:
"modules"}
49 o={modHTMLName:
"a",modToPathName:
"w"}
52 curFile = open(key,o[key])
53 curFile.write(theS%(f[key]))
56 liToBeWritten, frmPathHolder=
"",
"";
57 className, theS,frmPathStr =
"path",
"",
'%s%s:["%s"]'
58 newModsStr, oldModsStr=
'%s\n%s:["%s"]',
'%s"%s",%s'
59 dataFile= open(modHTMLName,
'a')
61 paths = self.cfg.process.paths
65 for item
in paths.keys():
71 liToBeWritten +=
format(self.
pathLi,nameID=item,className=className)
73 frmPathHolder +=frmPathStr%(theS,item,
"\",\"".
join(allMods))
74 fromMod = open(modToPathName,
'r')
75 fromModTemp = open(tempFile, 'w')
77 tLine= re.sub(
'\[.*?\]',
"",line)
78 result = re.split(
':|,', tLine[tLine.find(
'{')+1:])
79 namesFound = [x
for i, x
in enumerate(result)
if not i%2]
83 if(each
in namesFound):
85 index = line.find(each)+len(each)+2
86 line = oldModsStr %(line[:index],item,line[index:])
87 fromModTemp.write(line)
89 for each
in newModsNames:
90 fromModTemp.write(newModsStr%(theS,each,item))
93 os.rename(tempFile,modToPathName)
99 out.write(
"<a href='%s'> See Psets</a> \n<ul>%s"\
100 "</ul>\n</body>\n</html>"%(self.html.rsplit(
'/',1)[-1],liToBeWritten))
102 dataFile.write(
"};\nfunction getAllParams(){\n"\
103 "var newD ={};\n var keys = Object.keys(params);\n"\
104 "for(var i=0; i <keys.length; i++){ \n"\
105 " newD[keys[i]]= params[keys[i]][\"parameters\"];\n}"\
107 " function getParams(modName){\n"\
108 " return params[modName][\"parameters\"];}\n"\
109 "function getInnerParams(parentsNames){\n"\
110 "var curList=params[parentsNames[0]][\"parameters\"];\n"\
111 "for(var i=1; i < parentsNames.length;i++){\n"\
112 " for(var p=0; p < curList.length;p++){\n"\
113 " if(curList[p][0]==parentsNames[i]){\n"\
114 " var found = curList[p][1];\n"\
115 " break;\n }\n}\n curList = found;\n}\n"\
116 " return curList;}\n"\
117 "function getFile(name){\n"\
118 "return params[name][\"file\"];\n}"\
119 "function getType(name){\n"\
120 "return params[name][\"type\"];\n}")
121 fromPath= open(
"%spathToMod.js" %(self.
theDir),
'w')
122 fromPath.write(
"var paths={%s}\n "\
123 "function getModules(thePath){\n"\
124 "return paths[thePath];\n}"\
125 "\n function keys(){\n return Object.keys(paths); "\
126 "\n}" %(frmPathHolder))
128 fromMod = open(modToPathName,
'a')
129 fromMod.write(
"}\n function getPaths(theMod){\n"\
130 "return modules[theMod];\n}")
134 addC,writeOut,toParamWrite=
"",
"",
""
139 process = self.cfg.process
140 psets = process.psets
143 writeOut+=
format(outStr,nameID=pset,className=classN)
144 psetCfg = process.__dict__[pset]
145 res =
do(psetCfg.parameters_(),[])
150 out = open(self.
html,
'w')
152 out.write(
"<a href=\"%s\"> See Paths</a>\n<ul>"\
153 "%s</ul></html>"%(self.
pathName,writeOut))
156 psetTypes = open(
"%sparamTypes.js"%(self.
theDir),
'w')
157 psetTypes.write(
"psetParams=%s\nfunction getAllpsetParams(){\n"\
158 "return psetParams;}\n"\
159 " function getpsetParams(modName){\n"\
160 " return psetParams[modName];}\n"\
161 "function getInnerpsetParams(parentsNames){\n"\
162 "var currentList = psetParams[parentsNames[0]];\n"\
163 "for(var i=1; i < parentsNames.length;i++){\n"\
164 " for(var p=0; p < currentList.length;p++){\n"\
165 " if(currentList[p][0]==parentsNames[i]){\n"\
166 " var found = currentList[p][1];\n"\
167 " break;\n }\n}\n currentList = found;\n}\n"\
168 " return currentList;}\n"%(theDict))
173 <script type="text/javascript" src="paramTypes.js"></script>
177 <option id="module" selected="selected">Module</option>
182 <option id="path" selected="selected">Path</option>
183 <option id="module">Module</option>
184 <option value="type">Type</option>
185 <option value="parameter">Parameter</option>
186 <option value="value">Value</option>
189 <script type="text/javascript" src="pathToMod.js"></script>
190 <script type="text/javascript" src="modToPath.js"></script>
191 <script type="text/javascript" src="paramTypes.js"></script>
197 <meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
198 <title>cfg-browser</title>
199 <script type="text/javascript"
200 src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
203 <script type="text/javascript" src="%(js)s"></script>
205 <link href="%(css)s" rel="stylesheet" type="text/css"/>
208 <!--form name="input" action="html_form_action.asp" method="get"-->
209 <form name="searchInput" onsubmit="return false;">
210 <input type="text" id="searchWord"/>
211 <select id="searchType">
215 <input type="submit" value="Search" id="search" disabled/></form>
216 <br/><p id="searchNumber"></p><br/>
217 <a id="hide" style="cursor:default; color:#CCCCCC;"
218 class="%(class)sReset"
219 href="javascript:;" >
222 <span id="pageType" data-type=%(class)s></span>
224 <input type="submit" id ="searchReset" style="display:none"
225 value="Reset search results." class="%(class)sReset"/>
226 <br/><input type="checkbox" id="ShowFiles" value="File"/>Show module File.
229 """%{
'js':js,
'option':buttons,
'css':css,
'dis':dis,
230 'scripts':scripts,
'class':classType})
233 jsFile = open(thejs,
'w')
235 $(document).ready(function(){
236 $(document).on('click', '#search', function(e){
238 var par = $(this).parent();
239 var id = $(par).find('#searchType').attr('id');
240 var option = $('#'+id+' option:selected').text();
241 var val = $(par).find('#searchWord').val()
242 var reg = new RegExp("("+val+")", "gi");
245 reset('li.path', e, true);
246 numFound = topLevelMatch(keys(),reg,false); // will stay the same
249 if(typeof modKeys != 'function' && false){
250 //if modKeys is not defined means we're using pset html.
251 //maybe change this so instead we define top layer li with class top
252 reset('li.module', e, true);
253 //numFound = topLevelMatch
254 numFound = topLevelMatch( $('li.module'),reg,true);
257 // for now pretend that its in html.
258 //searchReplaceHTML(reg, "module");
259 // if not in the html
260 //Okay can either, get allmatched modules and add them
261 // to all html parents
262 // or go round paths and get all matched modules adding to tghe path
263 var strings = allMods(reg);
264 var Li = $(document.createElement('li')).attr(
265 "class","module expand");
266 console.log("hereiam before");
267 searchReplaceNonHTML(strings,Li, reg)
271 //get all modules names, get files for all modules
272 // once we have a list of all modules we want
273 // add those modules to
276 // gives the params which match the reg.
277 numFound = lowerLevels(reg,doInnerParams, e)
280 reset('li.path',e,true);
281 // similar to params except we're looking at
282 // the types and not the params names.
283 // so need to get all the params, loop over the keys
284 var matches = matchValue(reg);
285 console.log("matches are "+ matches)
288 numFound = lowerLevels(reg,doInnerValue, e)
290 $('#searchNumber').html(numFound+" found.");
291 $('#searchReset').show();
295 function lowerLevels(reg,funcCall, e){
296 reset('li.path', e, true);
298 if($("span[id='pageType']").attr("data-type")=="pset"){
299 var matches = getAllpsetParams();
301 else var matches = getAllParams();
303 var keys = Object.keys(matches);
304 for(var i=0; i < keys.length; i++){
305 var theKey = keys[i];
306 var params = matches[theKey];
307 var theMod = moduleLI.clone().attr("data-name",theKey).text(theKey);
308 // need to make the ul
310 var theUL = funcCall(params,reg);
311 if(tempNumber ==0)continue;
312 theMod.append(theUL);
313 // for now just do parents
314 var pathsAddTo = getPaths(theKey);
316 for(var k=0; k < pathsAddTo.length;k++){
317 // all paths to be added to.
318 var theP = pathsAddTo[k];
320 $('li.path[name='+theP+']').each(function(){
321 // for each one add the theMod.
322 $(this).children().empty();
323 $(this).append(theMod.clone());
327 numFound += (tempNumber*mul)
332 function doInnerValue(modules,reg){
333 var theUL = UL.clone();
334 // okay we have a list where we want to check the
335 // inner list is an inner list.
336 for(var i=0; i < modules.length; i++){
337 var innerList= modules[i];
338 var theName = innerList[0];
339 var next = innerList[1];
340 // next could be inner or could be what we want.
341 if(typeof(next)=="object"){
342 // we have inner params, recurse!
343 var oldNum = tempNumber
344 var newUL = doInnerValue(next, reg); // will return a ul.
345 if(tempNumber == oldNum){
346 var li= LIExpand.clone().attr("data-name", theName).html(theName);
349 var li= LIExpanded.clone().attr("data-name", theName).html(theName);
354 // else do normal and make the
356 var newValue = next.replace(reg, "<em>$1</em>");
357 if(newValue != next){
358 tempNumber +=next.match(reg).length;
360 var li= paramLI.clone().attr("data-name",theName).html(theName);
361 var theClass="value";
362 li.append(span.clone().attr("class", "value").html(": "+newValue));
363 innerList.slice(2).forEach(function(i){
364 li.append(span.clone().attr("class", "type").text(" ("+i+")"));
372 function doInnerParams(params,reg){
373 var theUL = UL.clone();
374 // okay we have a list where we want to check the
375 // inner list is an inner list.
376 for(var i=0; i < params.length; i++){
377 var param = params[i];// it's name.
378 var theName = param[0];
379 var newName = theName.replace(reg, "<em>$1</em>");
380 if(newName != theName){
381 tempNumber +=theName.match(reg).length;
384 if(typeof(next)=="object"){
385 // we have inner params, recurse!
386 //var cloLI= LIExpand.clone().attr("name", theName).text(theName);
387 //var ul = UL.clone();
388 var old = tempNumber;
389 var newUL = doInnerParams(next, reg); // will return a ul.
390 if(old == tempNumber){
391 var li= LIExpand.clone().attr("data-name", theName).html(newName);
394 var li= LIExpanded.clone().attr("data-name", theName).html(newName);
399 // else do normal and make the
400 var li= paramLI.clone().attr("data-name",theName).html(newName);
401 var theClass="value";
402 for(var w=1; w < param.length;w++){
405 li.append(span.clone().attr("class", "value").text(": "+param[w]));
407 li.append(span.clone().attr("class", "type").text(
415 var LI= $(document.createElement('li'));
416 var moduleLI= LI.clone().attr("class","module expand");
417 var paramLI= LI.clone().attr("class","param expanded");
418 var UL = $(document.createElement('ul'));
419 var span = $(document.createElement('span'));
420 var LIExpand = LI.clone().attr("class","expand paramInner");
421 var LIExpanded = LI.clone().attr("class","expanded paramInner");
422 // All params send here.
423 //[[normaloparam, value,type]
424 //[inner[innervalues, value,type]][norm, value, type]]
425 // we will get [normaloparam, value,type] etc
429 String format should have where they want the string to go as name.
430 For module just now. //
431 */// stringformat would be what we want it to go in,
432 function searchReplaceNonHTML(strings, theLi, regex){
433 // we have the things we want, the string should just be the
434 // what we want to be shwn i.e. an LI, which we clone.
435 var UL = $(document.createElement('ul'));
436 for(var i=0; i <strings.length; i++){
437 var thisOne = strings[i]; // e.g. generator
438 //here i have the string and now i will
439 //need a format string or something, to know what to put around it?
440 var LI = theLi.clone().attr("data-name", thisOne).html(
441 thisOne.replace(regex, "<em>$1</em>"));
442 var paths = getPaths(thisOne);
443 for (var p=0; p < paths.length; p++){
444 // need to find the path on the page and add the module to it.
445 $('li.path[name='+paths[p]+']').each(function(){
446 // for each add this LI
447 if($(this).children('ul').length ==0){
448 $(this).append(UL.clone().append(LI.clone()));
451 $(this).children('ul').append(LI.clone());
452 // so all paths dont point to the same LI,maybe can change this?
454 $(this).attr("class","expanded path");
460 Search when what we're looking for is in HTML but not topLevel element.
461 To be global replace, find should be regexp object with g.
463 function searchReplaceHTML(find,identifier){
467 $("li ."+identifier).each(function(){
469 if(howmany = $(this).attr("data-name").match(find)){
472 $(this).html() = $(this).html().replace(find,"<em>$1</em>");
474 // if parents not already showen show them
475 $(this).parents('ul').each(function(){
476 if(foundParents.indexOf(this) ==-1){
478 foundParents.append(this);
481 // already done these parents
482 return false;// (i.e. break out loop);// the parents loop.
487 notFoundLI.append(this);
488 // not a match, can just try and find a ul parent,
489 //if there is one, then we need to know whether to
490 // hide it.TODO or do nothing.
493 // now we have list of parents we want to hide all other parents
494 $(notFoundLI).each(function(){
495 $(this).parents('ul').each(function(){
496 if(foundParents.indexOf(this) ==-1){
500 // already done these parents
501 return false;// (i.e. break out loop);// the parents loop.
510 $(document).on('click', '#searchReset', function(e){
511 $('#searchNumber').html("");
512 if($(this).attr('class') == "pathReset"){
513 reset('li.path',e,true);
516 reset('li.module',e,true);
521 Hides children of top level. TODO: Done - works
523 $(document).on('click', '#hide', function(e){
524 //for hiding we just get top level and remove children.
525 if($(this).css('cursor')!='default'){
526 $('#searchNumber').html("");
527 if($(this).attr('class') == "pathReset"){
528 var selec ='li.path';
530 else var selec ='li.module';
531 $(selec).each(function(){
532 if(removeChildren(this, e))toggleExpand(this, e);
534 $(this).css('color','#CCCCCC');
535 $(this).css('cursor','default');
539 Retrieves and expands path elements. - works
541 $(document).on('click', '.path.expand',function(event){
542 var UL = addModules(getModules($(this).attr('data-name')));
544 $('#hide').css('color','')
545 $('#hide').css('cursor','')
548 Adds modules to a list and returns list.
550 function addModules(results){
551 var UL = $(document.createElement("ul"));
552 var LI = $(document.createElement('li')).attr("class","module expand");
553 for(var i=0; i < results.length; i++){
554 var theName = results[i];
555 var val = theName+"("+getType(theName)+")"
556 if(document.getElementById("ShowFiles").checked)
557 val+=" ("+getFile(theName)+")"
558 UL.append(LI.clone().attr("data-name", theName).text(val));
564 Retrieve and expands module elements.
565 //changed to deal with new data format,
566 //(data now seperate from html specification) - works
568 $(document).on('click','.module.expand', function(event){
570 event.stopPropagation();
574 Add params to the object. Object can be of any type
575 (normally module or param).
576 It's name needs to be in the data to find its parameters. - works
578 function addParams(obj, results){
579 var LIBasic = $(document.createElement('li')).attr("class","param");
580 var LIExpand = LIBasic.clone().attr("class","expand paramInner");
581 var span = $(document.createElement("span"));
582 var UL = $(document.createElement("ul"));
583 // getParams returns list of list.
584 // Format:[[name,value,type,trackedornot]].CHANGED!!
586 // :[[name, value,type,trackedornot],[namePset,[name,value,type]]]
587 // If 2nd element is list then its a pset.
588 var objName = $(obj).attr('data-name');
590 if($("span[id='pageType']").attr("data-type")=="pset"){
591 var results = getpsetParams(objName);
594 var results = getParams(objName);
595 var type = getType(objName);
596 if(type == "Sequence"){
597 // inside will be names of modules
598 //- so do the same as if this was a path obj
599 var ul = addModules(results);
605 for(var i =0; i < results.length; i++){
606 var all = results[i].slice();
607 var theName = all.shift();
608 if(typeof(all[0]) == "object"){
609 var cloLI= LIExpand.clone().attr("data-name", theName).text(theName);
610 //for(var p=0; p < all[0].length;p++){
616 var cloLI = LIBasic.clone().attr("data-name", theName).text(theName);
617 var value = all.shift()
618 // formating so lots of strings look nicer
619 if(value.indexOf(",")>-1)
620 value = "<ul>"+value.replace(/,/g, "</li><li>")+"</li></ul>"
621 cloLI.append(span.clone().attr("class","value").html(": "+value))
622 for(var p=0; p < all.length; p++){
623 cloLI.append(span.clone().attr("class","type").text(
630 $('#hide').css('color','')
631 $('#hide').css('cursor','')
634 Hides/Shows children from class param.
635 //changed to deal with new data format - works
637 $(document).on('click', '.paramInner.expand, .paramInner.expanded',
639 if($(this).children('ul').length ==0){
643 var parents =[$(this).attr("data-name")]
644 while(theClass.indexOf("module")==-1){
645 obj = $(obj).parent();
646 if(obj.prop("tagName")=="UL") continue;
647 var parName = obj.attr("data-name");
648 parents.unshift(parName);
649 theClass = obj.attr("class");
651 if($("span[id='pageType']").attr("data-type")=="pset"){
652 var result = getInnerpsetParams(parents);
654 else var result = getInnerParams(parents);
655 addParams(this, result);
658 $(this).children('ul').toggle();
660 event.stopPropagation();
662 // Needed to stop the propagation of event when it should not be expanded.
663 $(document).on('click', '.param',function(event){
664 if($(this).find('ul').length >0){
665 $(this).find('ul').toggle();
667 event.stopPropagation();
670 Removes children from expanded paths or modules.
672 $(document).on('click', '.path.expanded, .module.expanded',function(event){
673 removeChildren(this,event);
676 // Toggles class names.
677 $(document).on('click','.expand, .expanded', function(event){
678 toggleExpand(this, event);
681 Does matching for top level list elements.
682 Returns number of matches.
684 function topLevelMatch(list, reg, haveLIs){
686 for(var p=0; p < list.length; p++){
689 var item = li.attr('data-name');
693 var li= $('li[name='+item+']');
695 if(num=item.match(reg)){
696 numFound +=num.length;
697 li.html(li.html().replace(reg, "<em>$1</em>"));
706 Removes highlights from selector, removes also children
707 if rmChildren == true.
709 function reset(selector, e, rmChildren){
710 var rm = new RegExp('<em>|</em>', 'g');
711 $(selector).each(function(i){
712 var html = $(this).html();
714 $(this).html(html.replace(rm, ''));
719 if(rmChildren)if(removeChildren(this, e))toggleExpand(this, e);});
722 Removes children from parent.
724 function removeChildren(parent, event){
725 var c = $(parent).children('ul');
728 event.stopPropagation();
734 Helper function toggles classes.
736 function toggleExpand(me,event){
737 $(me).toggleClass("expanded expand");
738 event.stopPropagation();
745 cssFile= open(thecss,
'w')
749 background-color: rgb(255,255,0);
771 list-style-type:none;
779 .expanded:before, .param:before{
784 .expand, .expanded, .param{
792 Do Module Objects e.g. producers etc
795 def doModules(modObj, dataFile, seq, seqs, currentName, innerSeq):
796 name = modObj.label_()
797 typ = re.sub(
"<|>|'",
"", str(type(modObj))).
split(
".")[-1]
798 if(seq==0):allMods.append(name)
799 elif(
not innerSeq
and currentName
not in allMods):
800 allMods.append(currentName)
801 if(name
not in modsNames):
802 theList =
do(modObj.parameters_(), [])
803 modsNames.append(name)
804 newModsNames.append(name)
805 filename = modObj._filename.split(
"/")[-1]
807 if(len(modsNames) > 1): theS=
","
810 dataFile.write(theS%(name, d))
812 seqs[currentName].
append(name)
831 if(isinstance(value,cms._Module)):
834 if(isinstance(value,cms.Sequence)):
845 if(isinstance(value,cms.Sequence)):
847 if(name
in self.
oldNames):self.oldNames.remove(name)
850 if(name
not in self.
done):
852 re.sub(
"<|>|'",
"", str(type(value))).
split(
".")[-1],
"")
853 self.df.write(
",%s:%s"%(name,d))
854 self.done.append(name)
861 d[
"parameters"] = params
867 Prints out inner details of parameters.
872 if(hasattr(thing,
"parameters_")):
874 theList.append(
"%s(%s)"%(item,thing.configTypeName()))
876 theList.append(
do(getattr(thing,
"parameters_")(),[]))
878 elif(thing.configTypeName()==
"VPSet"):
880 theList.append(
"%s(%s)"%(item,thing.configTypeName()))
884 if(hasattr(popped,
"parameters_")):
886 innerList.append(
"(%s)"%(popped.configTypeName()))
887 innerList.append(
do(getattr(popped,
"parameters_")(),[]))
888 li2.append(innerList)
897 theType = thing.configTypeName()
898 if(hasattr(thing,
"pop")
and len(thing)>0):
899 value =
"%s"% (
",".
join(str(li)
for li
in thing))
901 value = thing.configValue()
902 theList.append(value)
904 if(theType ==
"double" or theType ==
"int"):
905 theList.append(theType)
907 if(thing.isTracked()):
908 theList.append(theType)
909 theList.append(
"tracked")
913 if __name__ ==
"__main__":
914 parser = OptionParser(usage=
"%prog <cfg-file> <html-file>")
916 parser.add_option(
"-c",
"--cfg_file", dest=
"_cfgfile",
917 help=
"The configuration file.")
918 parser.add_option(
"-o",
"--html_file", dest=
"_htmlfile",
919 help=
"The output html file.")
920 opts, args = parser.parse_args()
921 cfg, html = opts._cfgfile, opts._htmlfile
923 cfgGet, htmlGet =
False,
False
931 parser.error(
"Please provide one and only one configuration"\
932 "file and one output file.")
933 if(cfgGet): cfg = args[0]
934 if(htmlGet): html = args[1]
938 parser.error(
"File %s does not exist." % cfg)
def visit
Retrieve data from a perf suite output (sub) directory, only examines TimeSize at the moment...
static std::string join(char **cmd)