Changeset 816 for vanHelsing/trunk/src/bcfg.py
- Timestamp:
- Jan 15, 2010, 4:56:01 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vanHelsing/trunk/src/bcfg.py
r815 r816 13 13 14 14 rxp_item = re.compile('^\\s*(\\w[\\w ]*\\w+)\\s*\\=(.*)') # xxx = xxx matchen 15 rxp_item2 = re.compile('^\\s*(\\w[\\w ]*\\w+)\\s*\\=\\s*{(.*)}\\s*') # match key= { a = 1; b= 2}15 rxp_item2 = re.compile('^\\s*(\\w[\\w ]*\\w+)\\s*\\=\\s*{(.*)}\\s*') # match type = { a = 1; b= 2} 16 16 rxp_openbrace = re.compile('^\\s*(\\w[\\w ]*\\w+)\\s*\\=?\\s*\\{\\s*') # match xxx { 17 17 rxp_open = re.compile('^\\s*(\\w[\\w ]*\\w+)\\s*$') # match xxx … … 29 29 self.filename = filename 30 30 self.resources = resource.Root(level=0) 31 self.resources. name="<root>"31 self.resources.type="<root>" 32 32 33 33 def read(self): … … 42 42 f.close() 43 43 44 def getResourceById(self,theid):45 return self.resources.getById(theid)46 47 def getResourceByName(self,name):48 return self.resources.getByName(name)49 50 44 def getRoot(self): 51 45 return self.resources … … 58 52 59 53 newRes=resClass(level+1) 60 newRes. name=resname54 newRes.type=resname 61 55 curRes.add_item(newRes); 62 56 return newRes 63 57 64 58 def parse(self,curRes,f,level): 65 #print "START",curRes. name59 #print "START",curRes.type 66 60 67 61 while True: … … 95 89 #print "item:",name,value 96 90 newRes=resource.Resource(level+1) 97 newRes. name=name91 newRes.type=name 98 92 newRes.value="{"+value+"}" 99 93 curRes.add_item(newRes) … … 121 115 #print "item:",name,value 122 116 newRes=resource.Resource(level+1) 123 newRes. name=name117 newRes.type=name 124 118 newRes.value=value 125 119 curRes.add_item(newRes) … … 162 156 pass 163 157 164 def createClient(clientname,clientaddr,catalog,password):165 newclient=resource.Client(1,"Client")166 newclient.add("Name",clientname)167 newclient.add("Address",clientaddr)168 #newclient.add("FDPort",fdport)169 newclient.add("Catalog",catalog)170 newclient.add("Password",'"'+password+'"')171 return newclient172 173 158 def genpasswd(len=32): 174 159 charset="01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!/%()=?@" … … 178 163 return password 179 164 165 166 def createClientConfig(dirdcfg,clientName,clientPassword=genpasswd()): 167 director=dirdcfg.getRoot().getByType("Director")[0] 168 dirdName=director.getName() 169 r=dirdcfg.getRoot().getByName(clientName) 170 if len(r)==1: 171 client=r[0] 172 else: 173 return 174 175 filename=clientName+".conf" 176 fdcfg=FiledConfig(filename) 177 fdcfg.setDefaults(dirdName,clientPassword,clientName) 178 fdcfg.write() 179 180 180 def createAllClientConfigs(dirdcfg): 181 clients=dirdcfg.getR esourceByName("Client")182 director=dirdcfg.getR esourceByName("Director")[0]181 clients=dirdcfg.getRoot().getByType("Client",1) 182 director=dirdcfg.getRoot().getByType("Director")[0] 183 183 dirdName=director.getName() 184 184 185 185 for c in clients: 186 print c 186 187 clientName=c.getName() 187 188 if clientName!=None: 188 r=c.getBy Name("Password")189 r=c.getByType("Password") 189 190 if len(r)>0: 190 191 clientPassword=r[0].value … … 199 200 200 201 if __name__ == "__main__": 201 202 202 if len(sys.argv) < 2: 203 203 filename="test.conf" 204 204 else: 205 205 filename=sys.argv[1] 206 206 207 207 dirdcfg = DirdConfig(filename) 208 208 dirdcfg.read() 209 209 210 root=dirdcfg.getRoot() 211 210 212 job=resource.Job(1,"Job") 211 job.add("Name",'"test2"') 212 job.add("Client",'"test2"') 213 job.add("JobDefs",'"testdefs"') 214 job.add("FileSet",'"Full Set"') 215 216 root=dirdcfg.getRoot() 213 job.setDefaults("test2-job","test2","testdefs","Full Set") 214 217 215 root.add_item(job) 218 216 219 217 pwd=genpasswd() 220 newclient=createClient("test-fd","testclient","MyCatalog",pwd) 218 newclient=resource.Client(1,"Client") 219 newclient.setDefaults("test-fd","testclient","MyCatalog",pwd) 221 220 root.add_item(newclient) 222 221 … … 227 226 fdcfg.write() 228 227 228 229 createClientConfig(dirdcfg,"gaffel-fd") 230 createClientConfig(dirdcfg,"test-fd") 231 229 232 createAllClientConfigs(dirdcfg) 230 231 233 sys.exit(0)
Note:
See TracChangeset
for help on using the changeset viewer.