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 1384 of file cfg-viewer.py.

Referenced by main().

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

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

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

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

Definition at line 439 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().

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

Definition at line 515 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().

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

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

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

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

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

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

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

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