ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/JobDB.py
Revision: 1.15
Committed: Wed Jun 28 13:36:57 2006 UTC (18 years, 10 months ago) by slacapra
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_1_2_0_pre8
Changes since 1.14: +3 -1 lines
Log Message:
fix if multiple args but w/o []

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 slacapra 1.15 # print string.split(string.replace(argumentsTMP,"'",""))
112     # print db_entry.arguments
113 nsmirnov 1.1 self._jobs.append(db_entry)
114     pass
115     db_file.close()
116     return
117    
118 slacapra 1.5 def strToList_(self, list):
119 gutsche 1.14 if list[0] == '[' and list[-1] == ']' :
120     return string.split(string.replace(list[1:-1],"'",""),',')
121     else :
122 slacapra 1.15 return string.split(string.replace(list,"'",""),',')
123 gutsche 1.14
124 slacapra 1.5
125 nsmirnov 1.1 def setStatus(self, nj, status):
126 gutsche 1.11 self._jobs[int(nj)].status = status
127 nsmirnov 1.1 return
128    
129     def status(self, nj):
130 gutsche 1.11 return self._jobs[int(nj)].status
131 nsmirnov 1.1
132 slacapra 1.8 def setExitStatus(self, nj, exitStatus):
133 gutsche 1.11 self._jobs[int(nj)].exitStatus = exitStatus
134 slacapra 1.8 return
135    
136     def exitStatus(self, nj):
137 gutsche 1.11 return self._jobs[int(nj)].exitStatus
138 slacapra 1.8
139 nsmirnov 1.1 def setJobId(self, nj, jid):
140 gutsche 1.11 self._jobs[int(nj)].jid = jid
141 nsmirnov 1.1 return
142    
143     def jobId(self, nj):
144 gutsche 1.11 return self._jobs[int(nj)].jid
145 slacapra 1.4
146 fanzago 1.9 def setBossId(self, nj, bossid):
147 gutsche 1.11 self._jobs[int(nj)].bossid = bossid
148 fanzago 1.9 return
149    
150     def bossId(self, nj):
151 gutsche 1.11 return self._jobs[int(nj)].bossid
152 fanzago 1.9
153 gutsche 1.13 def setArguments(self, nj, args):
154     self._jobs[int(nj)].arguments = args
155 slacapra 1.4 return
156    
157 gutsche 1.13 def arguments(self, nj):
158     return self._jobs[int(nj)].arguments
159 slacapra 1.4
160    
161     def setCollections(self, nj, Collections):
162 gutsche 1.11 self._jobs[int(nj)].Collections = Collections
163 slacapra 1.4 return
164    
165     def collections(self, nj):
166 gutsche 1.11 return self._jobs[int(nj)].collections
167 slacapra 1.5
168     def setInputSandbox(self, nj, InputSandbox):
169 gutsche 1.11 self._jobs[int(nj)].inputSandbox = InputSandbox
170 slacapra 1.5 return
171    
172     def inputSandbox(self, nj):
173 gutsche 1.11 return self._jobs[int(nj)].inputSandbox
174 slacapra 1.5
175     def setOutputSandbox(self, nj, OutputSandbox):
176 gutsche 1.11 self._jobs[int(nj)].outputSandbox = OutputSandbox
177 slacapra 1.5 return
178    
179     def outputSandbox(self, nj):
180 gutsche 1.11 return self._jobs[int(nj)].outputSandbox
181 corvo 1.10
182     def setTaskId(self, nj, taskId):
183 gutsche 1.11 self._jobs[int(nj)].taskId = taskId