- configuration information file (like mailman)
- GNU GPL information in each file - more pythonic way to define attributes - exception class git-svn-id: file:///home/www/usr01/svn/gnuviechadmin/gnuviech.info/gnuviechadmin/trunk@215 a67ec6bc-e5d5-0310-a910-815c51eb3124
This commit is contained in:
parent
adbf8e440d
commit
a0778661c6
6 changed files with 200 additions and 47 deletions
|
@ -1,16 +1,28 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: UTF-8 -*-
|
# -*- coding: UTF-8 -*-
|
||||||
#
|
#
|
||||||
# This file is part of gnuviechadmin.
|
# Copyright (C) 2007 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
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful, but
|
||||||
|
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
# General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||||
|
# USA.
|
||||||
#
|
#
|
||||||
# Author: Jan Dittberner <jan@dittberner.info>
|
|
||||||
# Copyright (c) 2007 Jan Dittberner
|
|
||||||
# Version: $Id$
|
# Version: $Id$
|
||||||
|
|
||||||
import getopt, sys
|
import getopt, sys, sqlalchemy
|
||||||
from sqlalchemy import *
|
|
||||||
|
|
||||||
from gnuviechadmin import client
|
from gnuviechadmin import client, exceptions
|
||||||
|
|
||||||
def usage():
|
def usage():
|
||||||
print """Usage: %s [-h|--help] [-v|--verbose]
|
print """Usage: %s [-h|--help] [-v|--verbose]
|
||||||
|
@ -91,13 +103,19 @@ def main():
|
||||||
clientdata["phone"] = a
|
clientdata["phone"] = a
|
||||||
if verbose:
|
if verbose:
|
||||||
print "parsed client data is ", clientdata
|
print "parsed client data is ", clientdata
|
||||||
myclient = client.Client(clientdata)
|
try:
|
||||||
if not myclient:
|
myclient = client.Client(**clientdata)
|
||||||
|
except exceptions.MissingFieldsError, mfe:
|
||||||
|
print mfe
|
||||||
usage()
|
usage()
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
sess = create_session()
|
try:
|
||||||
sess.save(myclient)
|
sess = sqlalchemy.create_session()
|
||||||
sess.flush()
|
sess.save(myclient)
|
||||||
|
sess.flush()
|
||||||
|
except sqlalchemy.exceptions.SQLError, e:
|
||||||
|
print "saving client failed: ", e
|
||||||
|
sys.exit(2)
|
||||||
if verbose:
|
if verbose:
|
||||||
print myclient
|
print myclient
|
||||||
|
|
||||||
|
|
34
gnuviechadmin/Defaults.py
Normal file
34
gnuviechadmin/Defaults.py
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
# -*- python -*-
|
||||||
|
#
|
||||||
|
# Copyright (C) 2007 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
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful, but
|
||||||
|
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
# General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||||
|
# USA.
|
||||||
|
#
|
||||||
|
# Version: $Id$
|
||||||
|
|
||||||
|
"""Distributed default settings for significant GnuviechAdmin config
|
||||||
|
variables."""
|
||||||
|
|
||||||
|
# NEVER make site configuration changes to this file. ALWAYS make
|
||||||
|
# them in gva_cfg.py instead, in the designated area. See the
|
||||||
|
# comments in that file for details.
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------
|
||||||
|
# The database connection string in a format usable for
|
||||||
|
# sqlalchemy. The default is an sqlite in memory database which is not
|
||||||
|
# very usable for a real installation.
|
||||||
|
#
|
||||||
|
GVA_DBE = 'sqlite:///:memory:'
|
|
@ -1,11 +1,22 @@
|
||||||
# This file is part of gnuviechadmin.
|
|
||||||
# -*- coding: UTF-8 -*-
|
# -*- coding: UTF-8 -*-
|
||||||
#
|
#
|
||||||
# Author: Jan Dittberner <jan@dittberner.info>
|
# Copyright (C) 2007 by Jan Dittberner.
|
||||||
# Copyright (c) 2007, 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
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful, but
|
||||||
|
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
# General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||||
|
# USA.
|
||||||
|
#
|
||||||
# Version: $Id$
|
# Version: $Id$
|
||||||
|
|
||||||
"""
|
"""This is the gnuviechadmin package."""
|
||||||
This is the gnuviechadmin package.
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
|
@ -1,13 +1,28 @@
|
||||||
# This file is part of gnuviechadmin.
|
|
||||||
# -*- coding: UTF-8 -*-
|
# -*- coding: UTF-8 -*-
|
||||||
#
|
#
|
||||||
# Author: Jan Dittberner <jan@dittberner.info>
|
# Copyright (C) 2007 by Jan Dittberner.
|
||||||
# Copyright (c) 2007 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
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful, but
|
||||||
|
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
# General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||||
|
# USA.
|
||||||
|
#
|
||||||
# Version: $Id$
|
# Version: $Id$
|
||||||
|
|
||||||
from sqlalchemy import *
|
from sqlalchemy import *
|
||||||
|
from gnuviechadmin import gva_cfg, exceptions
|
||||||
|
|
||||||
meta = BoundMetaData('sqlite:///database.txt')
|
meta = BoundMetaData(gva_cfg.GVA_DBE)
|
||||||
client_table = Table('clients', meta,
|
client_table = Table('clients', meta,
|
||||||
Column('clientid', Integer, primary_key=True),
|
Column('clientid', Integer, primary_key=True),
|
||||||
Column('title', String(10)),
|
Column('title', String(10)),
|
||||||
|
@ -25,32 +40,29 @@ client_table = Table('clients', meta,
|
||||||
client_table.create(checkfirst=True)
|
client_table.create(checkfirst=True)
|
||||||
|
|
||||||
class Client(object):
|
class Client(object):
|
||||||
|
mandatory = ('firstname', 'lastname', 'address1', 'zip', 'city',
|
||||||
|
'country', 'phone', 'email')
|
||||||
|
|
||||||
"""This class provides a client representation"""
|
"""This class provides a client representation"""
|
||||||
def __init__(self, clientdata):
|
def __init__(self, **kwargs):
|
||||||
mandatory = ('firstname', 'lastname', 'address1', 'zip', 'city',
|
self.clientid = None
|
||||||
'email', 'phone', 'country')
|
self.country = 'de'
|
||||||
data = {"country": "de", "title": None, "address2": None,
|
self.title = None
|
||||||
"mobile": None, "fax": None, "organisation": None}
|
self.address2 = None
|
||||||
for key in clientdata.keys():
|
self.mobile = None
|
||||||
data[key] = clientdata[key]
|
self.fax = None
|
||||||
for key in mandatory:
|
self.organisation = None
|
||||||
if not key in data:
|
for key in kwargs.keys():
|
||||||
print "mandatory client field %s is missing" % (key)
|
self.__setattr__(key, kwargs[key])
|
||||||
self = None
|
self.validate()
|
||||||
return
|
|
||||||
self.title = data["title"]
|
def validate(self):
|
||||||
self.firstname = data["firstname"]
|
missingfields = []
|
||||||
self.lastname = data["lastname"]
|
for key in self.mandatory:
|
||||||
self.address1 = data["address1"]
|
if self.__getattribute__(key) is None:
|
||||||
self.address2 = data["address2"]
|
missingfields.append(key)
|
||||||
self.organisation = data["organisation"]
|
if missingfields:
|
||||||
self.zip = data["zip"]
|
raise exceptions.MissingFieldsError(missingfields)
|
||||||
self.city = data["city"]
|
|
||||||
self.country = data["country"]
|
|
||||||
self.phone = data["phone"]
|
|
||||||
self.mobile = data["mobile"]
|
|
||||||
self.fax = data["fax"]
|
|
||||||
self.email = data["email"]
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return """Client (Id %(clientid)d):
|
return """Client (Id %(clientid)d):
|
||||||
|
|
30
gnuviechadmin/exceptions.py
Normal file
30
gnuviechadmin/exceptions.py
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
# -*- coding: UTF-8 -*-
|
||||||
|
#
|
||||||
|
# Copyright (C) 2007 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
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful, but
|
||||||
|
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
# General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||||
|
# USA.
|
||||||
|
#
|
||||||
|
# Version: $Id$
|
||||||
|
|
||||||
|
"""This file defines the gnuviechadmin specific exception types."""
|
||||||
|
class MissingFieldsError(Exception):
|
||||||
|
"""This exception should be raised when a required field of a data
|
||||||
|
class is missing."""
|
||||||
|
def __init__(self, missingfields):
|
||||||
|
self.missing = missingfields
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return "the fields %s are missing." % (repr(self.missing))
|
48
gnuviechadmin/gva_cfg.py.tmpl
Normal file
48
gnuviechadmin/gva_cfg.py.tmpl
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
# -*- python -*-
|
||||||
|
#
|
||||||
|
# Copyright (C) 2007 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
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful, but
|
||||||
|
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
# General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||||
|
# USA.
|
||||||
|
#
|
||||||
|
# Version: $Id$
|
||||||
|
|
||||||
|
"""This is the module which takes your site-specific settings.
|
||||||
|
|
||||||
|
From a raw distribution it should be copied to gva_cfg.py. If you
|
||||||
|
already have a gva_cfg.py, be careful to add in only the new settings
|
||||||
|
you want. The complete set of distributed defaults, with annotation,
|
||||||
|
are in ./Defaults. In mm_cfg, override only those you want to change,
|
||||||
|
after the
|
||||||
|
|
||||||
|
from Defaults import *
|
||||||
|
|
||||||
|
line (see below)."""
|
||||||
|
|
||||||
|
###############################################################
|
||||||
|
# Here's where we get the distributed defaults. #
|
||||||
|
|
||||||
|
from Defaults import *
|
||||||
|
|
||||||
|
###############################################################
|
||||||
|
# Put YOUR site-specific configuration below, in gva_cfg.py . #
|
||||||
|
# See Defaults.py for explanations of the values. #
|
||||||
|
|
||||||
|
#--------------------------------------------------------------
|
||||||
|
# The database connection string in a format usable for
|
||||||
|
# sqlalchemy. For examples see
|
||||||
|
# http://www.sqlalchemy.org/docs/dbengine.myt
|
||||||
|
#
|
||||||
|
GVA_DBE = 'sqlite:///database.txt'
|
Loading…
Reference in a new issue