CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Public Attributes
pkg.AbstractPkg Class Reference
Inheritance diagram for pkg.AbstractPkg:

Public Member Functions

def __init__
 
def generate
 
def get_kwds
 
def parse_etags
 
def print_etags
 
def print_tags
 
def tmpl_etags
 
def tmpl_tags
 
def write
 

Public Attributes

 author
 
 config
 
 date
 
 debug
 
 not_in_dir
 
 pname
 
 rcsid
 
 tdir
 
 tmpl
 

Detailed Description

AbstractPkg takes care how to generate code from template/PKG
package area. The PKG can be any directory which may include
any types of files, e.g. C++ (.cc), python (.py), etc.
This class relies on specific logic which we outline here:

    - each template may use tags defined with double underscores
      enclosure, e.g. __class__, __record__, etc.
    - each template may have example tags, such tags should
      start with @example_. While processing template user may
      choose to strip them off or keep the code behind those tags
    - in addition user may specify pure python code which can
      operate with user defined tags. This code snipped should
      be enclosed with #python_begin and #python_end lines
      which declares start and end of python block

Definition at line 21 of file pkg.py.

Constructor & Destructor Documentation

def pkg.AbstractPkg.__init__ (   self,
  config = None 
)

Definition at line 38 of file pkg.py.

38 
39  def __init__(self, config=None):
40  super(AbstractPkg, self).__init__()
41  if not config:
42  self.config = {}
43  else:
44  self.config = config
45  self.pname = self.config.get('pname', None)
46  self.tmpl = self.config.get('tmpl', None)
47  self.debug = self.config.get('debug', 0)
48  self.tdir = self.config.get('tmpl_dir')
49  self.author = user_info(self.config.get('author', None))
50  self.date = time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime())
51  self.rcsid = '$%s$' % 'Id' # CVS commit is too smart
52  self.not_in_dir = self.config.get('not_in_dir', [])
def __init__
Definition: pkg.py:38
def user_info
Definition: utils.py:96

Member Function Documentation

def pkg.AbstractPkg.generate (   self)

Definition at line 160 of file pkg.py.

