43 Raise an exception if called by special config files. This checks 44 the call or import stack for the importing file. An exception is raised if 45 the importing module is not in allowedPatterns and if it is called too deeply: 46 minLevel = 2: inclusion by top lvel cfg only 47 minLevel = 1: No inclusion allowed 48 allowedPatterns = ['Module1','Module2/SubModule1'] allows import 49 by any module in Module1 or Submodule1 55 ignorePatterns = [
'FWCore/ParameterSet/Config.py',
'FWCore/ParameterSet/python/Config.py',
'<string>',
'<frozen ']
56 CMSSWPath = [os.environ[
'CMSSW_BASE'],os.environ[
'CMSSW_RELEASE_BASE']]
60 for item
in inspect.stack():
64 for pattern
in CMSSWPath:
65 if item[1].
find(pattern) != -1:
68 if item[1].
find(
'/') == -1:
71 for pattern
in ignorePatterns:
72 if item[1].
find(pattern) != -1:
76 if inPath
and not ignore:
77 trueStack.append(item[1])
79 importedFile = trueStack[0]
81 if len(trueStack) > 1:
82 importedBy = trueStack[1]
84 for pattern
in allowedPatterns:
85 if importedBy.find(pattern) > -1:
88 if len(trueStack) <= minLevel:
91 raise ImportError(
"Inclusion of %s is allowed only by cfg or specified cfi files." void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
def checkImportPermission(minLevel=2, allowedPatterns=[])