root / pykota / trunk / pykota / storage.py @ 697

Revision 697, 1.5 kB (checked in by jalet, 21 years ago)

import statement didn't work as expected

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1# PyKota
2#
3# PyKota : Print Quotas for CUPS
4#
5# (c) 2003 Jerome Alet <alet@librelogiciel.com>
6# You're welcome to redistribute this software under the
7# terms of the GNU General Public Licence version 2.0
8# or, at your option, any higher version.
9#
10# You can read the complete GNU GPL in the file COPYING
11# which should come along with this software, or visit
12# the Free Software Foundation's WEB site http://www.fsf.org
13#
14# $Id$
15#
16# $Log$
17# Revision 1.2  2003/02/05 22:02:22  jalet
18# __import__ statement didn't work as expected
19#
20# Revision 1.1  2003/02/05 21:28:17  jalet
21# Initial import into CVS
22#
23#
24#
25
26class PyKotaStorageError(Exception):
27    """An exception for Quota Storage related stuff."""
28    def __init__(self, message = ""):
29        self.message = message
30        Exception.__init__(self, message)
31    def __repr__(self):
32        return self.message
33    __str__ = __repr__
34   
35def openConnection(config, asadmin=0) :
36    """Returns a connection handle to the appropriate Quota Storage Database."""
37    (backend, host, database, admin, user) = config.getStorageBackend()
38    try :
39        if not isalpha(backend) :
40            # don't trust user input
41            raise ImportError
42        exec "from pykota.storages import %s as storagebackend" % backend.lower()   
43    except ImportError :
44        raise PyKotaStorageError, "Unsupported quota storage backend %s" % backend
45    else :   
46        return getattr(storagebackend, "Storage")(host, database, (asadmin and admin) or user)
Note: See TracBrowser for help on using the browser.