Changeset 816 for vanHelsing/trunk
- Timestamp:
- Jan 15, 2010, 4:56:01 PM (15 years ago)
- Location:
- vanHelsing/trunk/src
- Files:
-
- 2 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) -
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.