Raise an exception if called by special config files. This checks
the call or import stack for the importing file. An exception is raised if
the importing module is not in allowedPatterns and if it is called too deeply:
minLevel = 2: inclusion by top lvel cfg only
minLevel = 1: No inclusion allowed
allowedPatterns = ['Module1','Module2/SubModule1'] allows import
by any module in Module1 or Submodule1
Definition at line 27 of file Config.py.
00028 :
00029 """
00030 Raise an exception if called by special config files. This checks
00031 the call or import stack for the importing file. An exception is raised if
00032 the importing module is not in allowedPatterns and if it is called too deeply:
00033 minLevel = 2: inclusion by top lvel cfg only
00034 minLevel = 1: No inclusion allowed
00035 allowedPatterns = ['Module1','Module2/SubModule1'] allows import
00036 by any module in Module1 or Submodule1
00037 """
00038
00039 import inspect
00040 import os
00041
00042 ignorePatterns = ['FWCore/ParameterSet/Config.py','<string>']
00043 CMSSWPath = [os.environ['CMSSW_BASE'],os.environ['CMSSW_RELEASE_BASE']]
00044
00045
00046 trueStack = []
00047 for item in inspect.stack():
00048 inPath = False
00049 ignore = False
00050
00051 for pattern in CMSSWPath:
00052 if item[1].find(pattern) != -1:
00053 inPath = True
00054 break
00055 if item[1].find('/') == -1:
00056 inPath = True
00057
00058 for pattern in ignorePatterns:
00059 if item[1].find(pattern) != -1:
00060 ignore = True
00061 break
00062
00063 if inPath and not ignore:
00064 trueStack.append(item[1])
00065
00066 importedFile = trueStack[0]
00067 importedBy = ''
00068 if len(trueStack) > 1:
00069 importedBy = trueStack[1]
00070
00071 for pattern in allowedPatterns:
00072 if importedBy.find(pattern) > -1:
00073 return True
00074
00075 if len(trueStack) <= minLevel:
00076 return True
00077
00078 raise ImportError("Inclusion of %s is allowed only by cfg or specified cfi files."
00079 % importedFile)