CMS 3D CMS Logo

Public Member Functions | Static Public Attributes

JSONExport::JsonExport Class Reference

Inherits FWCore::GuiBrowsers::FileExportPlugin::FileExportPlugin.

List of all members.

Public Member Functions

def __init__
def export
def produce

Static Public Attributes

tuple file_types = ('html','json')
dictionary option_types = {}
string plugin_name = 'JSON Export'

Detailed Description

Definition at line 15 of file JSONExport.py.


Constructor & Destructor Documentation

def JSONExport::JsonExport::__init__ (   self)

Definition at line 19 of file JSONExport.py.

00020                     :
00021     FileExportPlugin.__init__(self)


Member Function Documentation

def JSONExport::JsonExport::export (   self,
  data,
  filename,
  filetype 
)

Definition at line 136 of file JSONExport.py.

00137                                          :
00138     if not data.process():
00139       raise "JSONExport requires a cms.Process object"
00140       
00141     json = self.produce(data)
00142     
00143     if filetype=='json':
00144       jsonfile = open(filename,'w')
00145       jsonfile.write(json)
00146       jsonfile.close()
00147     if filetype=='html':
00148       #open the HTML template and inject the JSON...
00149       pass
00150       
def JSONExport::JsonExport::produce (   self,
  data 
)

Definition at line 22 of file JSONExport.py.

00023                         :
00024     
00025     #pset = lambda pdict: [[k,repr(v).split('(',1)[0],(repr(v).split('(',1)[1][:-1])] for k,v in pdict.items()]
00026     def pset(pdict):
00027       result = []
00028       for k,v in pdict.items():
00029         if v.pythonTypeName()=='cms.PSet' or v.pythonTypeName()=='cms.untracked.PSet':
00030           result.append([k,v.pythonTypeName(),'pset',pset(v.parameters_())])
00031         elif v.pythonTypeName()=='cms.VPSet' or v.pythonTypeName()=='cms.untracked.VPSet':
00032           result.append([k,v.pythonTypeName(),'vpset',[pset(a.parameters_()) for a in v]])
00033         elif v.pythonTypeName().lower().startswith('cms.v') or v.pythonTypeName().lower().startswith('cms.untracked.v'):
00034           result.append([k,v.pythonTypeName(),'list',[repr(a) for a in v]])
00035         else:
00036           result.append([k,v.pythonTypeName(),'single',repr(v.pythonValue())])
00037       return result
00038           
00039     #allObjects = [d for d in data._allObjects if (data.type(d) in ("EDProducer","EDFilter","EDAnalyzer","OutputModule"))]
00040     #data.readConnections(allObjects)
00041         
00042     def moduledict(mod,prefix,links=False):
00043       result={}
00044       result['label']=data.label(mod)
00045       result['class']=data.classname(mod)
00046       result['file']=data.pypath(mod)
00047       result['line']=data.lineNumber(mod)
00048       result['package']=data.pypackage(mod)
00049       result['pset']=pset(mod.parameters_())
00050       result['type']=data.type(mod)
00051       if links:
00052         result['uses']=[data.uses(mod)]
00053         result['usedby']=[data.usedBy(mod)]
00054       result['id']='%s_%s'%(prefix,data.label(mod))
00055       return result
00056       
00057     all={}
00058     for tlo in data.topLevelObjects():
00059       children=data.children(tlo)
00060       if children:
00061         all[tlo._label]=children
00062       
00063     process = {'name':data.process().name_(),'src':data._filename}
00064     
00065     #now unavailable  
00066     #schedule = []
00067     #if 'Schedule' in all:
00068     #  for s in all['Schedule']:
00069     #    schedule.append(data.label(s))
00070       
00071     source={}
00072     if 'source' in all:
00073       s = all['source'][0]
00074       source['class']=data.classname(s)
00075       source['pset']=pset(s.parameters_())
00076       
00077     essources=[]
00078     if 'essources' in all:
00079       for e in all['essources']:
00080         essources.append(moduledict(e,'essource'))
00081     esproducers=[]
00082     if 'esproducers' in all:
00083       for e in all['esproducers']:
00084         essources.append(moduledict(e,'esproducer'))
00085     esprefers=[]
00086     if 'esprefers' in all:
00087       for e in all['esprefers']:
00088         essources.append(moduledict(e,'esprefers'))
00089     services=[]
00090     if 'services' in all:
00091       for s in all['services']:
00092         services.append({'class':data.classname(s),'pset':pset(s.parameters_())})    
00093       
00094       
00095     def jsonPathRecursive(p,prefix):
00096       #print "At:",self.label(p),self.type(p)
00097       children = data.children(p)
00098       if children:
00099         children = [jsonPathRecursive(c,prefix) for c in children]
00100         return {'type':'Sequence','label':'Sequence %s'%(data.label(p)),'id':'seq_%s' % data.label(p),'children':children}
00101       else:
00102         return moduledict(p,prefix,True)
00103         
00104           
00105     paths=[]
00106     if 'paths' in all:
00107       for p in all['paths']:
00108         path=jsonPathRecursive(p,data.label(p))
00109         if path:
00110           if not type(path)==type([]):
00111             if path['type']=='Sequence':
00112               path = path['children']
00113             else:
00114               path = [path]
00115         else:
00116           path=[]
00117         paths.append({'label':data.label(p),'path':path})
00118     endpaths=[]
00119     if 'endpaths' in all:
00120       for p in all['endpaths']:
00121         path=jsonPathRecursive(p,data.label(p))
00122         if path:
00123           if not type(path)==type([]):
00124             if path['type']=='Sequence':
00125               path = path['children']
00126             else:
00127               path = [path]
00128         else:
00129           path=[]
00130         endpaths.append({'label':data.label(p),'path':path})
00131       
00132     #json={'process':process,'schedule':schedule,'source':source,'essources':essources,'esproducers':esproducers,'esprefers':esprefers,'services':services,'paths':paths,'endpaths':endpaths}
00133     json={'process':process,'source':source,'essources':essources,'esproducers':esproducers,'esprefers':esprefers,'services':services,'paths':paths,'endpaths':endpaths}
00134       
00135     return repr(json)
    

Member Data Documentation

tuple JSONExport::JsonExport::file_types = ('html','json') [static]

Definition at line 18 of file JSONExport.py.

dictionary JSONExport::JsonExport::option_types = {} [static]

Definition at line 16 of file JSONExport.py.

string JSONExport::JsonExport::plugin_name = 'JSON Export' [static]

Definition at line 17 of file JSONExport.py.