Changeset 812 for vanHelsing/trunk/src
- Timestamp:
- Jan 13, 2010, 12:35:53 PM (15 years ago)
- Location:
- vanHelsing/trunk/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
vanHelsing/trunk/src/bcfg.py
r799 r812 26 26 self.resource_type = resource_type 27 27 self.filename = filename 28 self.resources = resource.R esource(level=0)28 self.resources = resource.Root(level=0) 29 29 self.resources.name="<root>" 30 30 … … 33 33 #print self.resources 34 34 35 def write(self): 36 pass 35 def write(self, filename=None): 36 if(filename==None): 37 filename=self.filename 38 f=open(filename,"w") 39 f.write(str(self.getRoot())) 40 f.close() 37 41 38 42 def getResourceById(self,theid): … … 60 64 line=line[:commentStart].strip() 61 65 #curRes.add_comment(inlinecomment) 66 67 if len(line)>0 and line[0]=='@': 68 includepath=line[1:].strip() 69 print "include " +includepath 70 self.parse(self.resources,open(includepath,"r"),0) 62 71 63 72 if rxp_closebrace.match(line): … … 96 105 if item: 97 106 name = item.group(1) 98 value = item.group(2) 107 value = item.group(2).strip() 99 108 #print "item:",name,value 100 109 newRes=resource.Resource(level+1) … … 120 129 pass 121 130 131 def createClient(clientname,clientaddr,catalog,password): 132 newclient=resource.Client(1,"Client") 133 newclient.add("Name",clientname) 134 newclient.add("Address",clientaddr) 135 #newclient.add("FDPort",fdport) 136 newclient.add("Catalog",catalog) 137 newclient.add("Password",password) 138 return newclient 139 122 140 if __name__ == "__main__": 123 141 124 142 dirdcfg = DirdConfig("test.conf") 125 143 dirdcfg.read() 126 #print dirdcfg.getResourceById(174)127 jobs=dirdcfg.getResourceByName("Job")128 for j in jobs:129 print j.getByName("Name")[0].value130 d=dirdcfg.getResourceByName("ip")[1]131 print d132 144 133 145 job=resource.Job(1,"Job") … … 140 152 root.add_item(job) 141 153 142 print root 154 newclient=createClient("testclient-fd","testclient","MyCatalog","testpassword") 155 root.add_item(newclient) 156 157 dirdcfg.write("test.conf.out") 143 158 sys.exit(0) -
vanHelsing/trunk/src/resource.py
r799 r812 22 22 23 23 def __str__(self): 24 25 equalsign_hack=[ 'diraddresses', 'ip', 'ipv4' ] 26 24 27 s = "\n".join(self.comments) 25 28 indent=" "*self._recurselevel … … 29 32 return indent+self.name+" = "+self.value+"\n"; 30 33 31 s += indent+self.name + " {\n" 34 if self.name.lower() in equalsign_hack: 35 s += indent+self.name + " = {\n"; 36 else: 37 s += indent+self.name + " {\n" 32 38 for d in self.items: 33 39 s += str(d) … … 71 77 return result 72 78 79 80 class Root(Resource): 81 def __str__(self): 82 s="" 83 for d in self.items: 84 s += str(d) 85 return s 73 86 74 87 class Director(Resource):
Note:
See TracChangeset
for help on using the changeset viewer.