References CSCRPCData.debug, DTDigiToRawModule.debug, CSCTMBScope.debug, ALIUtils.debug, CSCDCCUnpacker.debug, BxNumberFilter.debug, EgammaProbeSelector.debug, DTDigiToRaw.debug, DTTTrigCorrectionFirst.debug, CSCDCCEventData.debug, pkg.AbstractPkg.debug, DTSegmentsTask.debug, DTDDUUnpacker.debug, IsolatedParticlesGeneratedJets.debug, SiPixelDigiToRaw.debug, DTTriggerCheck.debug, DTTPDeadWriter.debug, SiPixelRawToDigi.debug, DTTTrigWriter.debug, DTT0Calibration.debug, DTT0CalibrationNew.debug, DTOccupancyPoint.debug, DTEfficiencyTask.debug, HCALResponse.debug, LumiblockFilter.debug, DTNoiseComputation.debug, DTRunConditionVar.debug, CSCDDUEventData.debug, DTROS25Unpacker.debug, DTTTrigSyncT0Only.debug, DTAlbertoBenvenutiTask.debug, DTTTrigCalibration.debug, DTDigiForNoiseTask.debug, CSCCLCTData.debug, DTChamberEfficiencyTask.debug, DTChamberEfficiency.debug, DTTMax.debug, PixelDataFormatter.debug, CSCTMBData.debug, DTVDriftCalibration.debug, DTNoiseTest.debug, DTTTrigSyncFromDB.debug, DTTTrigSyncTOFCorr.debug, CSCALCTTrailer.debug, CSCEventData.debug, CSCTMBHeader.debug, BaseParticlePropagator.debug, CSCALCTHeader.debug, RPCEfficiency.debug, AlCaHOCalibProducer.debug, RPCEfficiencySecond.debug, spr.find(), pkg.AbstractPkg.get_kwds(), join(), pkg.AbstractPkg.not_in_dir, pkg.AbstractPkg.pname, linker.replace(), split, pkg.AbstractPkg.tdir, pkg.AbstractPkg.tmpl, diffTreeTool.tree, ora::PVectorWriter.write(), pos::PixelConfig.write(), FileBlob.write(), ora::IBlobStreamingService.write(), AlignmentCorrelationsIO.write(), edm::RunLumiEntryInfo.write(), edm::AsciiOutputModule.write(), edm::EventEntryInfo.write(), ora::IRelationalWriter.write(), AlignmentCorrelationsIORoot.write(), SurveyOutput.write(), ora::QueryableVectorWriter.write(), cond::BlobStreamingService.write(), MultiFileBlob.write(), ExTestEcalChannelStatusAnalyzer.write(), edm::ConstBranchDescription.write(), EcalUnpackerWorkerBase.write(), HcalTimingParamsPopConAnalyzer.write(), HcalValidationCorrsPopConAnalyzer.write(), KalmanAlignmentDataCollector.write(), HcalLutMetadataPopConAnalyzer.write(), HcalPFCorrsPopConAnalyzer.write(), HcalGainWidthsPopConAnalyzer.write(), HcalChannelQualityPopConAnalyzer.write(), CastorElectronicsMapPopConAnalyzer.write(), HcalZSThresholdsPopConAnalyzer.write(), CastorSaturationCorrsPopConAnalyzer.write(), ora::CArrayWriter.write(), ora::OraPtrWriter.write(), HcalTimeCorrsPopConAnalyzer.write(), HcalRecoParamsPopConAnalyzer.write(), HcalDcsValuesPopConAnalyzer.write(), CastorChannelQualityPopConAnalyzer.write(), CastorGainsPopConAnalyzer.write(), CastorGainWidthsPopConAnalyzer.write(), CastorPedestalsPopConAnalyzer.write(), CastorQIEDataPopConAnalyzer.write(), CastorRecoParamsPopConAnalyzer.write(), cond::TBufferBlobStreamingService.write(), HcalCholeskyMatricesPopConAnalyzer.write(), HcalCovarianceMatricesPopConAnalyzer.write(), HcalDcsMapPopConAnalyzer.write(), CastorPedestalWidthsPopConAnalyzer.write(), HcalElectronicsMapPopConAnalyzer.write(), HcalRespCorrsPopConAnalyzer.write(), HcalFlagHFDigiTimeParamsPopConAnalyzer.write(), HcalPedestalWidthsPopConAnalyzer.write(), HcalGainsPopConAnalyzer.write(), HcalL1TriggerObjectsPopConAnalyzer.write(), HcalLongRecoParamsPopConAnalyzer.write(), HcalLUTCorrsPopConAnalyzer.write(), HcalMCParamsPopConAnalyzer.write(), HcalPedestalsPopConAnalyzer.write(), HcalQIEDataPopConAnalyzer.write(), edm::RunAuxiliary.write(), edm::Parentage.write(), edm::ProvenanceCheckerOutputModule.write(), ora::UniqueRefWriter.write(), edm::EventEntryDescription.write(), AlignmentParametersIO.write(), ESUnpackerWorker.write(), AlignmentUserVariablesIO.write(), edm::LuminosityBlockAuxiliary.write(), SiPixelConfigWriter.write(), edm::GetProductCheckerOutputModule.write(), ora::STLContainerWriter.write(), edm::ProductProvenance.write(), popcon::PopConAnalyzer< S >.write(), SiStripConfigWriter.write(), ora::ObjectWriter.write(), EcalUnpackerWorker.write(), MuonAlignmentOutputXML.write(), ora::PrimitiveWriter.write(), edm::ModuleDescription.write(), electronCompare.flushfile.write(), stor::DbFileHandler.write(), ora::OraReferenceWriter.write(), ora::InlineCArrayWriter.write(), electronStore.flushfile.write(), ora::DependentClassWriter.write(), ora::BlobWriter.write(), popcon::PopCon.write(), CSCPairResidualsConstraint.write(), edm::EventAuxiliary.write(), DDStreamer.write(), edmplugin::CacheParser.write(), ora::NamedRefWriter.write(), XMLDOMBlock.write(), ora::ITokenWriter.write(), Benchmark.write(), XMLDocument.write, edm::BranchDescription.write(), stor::DQMEventConsumerRegistrationInfo.write(), stor::EventConsumerRegistrationInfo.write(), edm::Provenance.write(), MuonResidualsTwoBin.write(), edm::FileInPath.write(), pkg.AbstractPkg.write(), cond::PoolTokenWriter.write(), edm::ProductHolderBase.write(), XMLProcessor.write(), DQMRootOutputModule.write(), RPCDBPopConAnalyzer.write(), edm::OutputModule.write(), edm::SubProcess.write(), and MuonResidualsFitter.write().

