source: dassmodus/trunk/dassmodus/nosferatu/nosferatu/tools/generate_web2py_db_model.py @ 994

Last change on this file since 994 was 994, checked in by pstorz, 9 years ago

web2py

File size: 12.9 KB
Line 
1# -*- coding: utf-8 -*-
2# $Id: $
3#
4# automatically generate the database model for web2py
5# from the info we already have for dassModus
6#
7#
8# we do have every information about the bacula configuration files.
9# we now have to create the following database model:
10# a table for each main configuration file:
11# dird_conf,
12# filed_conf,
13# stored_conf,
14# bconsole_conf
15#
16# in each bacula configuration file, we have two classes of ressources:
17# 1.: Ressources, that can only appear once
18#   here, we can just create a reference to a table containing the
19#   configuration options of this ressource.
20
21#
22#
23# 2.: Ressources, that can appear multiple times
24#   we need a table between the bacula configuration and the list of ressources.
25#
26#   here, we have a link to a list of ressources
27#  example: a dird can have multiple client ressources:
28#
29#
30#
31#
32         
33
34from nosferatu.config_classes import *
35from resource import Resource
36from nosferatu import prettynames, auto_configrules, auto_types
37
38#single_res=['dir_res']
39## this ressource can only appear once in the dir conf
40#for res in single_res:
41#  print """db.define_table('dird_conf-%s',
42#  Field('name','string'),
43#  format='%%s(name)s)'
44#  """ % (res)
45
46#print """db.define_table('dird_conf',
47#  Field('name','string'),"""
48#for res in single_res:
49#  print "  Field('dird_conf-%s', reference dird_conf-%s)," % (res,res )
50#print "  format='%(name)s')"
51
52
53
54def item2field(confshort, item, resname):
55    # file, run and plugin item names can appear multiple times
56    if item.name in MULTIPLE_ALLOWED_ITEMS_SET:
57      print "# item %s can appear multiple times" %(item.name)
58      refname = item.name
59      fieldtype = 'reference %s_conf__%s'  %  ('dird', item.name)
60      defaultvalue = 0
61      return """  Field('%s','%s', default=%s), """ %(item.name, fieldtype , defaultvalue)
62 
63 
64 
65 
66 
67 
68 
69 
70    if resname == 'inc_options_items':
71      if item.name in  auto_types.FS_option_kw:
72        fieldtype = 'string'
73        defaultvalue = '"' + FS_option_kw[item.name][0] + '"' #"incremental"
74        return """  Field('%s','%s', default=%s,
75                  requires=IS_IN_SET(%s)), """ %(item.name,
76                                                 fieldtype , defaultvalue,
77                                                 repr(auto_types.FS_option_kw[item.name])) 
78     
79   
80    if item.name == 'where' : # where cannot be a column name in sqlite
81      item.name = 'where_'
82   
83    if item.name in INTERNALLY_REFERENCED_ITEMS:
84      refname = item.name
85      if item.name.endswith('pool'):
86        refname = 'pool'
87      print '### ' + refname
88     
89      fieldtype = 'reference %s_conf__%s'  %  (confshort,refname)
90      defaultvalue = 0
91      return """ Field('%s','%s', default=%s), """ %(item.name, fieldtype , defaultvalue)
92   
93    elif item.name in set(['include', 'exclude']):
94      refname = item.name
95      fieldtype = 'reference %s_conf__%s_link'  %  ('dird','inc_newinc_items')
96      defaultvalue = 0
97      return """ Field('%s','%s', default=%s), """ %(item.name, fieldtype , defaultvalue)
98   
99    elif item.name == 'options':
100      refname = item.name
101      fieldtype = 'reference %s_conf__%s_link'  %  ('dird','inc_options')
102      defaultvalue = 0
103      return """ Field('%s','%s', default=%s), """ %(item.name, fieldtype , defaultvalue)
104   
105    elif item.name == 'runscript':
106      refname = item.name
107      fieldtype = 'reference %s_conf__%s_link'  %  ('dird','runscript')
108      defaultvalue = 0
109      return """  Field('%s','%s', default=%s), """ %(item.name, fieldtype , defaultvalue)
110     
111   
112    elif item.name == 'level':
113      refname = item.name
114      fieldtype = 'string'
115      defaultvalue = '"' + auto_types.joblevels[2] + '"' #"incremental"
116      return """  Field('%s','%s', default=%s,
117                  requires=IS_IN_SET(%s)), """ %(item.name,
118                                                 fieldtype , defaultvalue,
119                                                 repr(auto_types.joblevels))
120    elif item.name == 'type':
121      refname = item.name
122      fieldtype = 'string'
123      defaultvalue = '"' + auto_types.jobtypes[5] + '"' # "backup"
124      return """  Field('%s','%s', default=%s,
125                  requires=IS_IN_SET(%s)), """ %(item.name,
126                                                 fieldtype , defaultvalue,
127                                                 repr(auto_types.jobtypes))     
128     
129    elif item.name == 'replace':
130      refname = item.name
131      fieldtype = 'string'
132      defaultvalue = '"' + auto_types.ReplaceOptions[0] + '"' # "always"
133      return """  Field('%s','%s', default=%s,
134                  requires=IS_IN_SET(%s)), """ %(item.name,
135                                                 fieldtype , defaultvalue,
136                                                 repr(auto_types.ReplaceOptions))     
137    else:
138      fieldtype = 'string'
139      defaultvalue = item.defaultvalue
140      if defaultvalue == None:
141        defaultvalue = ''
142      if item.type == "store_bool":
143        fieldtype = "boolean"
144        #print "#####%s %s %s" % (item.name, item.defaultvalue, defaultvalue)
145        return """ Field('%s','%s', default=%s), """ %(item.name, fieldtype , defaultvalue)
146      return """ Field('%s','%s', default='%s'), """ %(item.name, fieldtype , defaultvalue)
147
148
149
150
151# subressourcen:
152# unterhalb von fileset  include und exclude
153# unterhalb von include und exclude options
154# unterhalb von job runscript
155
156
157
158#inc_newinc_items
159#inc_options_items
160#dird_runscript_items
161print "# subressources"
162
163
164confshort = 'dird'
165res_name = 'options'
166print """db.define_table('%s_conf__%s',  """ % (confshort,res_name)
167for item in auto_configrules.inc_options_items:
168    item.required=False
169    item.printall=True
170    print item2field(confshort,item, res_name)
171print """ format='options-%(id)s')
172"""
173#print """db.define_table('%s_conf__%s_link', 
174#  Field('%s','reference %s_conf__%s'),
175#  format = '%%(id)s')
176#    """ %  (confshort,res_name, res_name, confshort,res_name)
177
178
179   
180for res_name in ('include', 'exclude'):   
181  confshort = 'dird'
182  #res_name = 'include'
183  print """db.define_table('%s_conf__%s',  """ % (confshort,res_name)
184  for item in auto_configrules.inc_newinc_items:
185    item.required=False
186    item.printall=True
187    print item2field(confshort,item, res_name)
188  print """ format='include-%(id)s')
189  """
190#  print """db.define_table('%s_conf__%s_link', 
191#  Field('%s','reference %s_conf__%s'),
192#  format = '%%(id)s')
193#    """ %  (confshort,res_name, res_name, confshort,res_name)
194
195
196#
197
198confshort = 'dird'
199res_name = 'dird_runscript_items'
200print """db.define_table('%s_conf__%s',  """ % (confshort,res_name)
201for item in auto_configrules.dird_runscript_items:
202    item.required=False
203    item.printall=True
204    print item2field(confshort,item, res_name)
205print """ format='runscript-%(id)s')
206"""
207#print """db.define_table('%s_conf__%s_link', 
208#  Field('%s','reference %s_conf__%s'),
209#  format = '%%(id)s')
210#    """ %  (confshort,res_name, res_name, confshort,res_name)
211
212
213# TODO: folgende linktabellen herstellen
214# TODO: include_to_options
215# TODO: fileset_to_include
216# TODO: fileset_to_exclude
217# TODO: job_to_runscript_items
218
219
220# Anlegen der eigentlichen Speicherplätze für die Ressourcen
221
222dir_res_list = list()
223 
224confshort = 'dird'
225for res in auto_configrules.dird_resources:
226  res_name = res[0]
227  res_type = res[1]
228  res_items = res[2]
229  dir_res_list.append(res_name)
230  print
231  #print res_name
232  print """db.define_table('%s_conf__%s',  """ % (confshort, res_name)
233  for item in res_items:
234    item.required=False
235    item.printall=True
236    print item2field(confshort,item, res_name)
237  print """ format='%(name)s')"""
238
239
240confshort = 'stored'
241stor_res_list = list()
242for res in auto_configrules.stored_resources:
243  res_name = res[0]
244  res_type = res[1]
245  res_items = res[2]
246  stor_res_list.append(res_name)
247  print
248  #print res_name
249  print """db.define_table('%s_conf__%s',  """ % (confshort,res_name)
250  for item in res_items:
251    item.required=False
252    item.printall=True
253    print item2field(confshort,item, res_name)
254  print """ format='%(name)s')"""
255
256
257confshort = 'filed'
258filed_res_list = list()
259for res in auto_configrules.filed_resources:
260  res_name = res[0]
261  res_type = res[1]
262  res_items = res[2]
263  filed_res_list.append(res_name)
264  print
265  #print res_name
266  print """db.define_table('%s_conf__%s',  """ % (confshort,res_name)
267  for item in res_items:
268    item.required=False
269    item.printall=True
270    print item2field(confshort,item, res_name)
271  print """ format='%(name)s')"""
272
273confshort = 'cons'
274cons_res_list = list()
275for res in auto_configrules.console_resources:
276  res_name = res[0]
277  res_type = res[1]
278  res_items = res[2]
279  cons_res_list.append(res_name)
280  print
281  #print res_name
282  print """db.define_table('%s_conf__%s',  """ % (confshort,res_name)
283  for item in res_items:
284    item.required=False
285    item.printall=True
286    print item2field(confshort,item, res_name)
287  print """ format='%(name)s')"""
288
289
290
291
292
293for confshort  in ['dird','stored','filed','cons']:
294
295
296  print "\n#the table representing the %s configuration file" % (confshort)
297
298  print """db.define_table('%s_conf',
299    Field('name','string'),
300    format='%%(name)s') """ % (confshort)
301
302  print "\n#link tables between %s configs and %s config ressources" % (confshort, confshort)
303
304  for res in dir_res_list:   
305    print """db.define_table('%s_conf_to_%s',
306    Field('%s_conf','reference %s_conf'),
307    Field('%s','reference %s_conf__%s'),
308    format = '%%(id)s')
309    """ % (confshort,res,confshort,confshort,res,confshort,res)
310
311
312
313
314
315
316print "# items that can appear multiple times"
317confshort = 'dird'
318for name in  MULTIPLE_ALLOWED_ITEMS_SET:
319
320  # create the table itself
321  print """db.define_table('%s_conf__%s', 
322    Field('%s','string', default=''),
323  format = '%%(%s)s')
324    """ %  (confshort, name, name, name ) 
325 
326  # create the linking tables
327  # plugin and file belong to dird_fileset_includes,
328  # runscript belong to job ressource
329  if name == 'run':
330    parent_res = 'schedule'
331  else:
332    parent_res = 'include'
333   
334  print """db.define_table('%s_conf__%s_to_%s_conf__%s', 
335    Field('%s_conf__%s','reference %s_conf__%s'),
336    Field('%s_conf__%s','reference %s_conf__%s'),
337  format = '%%(id)s')
338    """ %  (confshort,name,confshort,parent_res,
339            confshort,name,confshort,name,
340            confshort,parent_res,confshort,parent_res)
341
342
343
344
345
346
347
348
349#    print """db.define_table('dird_conf_to_%s',
350#    Field('dird_conf','reference dird_conf'),
351#    Field('%s','reference dird_conf__%s'),
352#    format = '%%(id)s')
353#    """ % (res,res,res)
354   
355 
356#for res in dir_res_list:
357#  print "  Field('dird_conf__%s', 'reference dirs_to_%ss')," % (res,res )
358#print """  format='%(name)s')
359#"""
360
361
362
363#for res in stor_res_list:   
364#  print """db.define_table('stord_conf__%s_link',
365#  Field('%s','reference stord_conf__%s'),
366#  format = '%%(id)s')
367#    """ % (res,res,res)
368#print """db.define_table('stord_conf',
369#  Field('name','string'),"""
370#
371#for res in stor_res_list:
372#  print "  Field('stord_conf__%s', 'reference stord_conf__%s_link')," % (res,res )
373#print """  format='%(name)s')
374#"""
375#
376#
377#
378#for res in filed_res_list:   
379#  print """db.define_table('filed_conf__%s_link',
380#  Field('%s','reference filed_conf__%s'),
381#  format = '%%(id)s')
382#    """ % (res,res,res)
383#print """db.define_table('filed_conf',
384#  Field('name','string'),"""
385#
386#for res in filed_res_list:
387#  print "  Field('filed_conf__%s', 'reference filed_conf__%s_link')," % (res,res )
388#print """  format='%(name)s')
389#"""
390#
391#
392#
393#for res in cons_res_list:   
394#  print """db.define_table('cons_conf__%s_link',
395#  Field('%s','reference cons_conf__%s'),
396#  format = '%%(id)s')
397#    """ % (res,res,res)
398#print """db.define_table('cons_conf',
399#  Field('name','string'),"""
400#
401#for res in cons_res_list:
402#  print "  Field('cons_conf__%s', 'reference cons_conf__%s_link')," % (res,res )
403#print """  format='%(name)s')
404#"""
405#
406
407
408
409
410
411
412
413#Abhängikeiten:
414# dird
415#  job/jobdefs   ->client
416#                -> pool
417#                -> fileset
418#                -> pool
419#                -> messages
420#                -> schedule
421#                -> storage
422#                -> jobdefs
423#                -> job
424# messages   -> catalog
425# counter    -> catalog
426# storage    -> device
427# director   -> messages
428# client     -> catalog
429# pool       -> catalog, storage
430
431
432# Reihenfolge:
433# storage->catalog->fileset->pool->jobdefs->client->
434# counter->messages->job->director
435
436
437
438# stored:
439# autochanger -> device
440# storage  -> messages
441# messages -> catalog
442
443# filed:
444# messages -> catalog
445# client/filedaemon -> messages
446
447
448
449
450# Tabellenarchitektur:
451
452
453# Zur Speicherung der verschiedenen Ressourcentypen benötigen
454# wir jeweils eine Tabelle für jeden Ressourcentyp
455
456
457
458
459# jede Konfigurationsdatei hat wird durch eine Tabelle dargestellt:
460#db.dirdconf
461#db.consconf
462#db.stordconf
463#db.filedconf
464
465# da jeder dieser Konfigurationsdateien ressourcen
466# enthalten kann, auch unterschiedlichen Typs,
467# enthält jede Konfigdateitabelle einen Verweis auf eine
468# Tabelle des jeweiligen ressourcentyps.
469# Diese Tabelle verweist dann auf die eigentlichen Ressourcen:
470
471
472
473
474
475
476
477
478
479
480
481
482
483
Note: See TracBrowser for help on using the repository browser.