2008-01-12 23:24:08 +01:00
|
|
|
#!/usr/bin/env python
|
2008-06-06 21:20:18 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2008-01-12 23:24:08 +01:00
|
|
|
#
|
2008-06-06 21:20:18 +02:00
|
|
|
# Copyright (C) 2007, 2008 by Jan Dittberner.
|
2008-01-12 23:24:08 +01:00
|
|
|
#
|
2008-06-06 21:20:18 +02:00
|
|
|
# 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$
|
|
|
|
import getopt
|
|
|
|
import sys
|
2008-01-12 23:24:08 +01:00
|
|
|
from gnuviechadmin.dblayer import *
|
|
|
|
|
2008-06-06 21:20:18 +02:00
|
|
|
|
2008-01-12 23:24:08 +01:00
|
|
|
def usage():
|
2008-06-06 21:20:18 +02:00
|
|
|
print """Usage information:
|
|
|
|
=====================
|
|
|
|
%(process)s -h|--help
|
|
|
|
- prints this help text
|
2008-01-12 23:24:08 +01:00
|
|
|
|
2008-06-06 21:20:18 +02:00
|
|
|
%(process)s --firstname=<firstname> --lastname=<lastname> \
|
|
|
|
--address1=<address1> --town=<town> --zipcode=<zipcode> \
|
|
|
|
[--address2=<address2>] [--country=<country>] [--state=<state>] \
|
|
|
|
[--active=true|false] [--phone=<phone>] [--mobile=<mobile>]
|
|
|
|
- adds a new client
|
|
|
|
""" % {'process': sys.argv[0]}
|
2008-01-12 23:24:08 +01:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2008-06-06 21:20:18 +02:00
|
|
|
try:
|
|
|
|
(options, args) = getopt.getopt(sys.argv[1:], "h",
|
|
|
|
['help',
|
|
|
|
'firstname=', 'lastname=',
|
|
|
|
'address1=',
|
|
|
|
'town=', 'zipcode=', 'address2=',
|
|
|
|
'country=', 'state=', 'active=',
|
|
|
|
'phone=', 'mobile='])
|
|
|
|
except getopt.GetoptError:
|
|
|
|
usage()
|
|
|
|
sys.exit(1)
|
2008-01-12 23:24:08 +01:00
|
|
|
|
2008-06-06 21:20:18 +02:00
|
|
|
if (not options or
|
|
|
|
'-h' in dict(options) or
|
|
|
|
'--help' in dict(options) or
|
|
|
|
not '--firstname' in dict(options) or
|
|
|
|
not '--lastname' in dict(options) or
|
|
|
|
not '--address1' in dict(options) or
|
|
|
|
not '--town' in dict(options) or
|
|
|
|
not '--zipcode' in dict(options) or
|
|
|
|
not dict(options)['--firstname'].strip() or
|
|
|
|
not dict(options)['--lastname'].strip() or
|
|
|
|
not dict(options)['--address1'].strip() or
|
|
|
|
not dict(options)['--town'].strip() or
|
|
|
|
not dict(options)['--zipcode'].strip()):
|
|
|
|
usage()
|
|
|
|
sys.exit(1)
|
2008-01-12 23:24:08 +01:00
|
|
|
|
2008-06-06 21:20:18 +02:00
|
|
|
po = dict(options)
|
|
|
|
for key in po.keys():
|
|
|
|
po[key] = po[key].strip()
|
|
|
|
client = Client()
|
|
|
|
client.firstname = po['--firstname']
|
|
|
|
client.lastname = po['--lastname']
|
|
|
|
client.address1 = po['--address1']
|
|
|
|
client.town = po['--town']
|
|
|
|
client.zipcode = po['--zipcode']
|
|
|
|
if '--active' in po:
|
|
|
|
client.active = (po['--active'] == 'true')
|
|
|
|
else:
|
|
|
|
client.active = True
|
|
|
|
if '--address2' in po and po['--address2']:
|
|
|
|
client.address2 = po['--address2']
|
|
|
|
if '--country' in po and po['--country']:
|
|
|
|
client.country = po['--country']
|
|
|
|
if '--state' in po and po['--state']:
|
|
|
|
client.state = po['--state']
|
|
|
|
if '--phone' in po and po['--phone']:
|
|
|
|
client.phone = po['--phone']
|
|
|
|
if '--mobile' in po and po['--mobile']:
|
|
|
|
client.mobile = po['--mobile']
|
|
|
|
session.save(client)
|
|
|
|
session.flush()
|