Changeset 815
- Timestamp:
- Jan 13, 2010, 5:32:53 PM (15 years ago)
- Location:
- vanHelsing/trunk/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
vanHelsing/trunk/src/bcfg.py
r813 r815 15 15 rxp_item2 = re.compile('^\\s*(\\w[\\w ]*\\w+)\\s*\\=\\s*{(.*)}\\s*') # match key = { a = 1; b= 2} 16 16 rxp_openbrace = re.compile('^\\s*(\\w[\\w ]*\\w+)\\s*\\=?\\s*\\{\\s*') # match xxx { 17 rxp_open = re.compile('^\\s*(\\w[\\w ]*\\w+)\\s*$') # match xxx 17 18 rxp_closebrace = re.compile('[^{]*}.*') # match } 18 19 rxp_comment = re.compile('^\s*#.*') … … 49 50 def getRoot(self): 50 51 return self.resources 52 53 def addResource(self,resname,level,curRes): 54 try: 55 resClass = getattr(resource,resname); 56 except: 57 resClass = resource.Resource 58 59 newRes=resClass(level+1) 60 newRes.name=resname 61 curRes.add_item(newRes); 62 return newRes 51 63 52 64 def parse(self,curRes,f,level): … … 92 104 #print "openbraceline" 93 105 resname = openbraceline.group(1) 94 try: 95 resClass = getattr(resource,resname); 96 except: 97 resClass = resource.Resource 98 99 newRes=resClass(level+1) 100 newRes.name=resname 101 curRes.add_item(newRes); 106 newRes=self.addResource(resname,level,curRes) 102 107 self.parse(newRes,f,level+1); 103 108 continue 109 110 open = rxp_open.match(line) 111 if open: 112 resname = open.group(1) 113 newRes=self.addResource(resname,level,curRes) 114 self.parse(newRes,f,level+1); 104 115 continue 105 116 … … 166 177 password += random.choice(charset) 167 178 return password 179 180 def createAllClientConfigs(dirdcfg): 181 clients=dirdcfg.getResourceByName("Client") 182 director=dirdcfg.getResourceByName("Director")[0] 183 dirdName=director.getName() 184 185 for c in clients: 186 clientName=c.getName() 187 if clientName!=None: 188 r=c.getByName("Password") 189 if len(r)>0: 190 clientPassword=r[0].value 191 clientPassword=clientPassword.replace('"','') 192 else: 193 clientPassword="" 194 filename=clientName+".conf" 195 fdcfg=FiledConfig(filename) 196 fdcfg.setDefaults(dirdName,clientPassword,clientName) 197 fdcfg.write() 198 168 199 169 200 if __name__ == "__main__": … … 196 227 fdcfg.write() 197 228 229 createAllClientConfigs(dirdcfg) 230 198 231 sys.exit(0) -
vanHelsing/trunk/src/resource.py
r814 r815 77 77 return result 78 78 79 def getName(self): 80 for i in self.items: 81 if i.name=="Name": 82 return i.value 83 return None 79 84 80 85 class Root(Resource):
Note:
See TracChangeset
for help on using the changeset viewer.