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

Last change on this file since 989 was 989, checked in by pstorz, on Apr 6, 2012 at 10:59:44 AM

generate web2py

File size: 3.6 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
53dir_res_list = list()
54
55for res in auto_configrules.dird_resources:
56 res_name = res[0]
57 res_type = res[1]
58 res_items = res[2]
59 dir_res_list.append(res_name)
60 print
61 #print res_name
62 print """db.define_table('dird_conf__%s', """ % (res_name)
63 for item in res_items:
64 item.required=False
65 item.printall=True
66 if item.name == 'where' : # where cannot be a column name in sqlite
67 item.name = 'where_'
68 print """ Field('%s','string', default='%s'), """ %(item.name , item.defaultvalue)
69 #print item.name
70 print """ format='%(name)s')"""
71
72
73
74stor_res_list = list()
75for res in auto_configrules.stored_resources:
76 res_name = res[0]
77 res_type = res[1]
78 res_items = res[2]
79 stor_res_list.append(res_name)
80 print
81 #print res_name
82 print """db.define_table('stored_conf__%s', """ % (res_name)
83 for item in res_items:
84 item.required=False
85 item.printall=True
86 if item.name == 'where' : # where cannot be a column name in sqlite
87 item.name = 'where_'
88 print """ Field('%s','string', default='%s'), """ %(item.name , item.defaultvalue)
89 #print item.name
90 print """ format='%(name)s')"""
91
92
93
94filed_res_list = list()
95for res in auto_configrules.filed_resources:
96 res_name = res[0]
97 res_type = res[1]
98 res_items = res[2]
99 filed_res_list.append(res_name)
100 print
101 #print res_name
102 print """db.define_table('filed_conf__%s', """ % (res_name)
103 for item in res_items:
104 item.required=False
105 item.printall=True
106 if item.name == 'where' : # where cannot be a column name in sqlite
107 item.name = 'where_'
108 print """ Field('%s','string', default='%s'), """ %(item.name , item.defaultvalue)
109 #print item.name
110 print """ format='%(name)s')"""
111
112
113
114
115
116
117
118
119
120
121for res in dir_res_list:
122# print """db.define_table('dird_conf__%s',
123# Field('name','string'),
124# format = '%%(name)s')
125# """ % (res)
126
127 print """db.define_table('dird_conf__%s_link',
128 Field('%s','reference dird_conf__%s'),
129 format = '%%(id)s')
130 """ % (res,res,res)
131
132
133
134print """db.define_table('dird_conf',
135 Field('name','string'),"""
136for res in dir_res_list:
137 print " Field('dird_conf__%s', 'reference dird_conf__%s_link')," % (res,res )
138print """ format='%(name)s')
139"""
140
141
142
143
144
145#for item in auto_configrules.dird_cat_items:
146# item.required=False
147# print """
148# Field('%s','reference dird_conf_catalog'),
149# """
Note: See TracBrowser for help on using the repository browser.