Revision: | 1.2 |
Committed: | Wed Sep 27 14:17:41 2006 UTC (18 years, 7 months ago) by slacapra |
Content type: | text/x-python |
Branch: | MAIN |
CVS Tags: | CRAB_1_5_3, CRAB_1_5_3_pre5, CRAB_1_5_3_pre4, CRAB_2_0_0_pre5, CRAB_1_5_3_pre3, configure, CRAB_2_0_0_pre4, CRAB_1_5_3_pre2, CRAB_1_5_3_pre1, CRAB_2_0_0_pre3, CRAB_1_5_2, CRAB_2_0_0_pre2, CRAB_2_0_0_pre1, CRAB_1_5_1, CRAB_1_5_1_pre4, CRAB_1_5_1_pre3, CRAB_1_5_1_pre2, CRAB_1_5_1_pre1, CRAB_1_5_0, CRAB_1_5_0_pre9, CRAB_1_5_0_pre8, CRAB_1_5_0_pre7, CRAB_1_5_0_pre6, CRAB_1_5_0_pre5, CRAB_1_5_0_pre4, CRAB_1_5_0_pre3, CRAB_1_5_0_pre2, CRAB_1_4_2, CRAB_1_5_0_pre1, CRAB_1_4_1, CRAB_1_4_1_pre2, CRAB_1_4_1_pre1, CRAB_1_4_0, CRAB_1_4_0_pre4, CRAB_1_4_0_pre3, CRAB_1_4_0_pre2, CRAB_1_4_0_pre1, CRAB_1_3_0, CRAB_1_3_0_pre6 |
Branch point for: | CRAB_1_5_4_SLC3_start, branch_1_4_1 |
Changes since 1.1: | +5 -1 lines |
Log Message: | add check for non existing file |
# | User | Rev | Content |
---|---|---|---|
1 | slacapra | 1.1 | from WorkSpace import WorkSpace |
2 | from crab_exceptions import * | ||
3 | import common | ||
4 | |||
5 | import os, string | ||
6 | |||
7 | """ | ||
8 | Class to represent a task dedicated DB, suited to host all info which are | ||
9 | common to a given task. It is implemented in term of a persistent dictionary | ||
10 | """ | ||
11 | |||
12 | class TaskDB: | ||
13 | def __init__(self): | ||
14 | self.fName = 'task' | ||
15 | self._theDict = {} | ||
16 | |||
17 | def load(self): | ||
18 | """ | ||
19 | load the dictionary into memory | ||
20 | """ | ||
21 | slacapra | 1.2 | try: |
22 | fl = open(common.work_space.shareDir() + '/db/' + self.fName, 'r') | ||
23 | except IOError: | ||
24 | raise CrabException("TaskDB: not found. Task was not craeted successfully.") | ||
25 | |||
26 | slacapra | 1.1 | for i in fl.readlines(): |
27 | (key,val) = i.split('|') | ||
28 | self._theDict[key] = string.strip(val) | ||
29 | fl.close() | ||
30 | |||
31 | def save(self): | ||
32 | """ | ||
33 | save the dictionary to disk | ||
34 | """ | ||
35 | fl = open(common.work_space.shareDir() + '/db/' + self.fName, 'w') | ||
36 | for j, k in self._theDict.iteritems(): | ||
37 | fl.write(j + '|' + k + '\n') | ||
38 | fl.close() | ||
39 | |||
40 | def setDict(self, key, value): | ||
41 | """ | ||
42 | assign value to key: key is case sensitive | ||
43 | """ | ||
44 | self._theDict[key]=value | ||
45 | |||
46 | def dict(self, key): | ||
47 | """ | ||
48 | assign value to key | ||
49 | """ | ||
50 | if not self._theDict.has_key(key): | ||
51 | raise CrabException("TaskDB: key "+key+" not found") | ||
52 | return self._theDict[key] |