161  def generate(self):
162  "Generate package templates in a given directory"
163 
164  # keep current location, since generate will switch directories
165  cdir = os.getcwd()
166 
167  # read from configutation which template files to create
168  tmpl_files = self.config.get('tmpl_files', 'all')
169 
170  # setup keyword arguments which we'll pass to write method
171  kwds = self.get_kwds()
172 
173  # create template package dir and cd into it
174  if tmpl_files == 'all' and self.tmpl not in self.not_in_dir:
175  if os.path.isdir(self.pname):
176  msg = "Can't create package '%s'\n" % self.pname
177  msg += "Directory %s is already exists" % self.pname
178  print msg
179  sys.exit(1)
180  os.makedirs(self.pname)
181  os.chdir(self.pname)
182 
183  # read directory driver information and create file list to generate
184  sdir = os.path.join(self.tdir, self.tmpl)
185  sources = [s for s in os.listdir(sdir) \
186  if s != 'Driver.dir' and s.find('~') == -1]
187  driver = os.path.join(sdir, 'Driver.dir')
188  if os.path.isfile(driver):
189  sources = [s.replace('\n', '') for s in open(driver, 'r').readlines()]
190  if 'CVS' in sources:
191  sources.remove('CVS')
192 
193  # special case of Skeleton, which requires to generate only given
194  # file type if self.pname has extension of that type
195  names = set([s.split('.')[0] for s in sources])
196  if names == set(['Skeleton']):
197  if self.pname.find('.') != -1:
198  _, ext = os.path.splitext(self.pname)
199  sources = [s for s in sources if s.rfind(ext) != -1]
200  self.pname = self.pname.replace(ext, '')
201  kwds = self.get_kwds()
202  if not sources:
203  msg = 'Unable to find skeleton for extension "%s"' % ext
204  print msg
205  sys.exit(1)
206  bdir = os.environ.get('CMSSW_BASE', '')
207  dirs = os.getcwd().replace(bdir, '').split('/')
208  ldir = os.getcwd().split('/')[-1]
209  idir = ''
210  subsys = kwds['__subsys__']
211  pkgname = kwds['__pkgname__']
212  if sources == ['Skeleton.cc', 'Skeleton.h']:
213  if ldir == 'interface' and os.getcwd().find(bdir) != -1:
214  idir = '%s/%s/interface/' % (subsys, pkgname)
215  # run within some directory of the Sybsystem/Pkg area
216  # and only for mkskel <file>.cc
217  elif sources == ['Skeleton.cc'] and \
218  len(dirs) == 5 and dirs[0] == '' and dirs[1] == 'src':
219  idir = '%s/%s/interface/' % (subsys, pkgname)
220  elif sources == ['Skeleton.h'] and ldir == 'interface' and \
221  len(dirs) == 5 and dirs[0] == '' and dirs[1] == 'src':
222  idir = '%s/%s/interface/' % (subsys, pkgname)
223  kwds.update({'__incdir__': idir})
224 
225  # loop over source files, create dirs as necessary and generate files
226  # names for writing templates
227  gen_files = []
228  for src in sources:
229  if tmpl_files != 'all':
230  fname, ext = os.path.splitext(src)
231  if tmpl_files != ext:
232  continue
233  src = src.split('/')[-1]
234  if self.debug:
235  print "Read", src
236  items = src.split('/')
237  if items[-1] == '/':
238  items = items[:-1]
239  tname = items[-1] # template file name
240  tmpl_name = os.path.join(sdir, items[-1]) # full tmpl file name
241  if os.path.isfile(tmpl_name):
242  ftype = 'file'
243  else:
244  ftype = 'dir'
245  name2gen = src # new file we'll create
246  if tname.split('.')[0] == self.tmpl: # need to substitute
247  name2gen = name2gen.replace(self.tmpl, self.pname)
248  name2gen = os.path.join(os.getcwd(), name2gen)
249  if self.debug:
250  print "Create", name2gen
251  if ftype == 'dir':
252  if not os.path.isdir(name2gen):
253  os.makedirs(name2gen)
254  continue # we're done with dir
255  fdir = os.path.dirname(name2gen)
256  if not os.path.isdir(fdir):
257  os.makedirs(fdir)
258  self.write(name2gen, tmpl_name, kwds)
259  gen_files.append(name2gen.split('/')[-1])
260  if tmpl_files == 'all' and self.tmpl not in self.not_in_dir:
261  msg = 'New package "%s" of %s type is successfully generated' \
262  % (self.pname, self.tmpl)
263  else:
264  msg = 'Generated %s file' % ', '.join(gen_files)
265  if len(gen_files) > 1:
266  msg += 's'
267  print msg
268  # return back where we started
269  os.chdir(cdir)
270  if msg.find('New package') != -1:
271  tree(self.pname)
def write
Definition: pkg.py:116
def replace
Definition: linker.py:10
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def get_kwds
Definition: pkg.py:143
def generate
Definition: pkg.py:160
double split
Definition: MVATrainer.cc:139
def pkg.AbstractPkg.get_kwds (   self)

