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

Last change on this file since 991 was 991, checked in by pstorz, on Apr 7, 2012 at 5:44:00 PM

director ressource sorted differently

File size: 6.0 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
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):
55 if item.name == 'where' : # where cannot be a column name in sqlite
56 item.name = 'where_'
57
58 if item.name in INTERNALLY_REFERENCED_ITEMS:
59 refname = item.name
60 if item.name.endswith('pool'):
61 refname = 'pool'
62 print '### ' + refname
63
64 fieldtype = 'reference %s_conf__%s' % (confshort,refname)
65 defaultvalue = 0
66 return """ Field('%s','%s', default=%s), """ %(item.name, fieldtype , defaultvalue)
67 else:
68 fieldtype = 'string'
69 defaultvalue = item.defaultvalue
70 if item.type == "store_bool":
71 fieldtype = "boolean"
72 #print "#####%s %s %s" % (item.name, item.defaultvalue, defaultvalue)
73 return """ Field('%s','%s', default=%s), """ %(item.name, fieldtype , defaultvalue)
74 return """ Field('%s','%s', default='%s'), """ %(item.name, fieldtype , defaultvalue)
75
76
77
78
79
80
81dir_res_list = list()
82
83confshort = 'dird'
84for res in auto_configrules.dird_resources:
85 res_name = res[0]
86 res_type = res[1]
87 res_items = res[2]
88 dir_res_list.append(res_name)
89 print
90 #print res_name
91 print """db.define_table('%s_conf__%s', """ % (confshort,res_name)
92 for item in res_items:
93 item.required=False
94 item.printall=True
95 print item2field(confshort,item)
96 print """ format='%(name)s')"""
97
98
99confshort = 'stored'
100stor_res_list = list()
101for res in auto_configrules.stored_resources:
102 res_name = res[0]
103 res_type = res[1]
104 res_items = res[2]
105 stor_res_list.append(res_name)
106 print
107 #print res_name
108 print """db.define_table('%s_conf__%s', """ % (confshort,res_name)
109 for item in res_items:
110 item.required=False
111 item.printall=True
112 print item2field(confshort,item)
113 print """ format='%(name)s')"""
114
115
116confshort = 'filed'
117filed_res_list = list()
118for res in auto_configrules.filed_resources:
119 res_name = res[0]
120 res_type = res[1]
121 res_items = res[2]
122 filed_res_list.append(res_name)
123 print
124 #print res_name
125 print """db.define_table('%s_conf__%s', """ % (confshort,res_name)
126 for item in res_items:
127 item.required=False
128 item.printall=True
129 print item2field(confshort,item)
130 print """ format='%(name)s')"""
131
132confshort = 'cons'
133cons_res_list = list()
134for res in auto_configrules.console_resources:
135 res_name = res[0]
136 res_type = res[1]
137 res_items = res[2]
138 cons_res_list.append(res_name)
139 print
140 #print res_name
141 print """db.define_table('%s_conf__%s', """ % (confshort,res_name)
142 for item in res_items:
143 item.required=False
144 item.printall=True
145 print item2field(confshort,item)
146 print """ format='%(name)s')"""
147
148
149
150
151
152for res in dir_res_list:
153 print """db.define_table('dird_conf__%s_link',
154 Field('%s','reference dird_conf__%s'),
155 format = '%%(id)s')
156 """ % (res,res,res)
157print """db.define_table('dird_conf',
158 Field('name','string'),"""
159
160for res in dir_res_list:
161 print " Field('dird_conf__%s', 'reference dird_conf__%s_link')," % (res,res )
162print """ format='%(name)s')
163"""
164
165
166
167for res in stor_res_list:
168 print """db.define_table('stord_conf__%s_link',
169 Field('%s','reference stord_conf__%s'),
170 format = '%%(id)s')
171 """ % (res,res,res)
172print """db.define_table('stord_conf',
173 Field('name','string'),"""
174
175for res in stor_res_list:
176 print " Field('stord_conf__%s', 'reference stord_conf__%s_link')," % (res,res )
177print """ format='%(name)s')
178"""
179
180
181
182for res in filed_res_list:
183 print """db.define_table('filed_conf__%s_link',
184 Field('%s','reference filed_conf__%s'),
185 format = '%%(id)s')
186 """ % (res,res,res)
187print """db.define_table('filed_conf',
188 Field('name','string'),"""
189
190for res in filed_res_list:
191 print " Field('filed_conf__%s', 'reference filed_conf__%s_link')," % (res,res )
192print """ format='%(name)s')
193"""
194
195
196
197
198for res in cons_res_list:
199 print """db.define_table('cons_conf__%s_link',
200 Field('%s','reference cons_conf__%s'),
201 format = '%%(id)s')
202 """ % (res,res,res)
203print """db.define_table('cons_conf',
204 Field('name','string'),"""
205
206for res in cons_res_list:
207 print " Field('cons_conf__%s', 'reference cons_conf__%s_link')," % (res,res )
208print """ format='%(name)s')
209"""
210
211
212#Abhängikeiten:
213# dird
214# job/jobdefs ->client
215# -> pool
216# -> fileset
217# -> pool
218# -> messages
219# -> schedule
220# -> storage
221# -> jobdefs
222# -> job
223# messages -> catalog
224# counter -> catalog
225# storage -> device
226# director -> messages
227# client -> catalog
228# pool -> catalog, storage
229
230
231# Reihenfolge:
232# storage->catalog->fileset->pool->jobdefs->client->
233# counter->messages->job->director
234
235
236
237# stored:
238# autochanger -> device
239# storage -> messages
240# messages -> catalog
241
242# filed:
243# messages -> catalog
244# client/filedaemon -> messages
245
246
247
248
249
Note: See TracBrowser for help on using the repository browser.