source: vanHelsing/trunk/webservice/resource.py@ 1039

Last change on this file since 1039 was 823, checked in by slederer, on Feb 12, 2010 at 2:50:32 PM

Funktionen für SOAP-API hinzugefügt, Entwurf für WSDL-File

  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-python
File size: 3.4 KB
Line 
1'''
2Resource Objects
3Created on 30.06.2009
4
5@author: hmueller
6'''
7
8
9
10class 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,type=None):
86 result=[]
87 if self.getName()==name and (type==None or self.type==type):
88 result.append(self)
89 for i in self.items:
90 r=i.getByName(name,type)
91 if len(r)!=0:
92 for a in r:
93 result.append(a)
94 return result
95
96class Root(Resource):
97 def __str__(self):
98 s=""
99 for d in self.items:
100 s += str(d)
101 return s
102
103class Director(Resource):
104 pass
105
106class 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
113class JobDefs(Resource):
114 pass
115
116class Schedule(Resource):
117 pass
118
119class FileSet(Resource):
120 pass
121
122class 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
129class Storage(Resource):
130 pass
131
132class Pool(Resource):
133 pass
134
135class Catalog(Resource):
136 pass
137
138class Messages(Resource):
139 pass
140
141class Console(Resource):
142 pass
143
144class Counter(Resource):
145 pass
146
147class Device(Resource):
148 pass
149
150class Autochanger(Resource):
151 pass
152
153class FileDaemon(Resource):
154 pass
155
Note: See TracBrowser for help on using the repository browser.