Last change
on this file since 799 was 799, checked in by slederer, on Oct 15, 2009 at 6:37:56 PM |
Änderungen am Parser, so dass er funktioniert
|
-
Property svn:keywords
set to
Id
-
Property svn:mime-type
set to
text/x-python
|
File size:
2.6 KB
|
Line | |
---|
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 | s = "\n".join(self.comments)
|
---|
25 | indent=" "*self._recurselevel
|
---|
26 | s += indent+"# id:"+str(self.id)+"\n"
|
---|
27 |
|
---|
28 | if len(self.items)==0:
|
---|
29 | return indent+self.name+" = "+self.value+"\n";
|
---|
30 |
|
---|
31 | s += indent+self.name + " {\n"
|
---|
32 | for d in self.items:
|
---|
33 | s += str(d)
|
---|
34 | s += indent+"}\n"
|
---|
35 | return s
|
---|
36 |
|
---|
37 | def add_comment(self, comment):
|
---|
38 | if not comment.lstrip().startswith("#"):
|
---|
39 | comment = "# " + comment
|
---|
40 | self.comments.append(comment)
|
---|
41 |
|
---|
42 | def add_item(self, item):
|
---|
43 | self.items.append(item)
|
---|
44 |
|
---|
45 | def add(self,key,value):
|
---|
46 | newRes=Resource()
|
---|
47 | newRes.name=key
|
---|
48 | newRes.value=value
|
---|
49 | newRes._recurselevel=self._recurselevel+1
|
---|
50 | self.items.append(newRes)
|
---|
51 |
|
---|
52 | def getById(self,theid):
|
---|
53 | if self.id==theid:
|
---|
54 | return self
|
---|
55 |
|
---|
56 | for r in self.items:
|
---|
57 | result=r.getById(theid)
|
---|
58 | if result:
|
---|
59 | return result
|
---|
60 | return None
|
---|
61 |
|
---|
62 | def getByName(self,name):
|
---|
63 | result=[]
|
---|
64 | if self.name==name:
|
---|
65 | result.append(self)
|
---|
66 | for i in self.items:
|
---|
67 | r=i.getByName(name)
|
---|
68 | if len(r)!=0:
|
---|
69 | for a in r:
|
---|
70 | result.append(a)
|
---|
71 | return result
|
---|
72 |
|
---|
73 |
|
---|
74 | class Director(Resource):
|
---|
75 | DIRECTIVE="Director"
|
---|
76 | pass
|
---|
77 |
|
---|
78 | class Job(Resource):
|
---|
79 | DIRECTIVE="Job"
|
---|
80 |
|
---|
81 | class JobDefs(Resource):
|
---|
82 | DIRECTIVE="JobDefs"
|
---|
83 |
|
---|
84 | class Schedule(Resource):
|
---|
85 | DIRECTIVE="Schedule"
|
---|
86 |
|
---|
87 | class FileSet(Resource):
|
---|
88 | DIRECTIVE="FileSet"
|
---|
89 |
|
---|
90 | class Client(Resource):
|
---|
91 | DIRECTIVE="Client"
|
---|
92 |
|
---|
93 | class Storage(Resource):
|
---|
94 | DIRECTIVE="Storage"
|
---|
95 |
|
---|
96 | class Pool(Resource):
|
---|
97 | DIRECTIVE="Pool"
|
---|
98 |
|
---|
99 | class Catalog(Resource):
|
---|
100 | # ITEMS_DIRD = cdef.dird_cat_items
|
---|
101 | DIRECTIVE="Catalog"
|
---|
102 |
|
---|
103 | class Messages(Resource):
|
---|
104 | DIRECTIVE="Messages"
|
---|
105 |
|
---|
106 | class Console(Resource):
|
---|
107 | DIRECTIVE="Console"
|
---|
108 |
|
---|
109 | class Counter(Resource):
|
---|
110 | DIRECTIVE="Counter"
|
---|
111 |
|
---|
112 | class Device(Resource):
|
---|
113 | DIRECTIVE="Device"
|
---|
114 |
|
---|
115 | class Autochanger(Resource):
|
---|
116 | DIRECTIVE="Autochanger"
|
---|
117 |
|
---|
118 | __cls = locals().copy()
|
---|
119 |
|
---|
120 | directives = [v.DIRECTIVE for k,v in __cls.iteritems()
|
---|
121 | if k != "Resource" and getattr(v, "DIRECTIVE", None)]
|
---|
Note:
See
TracBrowser
for help on using the repository browser.