Changeset 799 for vanHelsing/trunk/src/resource.py
- Timestamp:
- Oct 15, 2009, 6:37:56 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vanHelsing/trunk/src/resource.py
r798 r799 6 6 ''' 7 7 8 9 8 10 class Resource(object): 9 DIRECTIVE="" 11 DIRECTIVE="Resource" 12 serial=0 10 13 11 def __init__(self, level=0): 14 def __init__(self, level=0,name=None): 15 Resource.serial=Resource.serial+1 12 16 self.items = [] 13 17 self.comments = [] 14 18 self._recurselevel = level 15 19 self.name = name 20 self.value = None 21 self.id=Resource.serial 22 16 23 def __str__(self): 17 24 s = "\n".join(self.comments) 18 s += self.DIRECTIVE + "{\n" 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" 19 32 for d in self.items: 20 s += " " + str(d) + "\n"21 s += "}\n"33 s += str(d) 34 s += indent+"}\n" 22 35 return s 23 36 … … 29 42 def add_item(self, item): 30 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 31 73 32 74 class Director(Resource):
Note:
See TracChangeset
for help on using the changeset viewer.