CMS 3D CMS Logo

Classes | Functions
cfg-viewer Namespace Reference

Classes

class  html
 
class  server
 
class  unscheduled
 
class  visitor
 

Functions

def computeConfigs (args)
 
def doTypes (spec, generic)
 
def getParameters (parameters)
 
def getParamSeqDict (params, fil, typ, oType)
 
def JSONFormat (d)
 
def listBase (VList)
 
def main (args, helperDir, htmlFile, quiet, noServer)
 

Function Documentation

def cfg-viewer.computeConfigs (   args)

Definition at line 1385 of file cfg-viewer.py.

Referenced by main().

1385 def computeConfigs(args):
1386  pyList=[]
1387  for x in args:
1388  if(os.path.isdir(x)):
1389  # get all .py files.
1390  allItems = os.listdir(x)
1391  py = [os.path.join(x,y) for y in allItems if y.endswith(".py")]
1392  pyList.extend(computeConfigs(py))
1393  if(recurse):
1394  # print "recurse"
1395  # if we want to recurse, we look for everything
1396  dirs = []
1397  for y in os.listdir(x):
1398  path = os.path.join(x,y)
1399  if(os.path.isdir(path)):
1400  pyList.extend(computeConfigs([os.path.join(path,z)
1401  for z in os.listdir(path)]))
1402  elif(x.endswith(".py")):
1403  pyList.append(x)
1404  return pyList
1405 
1406 recurse=False
1407 
def computeConfigs(args)
Definition: cfg-viewer.py:1385
def cfg-viewer.doTypes (   spec,
  generic 
)

Definition at line 1263 of file cfg-viewer.py.

Referenced by cfg-viewer.unscheduled._checkType(), cfg-viewer.visitor._doModules(), cfg-viewer.visitor.enter(), getParameters(), and listBase().

1263 def doTypes(spec, generic):
1264  genericTypes[spec] = generic
1265 
def doTypes(spec, generic)
Definition: cfg-viewer.py:1263
def cfg-viewer.getParameters (   parameters)

Definition at line 440 of file cfg-viewer.py.

References doTypes(), listBase(), split, and str.

Referenced by cfg-viewer.visitor._doModules(), cfg-viewer.unscheduled._doNonSequenceType(), listBase(), and LMFUnique.setByID().

440 def getParameters(parameters):
441  all =[]
442  if(not parameters):
443  return []
444  for (name,valType) in six.iteritems(parameters):
445  theT= (valType.configTypeName() if(
446  hasattr(valType,"configTypeName")) else "").split(" ",1)[-1]
447  temp = re.sub("<|>|'", "", str(type(valType)))
448  generic, spec = temp.split(".")[-2:]
449  doTypes(spec,generic)
450  theList=[name]
451  if(isinstance(valType,cms._Parameterizable)):
452  theList.append(getParameters(valType.parameters_()))
453  elif(isinstance(valType,cms._ValidatingListBase)):
454  theList.append(listBase(valType))
455  else:
456  if(isinstance(valType,cms._SimpleParameterTypeBase)):
457  value = valType.configValue()
458  else:
459  try:
460  value = valType.pythonValue()
461  except:
462  value = valType
463  theList.append(value)
464  if(theT != "double" and theT !="int" and not isinstance(valType, str)):
465  if(not valType.isTracked()):
466  theList.append("untracked")
467  theList.append(theT)
468  all.append(theList)
469  return all
470 
def getParameters(parameters)
Definition: cfg-viewer.py:440
def doTypes(spec, generic)
Definition: cfg-viewer.py:1263
def listBase(VList)
Definition: cfg-viewer.py:471
#define str(s)
double split
Definition: MVATrainer.cc:139
def cfg-viewer.getParamSeqDict (   params,
  fil,
  typ,
  oType 
)

Definition at line 516 of file cfg-viewer.py.

Referenced by cfg-viewer.visitor._doModules(), cfg-viewer.unscheduled._doNonSequenceType(), cfg-viewer.unscheduled._doSequenceTypes(), cfg-viewer.visitor.enter(), and cfg-viewer.visitor.leave().

516 def getParamSeqDict(params, fil, typ, oType):
517  d={}
518  d[dictFeatures[0]] = params
519  d[dictFeatures[1]] = typ
520  d[dictFeatures[2]] = fil
521  d[dictFeatures[3]] = oType
522  return d
523 
def getParamSeqDict(params, fil, typ, oType)
Definition: cfg-viewer.py:516
def cfg-viewer.JSONFormat (   d)
def cfg-viewer.listBase (   VList)

Definition at line 471 of file cfg-viewer.py.

References doTypes(), getParameters(), join(), and str.

Referenced by cfg-viewer.unscheduled._doNonSequenceType(), and getParameters().

