1 |
import imp, sys
|
2 |
import traceback
|
3 |
import common
|
4 |
from crab_exceptions import *
|
5 |
from crab_logger import Logger
|
6 |
|
7 |
|
8 |
class ValidateCfg:
|
9 |
def __init__(self, args):
|
10 |
|
11 |
self.pset = args.get('pset','0')
|
12 |
if self.pset == '0' or self.pset.upper() == 'NONE' :
|
13 |
msg = 'Error: Any configuration file has been specified.'
|
14 |
raise CrabException(msg)
|
15 |
|
16 |
def run(self):
|
17 |
|
18 |
if self.pset.endswith('py'):
|
19 |
self.DumpPset()
|
20 |
else:
|
21 |
self.IncludePset()
|
22 |
|
23 |
return
|
24 |
|
25 |
def ImportFile( self ):
|
26 |
"""
|
27 |
Read in Pset object
|
28 |
"""
|
29 |
common.logger.message( "Importing file %s"%self.pset)
|
30 |
handle = open(self.pset, 'r')
|
31 |
|
32 |
try:
|
33 |
cfo = imp.load_source("pycfg", self.pset, handle)
|
34 |
cmsProcess = cfo.process
|
35 |
except Exception, ex:
|
36 |
goodcfg = False
|
37 |
msg = "%s file is not valid python: %s" % (self.pset,str(ex))
|
38 |
raise CrabException( msg )
|
39 |
handle.close()
|
40 |
return cmsProcess
|
41 |
|
42 |
def DumpPset( self ):
|
43 |
"""
|
44 |
"""
|
45 |
cmsProcess = self.ImportFile()
|
46 |
|
47 |
common.logger.message( 'Starting the dump.....' )
|
48 |
try:
|
49 |
cmsProcess.dumpPython()
|
50 |
except Exception, ex:
|
51 |
msg = "....dumpPython failed : \n\t%s" % str(traceback.format_exc())
|
52 |
raise CrabException( msg )
|
53 |
msg = "....dumpPython succeded\n"
|
54 |
common.logger.message( msg )
|
55 |
|
56 |
def IncludePset(self):
|
57 |
"""
|
58 |
"""
|
59 |
from FWCore.ParameterSet.Config import include
|
60 |
common.logger.message( 'Starting include.....' )
|
61 |
try:
|
62 |
cfo = include(self.pset)
|
63 |
except Exception, ex:
|
64 |
msg = '....include failed with error: \n\t %s'%str(traceback.format_exc())
|
65 |
raise CrabException(msg)
|
66 |
msg = "....include succeded\n"
|
67 |
common.logger.message( msg )
|
68 |
|
69 |
|
70 |
if __name__ == '__main__' :
|
71 |
|
72 |
pset = sys.argv[1]
|
73 |
check = CheckPset(pset)
|
74 |
check.Dump()
|