Definition at line 143 of file pkg.py.

References pkg.AbstractPkg.author, pkg.AbstractPkg.date, CSCRPCData.debug, DTDigiToRawModule.debug, CSCTMBScope.debug, CSCDCCUnpacker.debug, ALIUtils.debug, BxNumberFilter.debug, EgammaProbeSelector.debug, DTDigiToRaw.debug, CSCDCCEventData.debug, DTTTrigCorrectionFirst.debug, pkg.AbstractPkg.debug, DTSegmentsTask.debug, DTDDUUnpacker.debug, IsolatedParticlesGeneratedJets.debug, SiPixelDigiToRaw.debug, DTTPDeadWriter.debug, DTTriggerCheck.debug, SiPixelRawToDigi.debug, DTTTrigWriter.debug, DTT0Calibration.debug, DTT0CalibrationNew.debug, DTOccupancyPoint.debug, DTEfficiencyTask.debug, HCALResponse.debug, LumiblockFilter.debug, DTNoiseComputation.debug, CSCDDUEventData.debug, DTRunConditionVar.debug, DTROS25Unpacker.debug, DTAlbertoBenvenutiTask.debug, DTTTrigSyncT0Only.debug, DTTTrigCalibration.debug, DTDigiForNoiseTask.debug, CSCCLCTData.debug, DTChamberEfficiencyTask.debug, DTChamberEfficiency.debug, DTTMax.debug, PixelDataFormatter.debug, CSCTMBData.debug, DTNoiseTest.debug, DTVDriftCalibration.debug, DTTTrigSyncFromDB.debug, DTTTrigSyncTOFCorr.debug, CSCALCTTrailer.debug, CSCEventData.debug, CSCTMBHeader.debug, BaseParticlePropagator.debug, CSCALCTHeader.debug, RPCEfficiency.debug, AlCaHOCalibProducer.debug, RPCEfficiencySecond.debug, pkg.AbstractPkg.pname, and pkg.AbstractPkg.rcsid.

Referenced by pkg.AbstractPkg.generate().

144  def get_kwds(self):
145  "Return keyword arguments to be used in methods"
146  kwds = {'__pkgname__': self.config.get('pkgname', 'Package'),
147  '__author__': self.author,
148  '__user__': os.getlogin(),
149  '__date__': self.date,
150  '__class__': self.pname,
151  '__name__': self.pname,
152  '__rcsid__': self.rcsid,
153  '__subsys__': self.config.get('subsystem', 'Subsystem')}
154  args = self.config.get('args', None)
155  kwds.update(args)
156  if self.debug:
157  print "Template tags:"
158  pprint.pprint(kwds)
159  return kwds
def get_kwds
Definition: pkg.py:143
def pkg.AbstractPkg.parse_etags (   self,
  line 
)
Determine either skip or keep given line based on class tags 
meta-strings

