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