Changeset 816 for vanHelsing/trunk/src/resource.py
- Timestamp:
- Jan 15, 2010, 4:56:01 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vanHelsing/trunk/src/resource.py
r815 r816 9 9 10 10 class Resource(object): 11 DIRECTIVE="Resource"12 11 serial=0 13 12 … … 17 16 self.comments = [] 18 17 self._recurselevel = level 19 self. name = name18 self.type = name 20 19 self.value = None 21 20 self.id=Resource.serial … … 30 29 31 30 if len(self.items)==0: 32 return indent+self. name+" = "+self.value+"\n";31 return indent+self.type+" = "+self.value+"\n"; 33 32 34 if self. name.lower() in equalsign_hack:35 s += indent+self. name + " = {\n";33 if self.type.lower() in equalsign_hack: 34 s += indent+self.type + " = {\n"; 36 35 else: 37 s += indent+self. name + " {\n"36 s += indent+self.type + " {\n" 38 37 for d in self.items: 39 38 s += str(d) … … 49 48 self.items.append(item) 50 49 51 def add(self, key,value):50 def add(self,type,value): 52 51 newRes=Resource() 53 newRes. name=key52 newRes.type=type 54 53 newRes.value=value 55 54 newRes._recurselevel=self._recurselevel+1 … … 66 65 return None 67 66 68 def getBy Name(self,name):67 def getByType(self,name,depth=10000): 69 68 result=[] 70 if self. name==name:69 if self.type==name: 71 70 result.append(self) 72 for i in self.items: 73 r=i.getByName(name) 71 if depth>0: 72 for i in self.items: 73 r=i.getByType(name,depth-1) 74 74 if len(r)!=0: 75 75 for a in r: … … 79 79 def getName(self): 80 80 for i in self.items: 81 if i. name=="Name":81 if i.type=="Name": 82 82 return i.value 83 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 84 95 85 96 class Root(Resource): … … 91 102 92 103 class Director(Resource): 93 DIRECTIVE="Director"94 104 pass 95 105 96 106 class Job(Resource): 97 DIRECTIVE="Job" 98 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 99 113 class JobDefs(Resource): 100 DIRECTIVE="JobDefs"114 pass 101 115 102 116 class Schedule(Resource): 103 DIRECTIVE="Schedule"117 pass 104 118 105 119 class FileSet(Resource): 106 DIRECTIVE="FileSet"120 pass 107 121 108 122 class Client(Resource): 109 DIRECTIVE="Client" 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+'"') 110 128 111 129 class Storage(Resource): 112 DIRECTIVE="Storage"130 pass 113 131 114 132 class Pool(Resource): 115 DIRECTIVE="Pool"133 pass 116 134 117 135 class Catalog(Resource): 118 # ITEMS_DIRD = cdef.dird_cat_items 119 DIRECTIVE="Catalog" 136 pass 120 137 121 138 class Messages(Resource): 122 DIRECTIVE="Messages"139 pass 123 140 124 141 class Console(Resource): 125 DIRECTIVE="Console"142 pass 126 143 127 144 class Counter(Resource): 128 DIRECTIVE="Counter"145 pass 129 146 130 147 class Device(Resource): 131 DIRECTIVE="Device"148 pass 132 149 133 150 class Autochanger(Resource): 134 DIRECTIVE="Autochanger"151 pass 135 152 136 153 class FileDaemon(Resource): 137 DIRECTIVE="FileDaemon"154 pass 138 155 139 __cls = locals().copy()140 141 directives = [v.DIRECTIVE for k,v in __cls.iteritems()142 if k != "Resource" and getattr(v, "DIRECTIVE", None)]
Note:
See TracChangeset
for help on using the changeset viewer.