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

Last change on this file since 814 was 814, checked in by slederer, on Jan 13, 2010 at 12:43:24 PM

FileDaemon-Ressourcen-Klasse für Client-Konfiguration

  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-python
File size: 2.9 KB
Line 
1'''
2Resource Objects
3Created on 30.06.2009
4
5@author: hmueller
6'''
7
8
9
10class 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
80class Root(Resource):
81 def __str__(self):
82 s=""
83 for d in self.items:
84 s += str(d)
85 return s
86
87class Director(Resource):
88 DIRECTIVE="Director"
89 pass
90
91class Job(Resource):
92 DIRECTIVE="Job"
93
94class JobDefs(Resource):
95 DIRECTIVE="JobDefs"
96
97class Schedule(Resource):
98 DIRECTIVE="Schedule"
99
100class FileSet(Resource):
101 DIRECTIVE="FileSet"
102
103class Client(Resource):
104 DIRECTIVE="Client"
105
106class Storage(Resource):
107 DIRECTIVE="Storage"
108
109class Pool(Resource):
110 DIRECTIVE="Pool"
111
112class Catalog(Resource):
113 # ITEMS_DIRD = cdef.dird_cat_items
114 DIRECTIVE="Catalog"
115
116class Messages(Resource):
117 DIRECTIVE="Messages"
118
119class Console(Resource):
120 DIRECTIVE="Console"
121
122class Counter(Resource):
123 DIRECTIVE="Counter"
124
125class Device(Resource):
126 DIRECTIVE="Device"
127
128class Autochanger(Resource):
129 DIRECTIVE="Autochanger"
130
131class FileDaemon(Resource):
132 DIRECTIVE="FileDaemon"
133
134__cls = locals().copy()
135
136directives = [v.DIRECTIVE for k,v in __cls.iteritems()
137 if k != "Resource" and getattr(v, "DIRECTIVE", None)]
Note: See TracBrowser for help on using the repository browser.