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:
parent
c049fd9bc9
commit
4ae866c559
7 changed files with 52 additions and 30 deletions
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 *
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue