ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/JobDB.py
Revision: 1.4
Committed: Wed Jul 20 10:03:22 2005 UTC (19 years, 9 months ago) by slacapra
Content type: text/x-python
Branch: MAIN
Changes since 1.3: +45 -1 lines
Log Message:
too many changes to list them here...

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     self.status = 'X' # job status
10     self.jid = '' # scheduler job id
11 slacapra 1.4 self.firstEvent = 0 # first event for this job
12     self.maxEvents = 0 # last event for this job
13     self.collections = [] # EvCollection to be analyzed in this job
14 nsmirnov 1.1 return
15    
16 nsmirnov 1.2 def __str__(self):
17     txt = 'Status <' + self.status + '>; '
18     txt += 'Job Id <' + self.jid + '>\n'
19 slacapra 1.4 if self.maxEvents!=0:
20     txt += 'FirstEvent <' + str(self.firstEvent) + '>\n'
21     txt += 'MaxEvents <' + str(self.maxEvents) + '>\n'
22     if len(self.collections)>0:
23     txt += 'Collections <' + self.collections + '>\n'
24    
25 nsmirnov 1.1 return txt
26    
27     class JobDB:
28     def __init__(self):
29     self._dir = common.work_space.shareDir() + 'db/'
30     self._db_fname = 'jobs'
31     self._jobs = [] # list of dbEntry's
32     return
33    
34 nsmirnov 1.2 def __str__(self):
35 nsmirnov 1.1 njobs = self.nJobs()
36     if njobs == 1: plural = ''
37     else: plural = 's'
38     txt = 'Total of %d job%s:\n' % (njobs, plural)
39     for i in range(njobs):
40 nsmirnov 1.3 txt += ('Job %03d' % (i+1)) + ': '
41 nsmirnov 1.1 txt += str(self._jobs[i])
42     pass
43     return txt
44    
45 slacapra 1.4 def dump(self, jobs):
46     njobs = len(jobs)
47     if njobs == 1: plural = ''
48     else: plural = 's'
49     print 'Listing %d job%s:\n' % (njobs, plural)
50     for job in jobs:
51     print string.strip(('Job %03d' % (job+1)) + ': ' + str(self._jobs[job]))
52     pass
53    
54 nsmirnov 1.1 def nJobs(self):
55     return len(self._jobs)
56    
57     def create(self, njobs):
58    
59     if os.path.exists(self._dir):
60     msg = 'Cannot create Job DB: already exists.'
61     raise CrabException(msg)
62    
63     os.mkdir(self._dir)
64    
65     for i in range(njobs):
66     self._jobs.append(dbEntry())
67     pass
68    
69 slacapra 1.4 common.logger.debug(5,'Created DB for '+str(njobs)+' jobs')
70    
71 nsmirnov 1.1 self.save()
72     return
73    
74     def save(self):
75     db_file = open(self._dir+self._db_fname, 'w')
76     for i in range(len(self._jobs)):
77     db_file.write(`(i+1)`+';')
78     db_file.write(self._jobs[i].status+';')
79     db_file.write(self._jobs[i].jid+';')
80 slacapra 1.4 db_file.write(str(self._jobs[i].firstEvent)+';')
81     db_file.write(str(self._jobs[i].maxEvents)+';')
82     db_file.write(str(self._jobs[i].collections)+';')
83 nsmirnov 1.1 db_file.write('\n')
84     pass
85     db_file.close()
86     return
87    
88     def load(self):
89     self._jobs = []
90     db_file = open(self._dir+self._db_fname, 'r')
91     for line in db_file:
92 nsmirnov 1.2 db_entry = dbEntry()
93 slacapra 1.4 (n, db_entry.status, db_entry.jid, db_entry.firstEvent, db_entry.maxEvents, db_entry.collections, rest) = string.split(line, ';')
94 nsmirnov 1.1 self._jobs.append(db_entry)
95     pass
96     db_file.close()
97     return
98    
99     def setStatus(self, nj, status):
100     self._jobs[nj].status = status
101     return
102    
103     def status(self, nj):
104     return self._jobs[nj].status
105    
106     def setJobId(self, nj, jid):
107     self._jobs[nj].jid = jid
108     return
109    
110     def jobId(self, nj):
111     return self._jobs[nj].jid
112 slacapra 1.4
113     def setFirstEvent(self, nj, firstEvent):
114     self._jobs[nj].firstEvent = firstEvent
115     return
116    
117     def firstEvent(self, nj):
118     return self._jobs[nj].firstEvent
119    
120     def setMaxEvents(self, nj, MaxEvents):
121     self._jobs[nj].maxEvents = MaxEvents
122     return
123    
124     def maxEvents(self, nj):
125     return self._jobs[nj].maxEvents
126    
127     def setCollections(self, nj, Collections):
128     self._jobs[nj].Collections = Collections
129     return
130    
131     def collections(self, nj):
132     return self._jobs[nj].collections