1
0
Fork 0

r1083@denkpolster: jan | 2008-04-04 20:36:31 +0200

work on compatibility issues
  * make gnuviechadmin compatible with (fixes #6)
  * setup database at startup if necessary (fixes #8)


git-svn-id: file:///home/www/usr01/svn/gnuviechadmin/trunk@248 a67ec6bc-e5d5-0310-a910-815c51eb3124
This commit is contained in:
Jan Dittberner 2008-04-04 18:36:46 +00:00
parent c049fd9bc9
commit 4ae866c559
7 changed files with 52 additions and 30 deletions

View file

@ -2,7 +2,7 @@ from sqlalchemy import *
from migrate import *
from gnuviechadmin.backend.settings import dbschema
meta = BoundMetaData(migrate_engine)
meta = MetaData(migrate_engine)
client = Table(
'client', meta,
Column('clientid', Integer, primary_key=True),
@ -29,7 +29,7 @@ sysuser = Table(
Column('shell', Boolean, nullable=False, default=False),
Column('clearpass', String(64)),
Column('md5pass', String(34)),
Column('clientid', Integer, ForeignKey("client.clientid"),
Column('clientid', Integer, ForeignKey(client.c.clientid),
nullable=False),
Column('sysuid', Integer, nullable=False, unique=True),
Column('lastchange', DateTime, default=func.now()),
@ -43,14 +43,14 @@ domain = Table(
Column('last_check', Integer),
Column('type', String(6), nullable=False),
Column('notified_serial', Integer),
Column('sysuserid', Integer, ForeignKey("sysuser.sysuserid"),
Column('sysuserid', Integer, ForeignKey(sysuser.c.sysuserid),
nullable=False),
schema = dbschema
)
record = Table(
'record', meta,
Column('recordid', Integer, primary_key=True),
Column('domainid', Integer, ForeignKey("domain.domainid"),
Column('domainid', Integer, ForeignKey(domain.c.domainid),
nullable=False),
Column('name', String(255)),
Column('type', String(6)),
@ -64,7 +64,7 @@ supermaster = Table(
'supermaster', meta,
Column('ip', String(25), nullable=False),
Column('nameserver', String(255), nullable=False),
Column('account', Integer, ForeignKey("sysuser.sysuserid"),
Column('account', Integer, ForeignKey(sysuser.c.sysuserid),
nullable=False),
schema = dbschema
)

View file

@ -2,12 +2,12 @@ from sqlalchemy import *
from migrate import *
from gnuviechadmin.backend.settings import dbschema
meta = BoundMetaData(migrate_engine)
meta = MetaData(migrate_engine)
domain = Table('domain', meta, schema = dbschema, autoload = True)
mailaccount = Table(
'mailaccount', meta,
Column('mailaccountid', Integer, primary_key = True),
Column('domainid', Integer, ForeignKey('domain.domainid'),
Column('domainid', Integer, ForeignKey(domain.c.domainid),
nullable = False),
Column('mailaccount', String(12), nullable = False, unique = True),
Column('clearpass', String(64)),
@ -22,7 +22,7 @@ mailaccount = Table(
mailaddress = Table(
'mailaddress', meta,
Column('mailaddressid', Integer, primary_key = True),
Column('domainid', Integer, ForeignKey('domain.domainid'),
Column('domainid', Integer, ForeignKey(domain.c.domainid),
nullable = False),
Column('email', String(255), nullable = False),
UniqueConstraint('email', 'domainid'),
@ -31,7 +31,7 @@ mailaddress = Table(
mailtarget = Table(
'mailtarget', meta,
Column('mailtargetid', Integer, primary_key = True),
Column('mailaddressid', Integer, ForeignKey('mailaddress.mailaddressid'),
Column('mailaddressid', Integer, ForeignKey(mailaddress.c.mailaddressid),
nullable = False),
Column('target', String(128), nullable = False),
UniqueConstraint('target', 'mailaddressid'),

View file

@ -1,6 +1,7 @@
# -*- python -*-
# -*- coding: utf-8 -*-
#
# Copyright (C) 2007 by Jan Dittberner.
# Copyright (C) 2007, 2008 by Jan Dittberner.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -26,6 +27,7 @@ from gnuviechadmin.exceptions import *
from gnuviechadmin.util import gpgmail
from subprocess import *
import sqlalchemy
from sqlalchemy.orm import object_mapper
class BackendEntity(object):
"""This is the abstract base class for all backend entity classes."""
@ -92,7 +94,7 @@ class BackendEntity(object):
values."""
missingfields = []
for key in [col.name for col in \
sqlalchemy.object_mapper(
object_mapper(
self.delegateto).local_table.columns \
if not col.primary_key and not col.nullable]:
if self.delegateto.__getattribute__(key) is None:

View file

@ -1,6 +1,7 @@
# -*- coding: UTF-8 -*-
# -*- python -*-
# -*- coding: utf-8 -*-
#
# Copyright (C) 2007 by Jan Dittberner.
# Copyright (C) 2007, 2008 by Jan Dittberner.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -20,6 +21,7 @@
# Version: $Id$
import sqlalchemy, logging
from sqlalchemy.orm import create_session
from gnuviechadmin.exceptions import *
from BackendEntity import *
@ -35,7 +37,7 @@ class BackendEntityHandler(object):
"""Create a new entity of the managed type with the fields set
to the values in kwargs."""
self.logger.debug("create with params %s", str(kwargs))
sess = sqlalchemy.create_session()
sess = create_session()
transaction = sess.create_transaction()
delegate = self.toclass(**kwargs)
entity = self.entityclass(delegate, self.verbose)
@ -54,12 +56,12 @@ class BackendEntityHandler(object):
def fetchall(self, **kwargs):
"""Fetches all entities of the managed entity type."""
self.logger.debug("fetchall with params %s", str(kwargs))
session = sqlalchemy.create_session()
session = create_session()
query = session.query(self.toclass)
if kwargs:
allentities = query.select_by(**kwargs)
allentities = query.filter_by(**kwargs).all()
else:
allentities = query.select()
allentities = query.all()
return [self.entityclass(entity, self.verbose) \
for entity in allentities]
@ -67,7 +69,7 @@ class BackendEntityHandler(object):
"""Deletes the entity of the managed entity type that has the
specified primary key value."""
self.logger.debug("delete with primary key %s", str(pkvalue))
sess = sqlalchemy.create_session()
sess = create_session()
transaction = sess.create_transaction()
try:
to = sess.query(self.toclass).get(pkvalue)

View file

@ -1,3 +1,4 @@
# -*- python -*-
# -*- coding: utf-8 -*-
#
# Copyright (C) 2007, 2008 by Jan Dittberner.
@ -19,7 +20,7 @@
#
# Version: $Id$
from sqlalchemy.orm import object_mapper
from sqlalchemy.orm import object_mapper, mapper, relation
from tables import *

View file

@ -1,3 +1,4 @@
# -*- python -*-
# -*- coding: utf-8 -*-
#
# Copyright (C) 2007, 2008 by Jan Dittberner.
@ -30,19 +31,34 @@ try:
config.get('database', 'uri'),
config.get('database', 'repository'))
if dbversion < required_version:
print("""Database version is %d but required version is %d, run
migrate upgrade %s %s
to fix this.""" %
(dbversion, required_version, config.get('database', 'uri'),
config.get('database', 'repository')))
print("""Database version is %d but required version is %d. Trying automatic upgrade.""" %
(dbversion, required_version))
try:
migrate.versioning.api.upgrade(
config.get('database', 'uri'),
config.get('database', 'repository'),
required_version)
except:
print "Automatic upgrade failed."
raise
elif dbversion > required_version:
print("""Database version is %d which is higher than the required version %d. I cannot handle this situation without possible data loss.""" %
(dbversion, required_version))
sys.exit(1)
except NoSuchTableError, nste:
print nste
sys.exit(1)
print """The database is not versioned. Trying automatic versioning."""
try:
migrate.versioning.api.version_control(
config.get('database', 'uri'),
config.get('database', 'repository'))
migrate.versioning.api.upgrade(
config.get('database', 'uri'),
config.get('database', 'repository', required_version))
except:
print "Automatic setup failed."
raise
meta = BoundMetaData(config.get('database', 'uri'))
meta = MetaData(config.get('database', 'uri'))
#meta.engine.echo = True
client_table = Table('client', meta, schema = dbschema, autoload = True)
sysuser_table = Table('sysuser', meta, schema = dbschema, autoload = True)

View file

@ -1,6 +1,7 @@
# -*- python -*-
# -*- coding: utf-8 -*-
#
# Copyright (C) 2007 by Jan Dittberner.
# Copyright (C) 2007, 2008 by Jan Dittberner.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by