[989] | 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 |
|
---|
| 34 | from nosferatu.config_classes import *
|
---|
| 35 | from resource import Resource
|
---|
| 36 | from 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 |
|
---|
[990] | 53 |
|
---|
| 54 |
|
---|
| 55 |
|
---|
| 56 | def item2field(item):
|
---|
| 57 | if item.name == 'where' : # where cannot be a column name in sqlite
|
---|
| 58 | item.name = 'where_'
|
---|
| 59 |
|
---|
| 60 | if item.name in INTERNALLY_REFERENCED_ITEMS:
|
---|
| 61 | refname = item.name
|
---|
| 62 | if item.name.endswith('pool'):
|
---|
| 63 | refname = 'pool'
|
---|
| 64 | fieldtype = 'reference dird_conf__%s' % (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 |
|
---|
[989] | 81 | dir_res_list = list()
|
---|
| 82 |
|
---|
| 83 | for res in auto_configrules.dird_resources:
|
---|
| 84 | res_name = res[0]
|
---|
| 85 | res_type = res[1]
|
---|
| 86 | res_items = res[2]
|
---|
| 87 | dir_res_list.append(res_name)
|
---|
| 88 | print
|
---|
| 89 | #print res_name
|
---|
| 90 | print """db.define_table('dird_conf__%s', """ % (res_name)
|
---|
| 91 | for item in res_items:
|
---|
| 92 | item.required=False
|
---|
| 93 | item.printall=True
|
---|
[990] | 94 | print item2field(item)
|
---|
[989] | 95 | print """ format='%(name)s')"""
|
---|
| 96 |
|
---|
| 97 |
|
---|
| 98 |
|
---|
| 99 | stor_res_list = list()
|
---|
| 100 | for res in auto_configrules.stored_resources:
|
---|
| 101 | res_name = res[0]
|
---|
| 102 | res_type = res[1]
|
---|
| 103 | res_items = res[2]
|
---|
| 104 | stor_res_list.append(res_name)
|
---|
| 105 | print
|
---|
| 106 | #print res_name
|
---|
| 107 | print """db.define_table('stored_conf__%s', """ % (res_name)
|
---|
| 108 | for item in res_items:
|
---|
| 109 | item.required=False
|
---|
| 110 | item.printall=True
|
---|
[990] | 111 | print item2field(item)
|
---|
[989] | 112 | print """ format='%(name)s')"""
|
---|
| 113 |
|
---|
| 114 |
|
---|
| 115 |
|
---|
| 116 | filed_res_list = list()
|
---|
| 117 | for res in auto_configrules.filed_resources:
|
---|
| 118 | res_name = res[0]
|
---|
| 119 | res_type = res[1]
|
---|
| 120 | res_items = res[2]
|
---|
| 121 | filed_res_list.append(res_name)
|
---|
| 122 | print
|
---|
| 123 | #print res_name
|
---|
| 124 | print """db.define_table('filed_conf__%s', """ % (res_name)
|
---|
| 125 | for item in res_items:
|
---|
| 126 | item.required=False
|
---|
| 127 | item.printall=True
|
---|
[990] | 128 | print item2field(item)
|
---|
[989] | 129 | print """ format='%(name)s')"""
|
---|
| 130 |
|
---|
| 131 |
|
---|
| 132 |
|
---|
| 133 |
|
---|
| 134 |
|
---|
| 135 |
|
---|
| 136 |
|
---|
| 137 |
|
---|
| 138 |
|
---|
| 139 |
|
---|
| 140 | for res in dir_res_list:
|
---|
| 141 | # print """db.define_table('dird_conf__%s',
|
---|
| 142 | # Field('name','string'),
|
---|
| 143 | # format = '%%(name)s')
|
---|
| 144 | # """ % (res)
|
---|
| 145 |
|
---|
| 146 | print """db.define_table('dird_conf__%s_link',
|
---|
| 147 | Field('%s','reference dird_conf__%s'),
|
---|
| 148 | format = '%%(id)s')
|
---|
| 149 | """ % (res,res,res)
|
---|
| 150 |
|
---|
| 151 |
|
---|
| 152 |
|
---|
| 153 | print """db.define_table('dird_conf',
|
---|
| 154 | Field('name','string'),"""
|
---|
| 155 | for res in dir_res_list:
|
---|
| 156 | print " Field('dird_conf__%s', 'reference dird_conf__%s_link')," % (res,res )
|
---|
| 157 | print """ format='%(name)s')
|
---|
| 158 | """
|
---|
| 159 |
|
---|
| 160 |
|
---|
| 161 |
|
---|
| 162 |
|
---|
| 163 |
|
---|
| 164 | #for item in auto_configrules.dird_cat_items:
|
---|
| 165 | # item.required=False
|
---|
| 166 | # print """
|
---|
| 167 | # Field('%s','reference dird_conf_catalog'),
|
---|
| 168 | # """
|
---|