source: vanHelsing/trunk/src/resource.py@ 856

Last change on this file since 856 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
RevLine 
[775]1'''
2Resource Objects
3Created on 30.06.2009
4
5@author: hmueller
6'''
7
[799]8
9
[775]10class Resource(object):
[799]11 serial=0
[775]12
[799]13 def __init__(self, level=0,name=None):
14 Resource.serial=Resource.serial+1
[775]15 self.items = []
16 self.comments = []
[798]17 self._recurselevel = level
[816]18 self.type = name
[799]19 self.value = None
20 self.id=Resource.serial
21
[775]22 def __str__(self):
[812]23
24 equalsign_hack=[ 'diraddresses', 'ip', 'ipv4' ]
25
[775]26 s = "\n".join(self.comments)
[799]27 indent=" "*self._recurselevel
28 s += indent+"# id:"+str(self.id)+"\n"
29
30 if len(self.items)==0:
[816]31 return indent+self.type+" = "+self.value+"\n";
[799]32
[816]33 if self.type.lower() in equalsign_hack:
34 s += indent+self.type + " = {\n";
[812]35 else:
[816]36 s += indent+self.type + " {\n"
[775]37 for d in self.items:
[799]38 s += str(d)
39 s += indent+"}\n"
[775]40 return s
41
42 def add_comment(self, comment):
43 if not comment.lstrip().startswith("#"):
44 comment = "# " + comment
45 self.comments.append(comment)
[798]46
47 def add_item(self, item):
48 self.items.append(item)
[775]49
[816]50 def add(self,type,value):
[799]51 newRes=Resource()
[816]52 newRes.type=type
[799]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
[816]67 def getByType(self,name,depth=10000):
[799]68 result=[]
[816]69 if self.type==name:
[799]70 result.append(self)
[816]71 if depth>0:
72 for i in self.items:
73 r=i.getByType(name,depth-1)
[799]74 if len(r)!=0:
75 for a in r:
76 result.append(a)
77 return result
78
[815]79 def getName(self):
80 for i in self.items:
[816]81 if i.type=="Name":
[815]82 return i.value
83 return None
[799]84
[823]85 def getByName(self,name,type=None):
[816]86 result=[]
[823]87 if self.getName()==name and (type==None or self.type==type):
[816]88 result.append(self)
89 for i in self.items:
[823]90 r=i.getByName(name,type)
[816]91 if len(r)!=0:
92 for a in r:
93 result.append(a)
94 return result
95
[812]96class Root(Resource):
97 def __str__(self):
98 s=""
99 for d in self.items:
100 s += str(d)
101 return s
102
[775]103class Director(Resource):
104 pass
105
106class Job(Resource):
[816]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
[775]113class JobDefs(Resource):
[816]114 pass
[775]115
116class Schedule(Resource):
[816]117 pass
[775]118
119class FileSet(Resource):
[816]120 pass
[775]121
122class Client(Resource):
[816]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+'"')
[775]128
129class Storage(Resource):
[816]130 pass
[775]131
132class Pool(Resource):
[816]133 pass
[775]134
135class Catalog(Resource):
[816]136 pass
[775]137
138class Messages(Resource):
[816]139 pass
[775]140
141class Console(Resource):
[816]142 pass
[775]143
144class Counter(Resource):
[816]145 pass
[775]146
147class Device(Resource):
[816]148 pass
[775]149
150class Autochanger(Resource):
[816]151 pass
[798]152
[814]153class FileDaemon(Resource):
[816]154 pass
[814]155
Note: See TracBrowser for help on using the repository browser.