Definition at line 96 of file pkg.py.

References pkg.AbstractPkg.tmpl_etags().

Referenced by pkg.AbstractPkg.write().

96 
97  def parse_etags(self, line):
98  """
99  Determine either skip or keep given line based on class tags
100  meta-strings
101  """
102  tmpl_etags = self.tmpl_etags()
103  keep_etags = self.config.get('tmpl_etags', [])
104  for tag in tmpl_etags:
105  if keep_etags:
106  for valid_tag in keep_etags:
107  if line.find(valid_tag) != -1:
108  line = line.replace(valid_tag, '')
109  return line
110  else:
111  if line.find(tag) != -1:
112  line = line.replace(tag, '')
113  line = ''
114  return line
115  return line
def tmpl_etags
Definition: pkg.py:53
def parse_etags
Definition: pkg.py:96
def pkg.AbstractPkg.print_etags (   self)

Definition at line 70 of file pkg.py.

References pkg.AbstractPkg.tmpl_etags().

70 
71  def print_etags(self):
72  "Print out template example tags"
73  for key in self.tmpl_etags():
74  print key
def tmpl_etags
Definition: pkg.py:53
def print_etags
Definition: pkg.py:70
def pkg.AbstractPkg.print_tags (   self)

Definition at line 91 of file pkg.py.

References pkg.AbstractPkg.tmpl_tags().

91 
92  def print_tags(self):
93  "Print out template keys"
94  for key in self.tmpl_tags():
95  print key
def tmpl_tags
Definition: pkg.py:75
def print_tags
Definition: pkg.py:91
def pkg.AbstractPkg.tmpl_etags (   self)

Definition at line 53 of file pkg.py.

References pkg.AbstractPkg.tdir, and pkg.AbstractPkg.tmpl.

Referenced by pkg.AbstractPkg.parse_etags(), and pkg.AbstractPkg.print_etags().

53 
54  def tmpl_etags(self):
55  "Scan template files and return example tags"
56  keys = []
57  sdir = '%s/%s' % (self.tdir, self.tmpl)
58  for name in os.listdir(sdir):
59  if name[-1] == '~':
60  continue
61  if name == 'CVS':
62  continue
63  fname = os.path.join(sdir, name)
64  with open(fname, 'r') as stream:
65  for line in stream.readlines():
66  if line.find('@example_') != -1: # possible tag
67  keys += [k for k in line.split() if \
68  k.find('@example_') != -1]
69  return set(keys)
def tmpl_etags
Definition: pkg.py:53
def pkg.AbstractPkg.tmpl_tags (   self)

Definition at line 75 of file pkg.py.

References utils.parse_word(), pkg.AbstractPkg.tdir, and pkg.AbstractPkg.tmpl.

Referenced by pkg.AbstractPkg.print_tags().

75 
76  def tmpl_tags(self):
77  "Scan template files and return template tags"
78  keys = []
79  sdir = '%s/%s' % (self.tdir, self.tmpl)
80  for name in os.listdir(sdir):
81  if name[-1] == '~':
82  continue
83  if name == 'CVS':
84  continue
85  fname = os.path.join(sdir, name)
86  with open(fname, 'r') as stream:
87  for line in stream.readlines():
88  if line.find('__') != -1: # possible key
89  keys += [k for k in parse_word(line)]
90  return set(keys)
def parse_word
Definition: utils.py:21
def tmpl_tags
Definition: pkg.py:75
def pkg.AbstractPkg.write (   self,
  fname,
  tmpl_name,
  kwds 
)

Definition at line 116 of file pkg.py.

