ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/JobDB.py
Revision: 1.14
Committed: Wed Jun 28 00:36:52 2006 UTC (18 years, 10 months ago) by gutsche
Content type: text/x-python
Branch: MAIN
Changes since 1.13: +5 -2 lines
Log Message:
fixed JobDB arguments extraction for CMSSW jobs, no doubling of backslashes

File Contents

# User Rev Content
1 nsmirnov 1.1 from WorkSpace import WorkSpace
2     from crab_exceptions import *
3     import common
4    
5 nsmirnov 1.2 import os, string
6 nsmirnov 1.1
7     class dbEntry:
8     def __init__(self):
9 slacapra 1.5 self.status = 'X' # job status
10 slacapra 1.8 self.exitStatus = '' # job exit status
11 slacapra 1.5 self.jid = '' # scheduler job id
12 corvo 1.10 self.bossid = '' # BOSS job id
13 slacapra 1.5 self.collections = [] # EvCollection to be analyzed in this job
14     self.inputSandbox = [] # InputSandbox
15     self.outputSandbox = [] # OutputSandbox
16 corvo 1.10 self.taskId = '' # Task job belongs to
17 gutsche 1.13 self.arguments = [] ### Fabio: abstract job_type parameters
18 nsmirnov 1.1 return
19    
20 nsmirnov 1.2 def __str__(self):
21     txt = 'Status <' + self.status + '>; '
22 slacapra 1.8 if self.exitStatus!='':
23     txt += 'exitStatus <' + str(self.exitStatus) + '>\n'
24 nsmirnov 1.2 txt += 'Job Id <' + self.jid + '>\n'
25 gutsche 1.13 if self.arguments:
26     txt += 'Job Type Arguments <' + str(self.arguments) + '>\n'
27 slacapra 1.8 if self.collections:
28 slacapra 1.5 txt += 'Collections <' + str(self.collections) + '>\n'
29 slacapra 1.4
30 nsmirnov 1.1 return txt
31    
32     class JobDB:
33     def __init__(self):
34     self._dir = common.work_space.shareDir() + 'db/'
35     self._db_fname = 'jobs'
36     self._jobs = [] # list of dbEntry's
37     return
38    
39 nsmirnov 1.2 def __str__(self):
40 nsmirnov 1.1 njobs = self.nJobs()
41     if njobs == 1: plural = ''
42     else: plural = 's'
43     txt = 'Total of %d job%s:\n' % (njobs, plural)
44     for i in range(njobs):
45 nsmirnov 1.3 txt += ('Job %03d' % (i+1)) + ': '
46 nsmirnov 1.1 txt += str(self._jobs[i])
47     pass
48     return txt
49    
50 slacapra 1.4 def dump(self, jobs):
51     njobs = len(jobs)
52     if njobs == 1: plural = ''
53     else: plural = 's'
54     print 'Listing %d job%s:\n' % (njobs, plural)
55     for job in jobs:
56 spiga 1.12 print string.strip(('Job %03d' % (job)) + ': ' + str(self._jobs[job - 1]))
57 slacapra 1.4 pass
58    
59 nsmirnov 1.1 def nJobs(self):
60     return len(self._jobs)
61    
62     def create(self, njobs):
63    
64     if os.path.exists(self._dir):
65     msg = 'Cannot create Job DB: already exists.'
66     raise CrabException(msg)
67    
68     os.mkdir(self._dir)
69    
70     for i in range(njobs):
71     self._jobs.append(dbEntry())
72     pass
73    
74 slacapra 1.4 common.logger.debug(5,'Created DB for '+str(njobs)+' jobs')
75    
76 nsmirnov 1.1 self.save()
77     return
78    
79     def save(self):
80     db_file = open(self._dir+self._db_fname, 'w')
81     for i in range(len(self._jobs)):
82     db_file.write(`(i+1)`+';')
83     db_file.write(self._jobs[i].status+';')
84 slacapra 1.8 db_file.write(self._jobs[i].exitStatus+';')
85 nsmirnov 1.1 db_file.write(self._jobs[i].jid+';')
86 fanzago 1.9 db_file.write(self._jobs[i].bossid+';')
87 slacapra 1.4 db_file.write(str(self._jobs[i].collections)+';')
88 slacapra 1.5 db_file.write(str(self._jobs[i].inputSandbox)+';')
89     db_file.write(str(self._jobs[i].outputSandbox)+';')
90 corvo 1.10 db_file.write(str(self._jobs[i].taskId)+';')
91 gutsche 1.13 db_file.write(str(self._jobs[i].arguments)+';')
92 nsmirnov 1.1 db_file.write('\n')
93     pass
94     db_file.close()
95     return
96    
97     def load(self):
98     self._jobs = []
99 slacapra 1.6 try:
100     db_file = open(self._dir+self._db_fname, 'r')
101     except IOError:
102 slacapra 1.7 raise DBException("Something really serious! no JobDB is present!!!")
103 slacapra 1.6
104 nsmirnov 1.1 for line in db_file:
105 nsmirnov 1.2 db_entry = dbEntry()
106 gutsche 1.13 (n, db_entry.status, db_entry.exitStatus, db_entry.jid, db_entry.bossid, collectionsTMP, inputSandboxTMP , outputSandboxTMP , db_entry.taskId, argumentsTMP, rest) = string.split(line, ';')
107 slacapra 1.5 db_entry.collections = self.strToList_(collectionsTMP)
108     db_entry.inputSandbox = self.strToList_(inputSandboxTMP)
109     db_entry.outputSandbox = self.strToList_(outputSandboxTMP)
110 gutsche 1.13 db_entry.arguments = self.strToList_(argumentsTMP)
111 nsmirnov 1.1 self._jobs.append(db_entry)
112     pass
113     db_file.close()
114     return
115    
116 slacapra 1.5 def strToList_(self, list):
117 gutsche 1.14 if list[0] == '[' and list[-1] == ']' :
118     return string.split(string.replace(list[1:-1],"'",""),',')
119     else :
120     return list
121    
122 slacapra 1.5
123 nsmirnov 1.1 def setStatus(self, nj, status):
124 gutsche 1.11 self._jobs[int(nj)].status = status
125 nsmirnov 1.1 return
126    
127     def status(self, nj):
128 gutsche 1.11 return self._jobs[int(nj)].status
129 nsmirnov 1.1
130 slacapra 1.8 def setExitStatus(self, nj, exitStatus):
131 gutsche 1.11 self._jobs[int(nj)].exitStatus = exitStatus
132 slacapra 1.8 return
133    
134     def exitStatus(self, nj):
135 gutsche 1.11 return self._jobs[int(nj)].exitStatus
136 slacapra 1.8
137 nsmirnov 1.1 def setJobId(self, nj, jid):
138 gutsche 1.11 self._jobs[int(nj)].jid = jid
139 nsmirnov 1.1 return
140    
141     def jobId(self, nj):
142 gutsche 1.11 return self._jobs[int(nj)].jid
143 slacapra 1.4
144 fanzago 1.9 def setBossId(self, nj, bossid):
145 gutsche 1.11 self._jobs[int(nj)].bossid = bossid
146 fanzago 1.9 return
147    
148     def bossId(self, nj):
149 gutsche 1.11 return self._jobs[int(nj)].bossid
150 fanzago 1.9
151 gutsche 1.13 def setArguments(self, nj, args):
152     self._jobs[int(nj)].arguments = args
153 slacapra 1.4 return
154    
155 gutsche 1.13 def arguments(self, nj):
156     return self._jobs[int(nj)].arguments
157 slacapra 1.4
158    
159     def setCollections(self, nj, Collections):
160 gutsche 1.11 self._jobs[int(nj)].Collections = Collections
161 slacapra 1.4 return
162    
163     def collections(self, nj):
164 gutsche 1.11 return self._jobs[int(nj)].collections
165 slacapra 1.5
166     def setInputSandbox(self, nj, InputSandbox):
167 gutsche 1.11 self._jobs[int(nj)].inputSandbox = InputSandbox
168 slacapra 1.5 return
169    
170     def inputSandbox(self, nj):
171 gutsche 1.11 return self._jobs[int(nj)].inputSandbox
172 slacapra 1.5
173     def setOutputSandbox(self, nj, OutputSandbox):
174 gutsche 1.11 self._jobs[int(nj)].outputSandbox = OutputSandbox
175 slacapra 1.5 return
176    
177     def outputSandbox(self, nj):
178 gutsche 1.11 return self._jobs[int(nj)].outputSandbox
179 corvo 1.10
180     def setTaskId(self, nj, taskId):
181 gutsche 1.11 self._jobs[int(nj)].taskId = taskId