1 | '''
|
---|
2 | Resource Objects
|
---|
3 | Created on 30.06.2009
|
---|
4 |
|
---|
5 | @author: hmueller
|
---|
6 | '''
|
---|
7 |
|
---|
8 |
|
---|
9 |
|
---|
10 | class Resource(object):
|
---|
11 | DIRECTIVE="Resource"
|
---|
12 | serial=0
|
---|
13 |
|
---|
14 | def __init__(self, level=0,name=None):
|
---|
15 | Resource.serial=Resource.serial+1
|
---|
16 | self.items = []
|
---|
17 | self.comments = []
|
---|
18 | self._recurselevel = level
|
---|
19 | self.name = name
|
---|
20 | self.value = None
|
---|
21 | self.id=Resource.serial
|
---|
22 |
|
---|
23 | def __str__(self):
|
---|
24 |
|
---|
25 | equalsign_hack=[ 'diraddresses', 'ip', 'ipv4' ]
|
---|
26 |
|
---|
27 | s = "\n".join(self.comments)
|
---|
28 | indent=" "*self._recurselevel
|
---|
29 | s += indent+"# id:"+str(self.id)+"\n"
|
---|
30 |
|
---|
31 | if len(self.items)==0:
|
---|
32 | return indent+self.name+" = "+self.value+"\n";
|
---|
33 |
|
---|
34 | if self.name.lower() in equalsign_hack:
|
---|
35 | s += indent+self.name + " = {\n";
|
---|
36 | else:
|
---|
37 | s += indent+self.name + " {\n"
|
---|
38 | for d in self.items:
|
---|
39 | s += str(d)
|
---|
40 | s += indent+"}\n"
|
---|
41 | return s
|
---|
42 |
|
---|
43 | def add_comment(self, comment):
|
---|
44 | if not comment.lstrip().startswith("#"):
|
---|
45 | comment = "# " + comment
|
---|
46 | self.comments.append(comment)
|
---|
47 |
|
---|
48 | def add_item(self, item):
|
---|
49 | self.items.append(item)
|
---|
50 |
|
---|
51 | def add(self,key,value):
|
---|
52 | newRes=Resource()
|
---|
53 | newRes.name=key
|
---|
54 | newRes.value=value
|
---|
55 | newRes._recurselevel=self._recurselevel+1
|
---|
56 | self.items.append(newRes)
|
---|
57 |
|
---|
58 | def getById(self,theid):
|
---|
59 | if self.id==theid:
|
---|
60 | return self
|
---|
61 |
|
---|
62 | for r in self.items:
|
---|
63 | result=r.getById(theid)
|
---|
64 | if result:
|
---|
65 | return result
|
---|
66 | return None
|
---|
67 |
|
---|
68 | def getByName(self,name):
|
---|
69 | result=[]
|
---|
70 | if self.name==name:
|
---|
71 | result.append(self)
|
---|
72 | for i in self.items:
|
---|
73 | r=i.getByName(name)
|
---|
74 | if len(r)!=0:
|
---|
75 | for a in r:
|
---|
76 | result.append(a)
|
---|
77 | return result
|
---|
78 |
|
---|
79 |
|
---|
80 | class Root(Resource):
|
---|
81 | def __str__(self):
|
---|
82 | s=""
|
---|
83 | for d in self.items:
|
---|
84 | s += str(d)
|
---|
85 | return s
|
---|
86 |
|
---|
87 | class Director(Resource):
|
---|
88 | DIRECTIVE="Director"
|
---|
89 | pass
|
---|
90 |
|
---|
91 | class Job(Resource):
|
---|
92 | DIRECTIVE="Job"
|
---|
93 |
|
---|
94 | class JobDefs(Resource):
|
---|
95 | DIRECTIVE="JobDefs"
|
---|
96 |
|
---|
97 | class Schedule(Resource):
|
---|
98 | DIRECTIVE="Schedule"
|
---|
99 |
|
---|
100 | class FileSet(Resource):
|
---|
101 | DIRECTIVE="FileSet"
|
---|
102 |
|
---|
103 | class Client(Resource):
|
---|
104 | DIRECTIVE="Client"
|
---|
105 |
|
---|
106 | class Storage(Resource):
|
---|
107 | DIRECTIVE="Storage"
|
---|
108 |
|
---|
109 | class Pool(Resource):
|
---|
110 | DIRECTIVE="Pool"
|
---|
111 |
|
---|
112 | class Catalog(Resource):
|
---|
113 | # ITEMS_DIRD = cdef.dird_cat_items
|
---|
114 | DIRECTIVE="Catalog"
|
---|
115 |
|
---|
116 | class Messages(Resource):
|
---|
117 | DIRECTIVE="Messages"
|
---|
118 |
|
---|
119 | class Console(Resource):
|
---|
120 | DIRECTIVE="Console"
|
---|
121 |
|
---|
122 | class Counter(Resource):
|
---|
123 | DIRECTIVE="Counter"
|
---|
124 |
|
---|
125 | class Device(Resource):
|
---|
126 | DIRECTIVE="Device"
|
---|
127 |
|
---|
128 | class Autochanger(Resource):
|
---|
129 | DIRECTIVE="Autochanger"
|
---|
130 |
|
---|
131 | class FileDaemon(Resource):
|
---|
132 | DIRECTIVE="FileDaemon"
|
---|
133 |
|
---|
134 | __cls = locals().copy()
|
---|
135 |
|
---|
136 | directives = [v.DIRECTIVE for k,v in __cls.iteritems()
|
---|
137 | if k != "Resource" and getattr(v, "DIRECTIVE", None)]
|
---|