References CSCRPCData.debug, DTDigiToRawModule.debug, CSCTMBScope.debug, CSCDCCUnpacker.debug, ALIUtils.debug, BxNumberFilter.debug, DTDigiToRaw.debug, EgammaProbeSelector.debug, DTTTrigCorrectionFirst.debug, CSCDCCEventData.debug, pkg.AbstractPkg.debug, DTDDUUnpacker.debug, DTSegmentsTask.debug, IsolatedParticlesGeneratedJets.debug, SiPixelDigiToRaw.debug, DTTPDeadWriter.debug, DTTriggerCheck.debug, SiPixelRawToDigi.debug, DTTTrigWriter.debug, DTT0Calibration.debug, DTT0CalibrationNew.debug, DTOccupancyPoint.debug, DTEfficiencyTask.debug, HCALResponse.debug, LumiblockFilter.debug, DTNoiseComputation.debug, CSCDDUEventData.debug, DTRunConditionVar.debug, DTROS25Unpacker.debug, DTAlbertoBenvenutiTask.debug, DTTTrigSyncT0Only.debug, DTTTrigCalibration.debug, DTDigiForNoiseTask.debug, CSCCLCTData.debug, DTChamberEfficiencyTask.debug, DTChamberEfficiency.debug, DTTMax.debug, PixelDataFormatter.debug, CSCTMBData.debug, DTVDriftCalibration.debug, DTNoiseTest.debug, DTTTrigSyncFromDB.debug, DTTTrigSyncTOFCorr.debug, CSCALCTTrailer.debug, CSCEventData.debug, CSCTMBHeader.debug, BaseParticlePropagator.debug, CSCALCTHeader.debug, RPCEfficiency.debug, AlCaHOCalibProducer.debug, RPCEfficiencySecond.debug, utils.functor(), and pkg.AbstractPkg.parse_etags().

Referenced by pkg.AbstractPkg.generate().

117  def write(self, fname, tmpl_name, kwds):
118  "Create new file from given template name and set of arguments"
119  code = ""
120  read_code = False
121  with open(fname, 'w') as stream:
122  for line in open(tmpl_name, 'r').readlines():
123  line = self.parse_etags(line)
124  if not line:
125  continue
126  if line.find('#python_begin') != -1:
127  read_code = True
128  continue
129  if line.find('#python_end') != -1:
130  read_code = False
131  if read_code:
132  code += line
133  if code and not read_code:
134  res = functor(code, kwds, self.debug)
135  stream.write(res)
136  code = ""
137  continue
138  if not read_code:
139  for key, val in kwds.items():
140  if isinstance(val, basestring):
141  line = line.replace(key, val)
142  stream.write(line)
def write
Definition: pkg.py:116
def parse_etags
Definition: pkg.py:96
def functor
Definition: utils.py:54

Member Data Documentation

pkg.AbstractPkg.author

Definition at line 48 of file pkg.py.

Referenced by pkg.AbstractPkg.get_kwds().

pkg.AbstractPkg.config

Definition at line 41 of file pkg.py.

pkg.AbstractPkg.date

Definition at line 49 of file pkg.py.

Referenced by pkg.AbstractPkg.get_kwds().

pkg.AbstractPkg.debug

Definition at line 46 of file pkg.py.

Referenced by pkg.AbstractPkg.generate(), pkg.AbstractPkg.get_kwds(), and pkg.AbstractPkg.write().

pkg.AbstractPkg.not_in_dir

Definition at line 51 of file pkg.py.

Referenced by pkg.AbstractPkg.generate().

pkg.AbstractPkg.pname

Definition at line 44 of file pkg.py.

Referenced by pkg.AbstractPkg.generate(), and pkg.AbstractPkg.get_kwds().

pkg.AbstractPkg.rcsid

Definition at line 50 of file pkg.py.

Referenced by pkg.AbstractPkg.get_kwds().

pkg.AbstractPkg.tdir

Definition at line 47 of file pkg.py.

Referenced by pkg.AbstractPkg.generate(), pkg.AbstractPkg.tmpl_etags(), and pkg.AbstractPkg.tmpl_tags().

pkg.AbstractPkg.tmpl

Definition at line 45 of file pkg.py.

Referenced by pkg.AbstractPkg.generate(), pkg.AbstractPkg.tmpl_etags(), and pkg.AbstractPkg.tmpl_tags().