471 def listBase(VList):
472  # we have a list of things..
473  #loop around the list get parameters of inners.
474  #Since ValidatingListBases "*usually* have the same types
475  #throughout, just test first --is this a rule?
476  # Find out and if needed move these ifs to the loop.
477  if(not VList):return ""
478  first = VList[0]
479  if(isinstance(first,cms._Parameterizable)or
480  isinstance(first,cms._ValidatingListBase)):
481  anotherVList=False
482  if(isinstance(first,cms._ValidatingListBase)):
483  anotherVList=True
484  outerList=[]
485  for member in VList:
486  if(member.hasLabel_()):
487  name = member.label()
488  else:
489  name = member.configTypeName()
490  innerList=[name]
491  if(not anotherVList):
492  innerList.append(getParameters(member.parameters_()))
493  else:
494  innerList.append(listBase(member))
495  temp = re.sub("<|>|'", "", str(type(member)))
496  generic, spec = temp.split(".")[-2:]
497  doTypes(spec,generic)
498  innerList.append(spec)
499  outerList.append(innerList)
500  return outerList
501  elif(isinstance(first,cms._SimpleParameterTypeBase)):
502  return ",".join(i.configValue() for i in VList)
503  elif(isinstance(first,cms._ParameterTypeBase)):
504  return ",".join(i.pythonValue() for i in VList)
505  else:
506  #Most things should at least be _ParameterTypeBase, adding this jic
507  try:
508  outcome = ",".join(str(i) for i in VList)
509  return outcome
510  except:
511  return "Unknown types"
512 
513 
514 dictFeatures=["Parameters", "Type", "File", "oType"]
515 # Used to enforce dictionary in datafiles.
def getParameters(parameters)
Definition: cfg-viewer.py:440
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def doTypes(spec, generic)
Definition: cfg-viewer.py:1263
def listBase(VList)
Definition: cfg-viewer.py:471
#define str(s)
def cfg-viewer.main (   args,
  helperDir,
  htmlFile,
  quiet,
  noServer 
)

Definition at line 1408 of file cfg-viewer.py.

References computeConfigs(), join(), edm.print(), and python.rootplot.root2matplotlib.replace().

1408 def main(args,helperDir,htmlFile,quiet, noServer):
1409  dirName = "%s-cfghtml"
1410  # new dir format
1411  # cfgViewer.html
1412  # patTuple-html/
1413  # lower.html
1414  # cfgViewerHelper/
1415  # -json files
1416  pyconfigs = computeConfigs(args)
1417  tmpte = '<li><a href ="%(n)s">%(s)s</a></li>'
1418  lis=""
1419  found =0
1420  for x in pyconfigs:
1421  print("-----")
1422  # for every config file
1423  name = os.path.split(x)[1].replace(".py", "")
1424  dirN = dirName%(name)
1425  # we have the dir name now we only need
1426  # now we have thedir for everything to be stored in
1427  #htmlF = opts._htmlfile
1428  #htmldir= os.path.split(htmlFile)[0]
1429  #baseDir = os.path.join(htmldir,dirN)
1430  baseDir = dirN
1431  dirCreated = False
1432  if not os.path.exists(baseDir):
1433  os.makedirs(baseDir)
1434  dirCreated = True
1435  # base Dir under where the htmlFile will be.
1436  lowerHTML = os.path.join(baseDir, htmlFile)
1437  helper = os.path.join(helperDir, "")
1438  helperdir = os.path.join(baseDir, helper, "")
1439  if not os.path.exists(helperdir):
1440  os.makedirs(helperdir)
1441  print("Calculating", x)
1442  try:
1443  u = unscheduled(x, lowerHTML, quiet, helper,helperdir)
1444  except Exception as e:
1445  print("File %s is a config file but something went wrong"%(x))
1446  print("%s"%(e))
1447  continue
1448  print("Finished with", x)
1449  if(not u._computed and dirCreated):
1450  # remove any directories created
1451  shutil.rmtree(baseDir)
1452  continue
1453  found +=1
1454  lis += tmpte%{"n":os.path.join(dirN,htmlFile),"s":name}
1455  with open("index.html", 'w')as f:
1456  f.write("""
1457 <!DOCTYPE html>
1458 <html>
1459  <head>
1460  <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
1461  <title>cfg-browser</title>
1462  </head>
1463  <body>
1464  <h4>Configuration files:</h4>
1465  <ul>
1466  %s
1467  </ul>
1468  </body>
1469 </html>
1470  """%("".join(lis)))
1471  if(found == 0):
1472  print("Sorry, no configuration files were found.")
1473  return
1474  print("Finished dealing with configuration files.")
1475  server("cfgServer.py")
1476  if(not noServer):
1477  print("-----")
1478  print("Starting the python server..")
1479  import cfgServer
1480  cfgServer.main()
1481 
1482 
def main(args, helperDir, htmlFile, quiet, noServer)
Definition: cfg-viewer.py:1408
def replace(string, replacements)
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:65
def computeConfigs(args)
Definition: cfg-viewer.py:1385
static std::string join(char **cmd)
Definition: RemoteFile.cc:18