1
0
Fork 0
gnuviechadmin-historic/bin/createclient
Jan Dittberner 6b1c80899d - moved all database specific code to the module, cli is just a frontend
git-svn-id: file:///home/www/usr01/svn/gnuviechadmin/gnuviech.info/gnuviechadmin/trunk@219 a67ec6bc-e5d5-0310-a910-815c51eb3124
2007-02-11 20:09:07 +00:00

115 lines
4 KiB
Python
Executable file

#!/usr/bin/python
# -*- 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$
import getopt, sys
from gnuviechadmin import client, exceptions
def usage():
print """Usage: %s [-h|--help] [-v|--verbose]
[-t <title>|--title=<title>]
-f <firstname>|--firstname=<firstname> -l <lastname>|--lastname=<lastname>
-a <address1>|--address=<address1> [--address2=<address2>]
-z <zip>|--zip=<zip> -c <city>|--city=<city> [--country=<isocode>]
[-o <organisation>|--organisation=<organisation>]
-e <email>|--email=<email> -p <phone>|--phone=<phone>
[-m <mobile>|--mobile=<mobile>] [-x <fax>|--fax=<fax>]
General options:
-h, --help show this usage message and exit
-v, --verbose verbose operation
Mandatory client data options:
-f, --firstname firstname
-l, --lastname lastname
-a, --address street address
-z, --zip zip or postal code
-c, --city city or location
-e, --email contact email address
-p, --phone telephone number
Optional client data options:
--address2 optional second line of the street address
-o, --organisation option organisation
--country country (defaults to de)
-t, --title optional title
-m, --mobile optional mobile number
-x, --fax optional fax number
""" % (sys.argv[0])
def main():
try:
opts, args = getopt.gnu_getopt(sys.argv[1:],
"hvf:l:a:z:c:e:p:o:t:m:x:",
["help", "verbose", "firstname=",
"lastname=", "address=", "zip=",
"city=", "email=", "phone=",
"address2=", "organisation=",
"country=", "title=", "mobile=",
"fax="])
except getopt.GetoptError:
usage()
sys.exit(2)
clientdata = {}
verbose = False
for o, a in opts:
if o in ("-v", "--verbose"):
verbose = True
if o in ("-h", "--help"):
usage()
sys.exit()
if o in ("-f", "--firstname"):
clientdata["firstname"] = a
if o in ("-l", "--lastname"):
clientdata["lastname"] = a
if o in ("-a", "--address"):
clientdata["address1"] = a
if o in ("-z", "--zip"):
clientdata["zip"] = a
if o in ("-c", "--city"):
clientdata["city"] = a
if o == "--country":
clientdata["country"] = a
if o in ("-t", "--title"):
clientdata["title"] = a
if o in ("-m", "--mobile"):
clientdata["mobile"] = a
if o in ("-e", "--email"):
clientdata["email"] = a
if o in ("-o", "--organisation"):
clientdata["organisation"] = a
if o in ("-x", "--fax"):
clientdata["fax"] = a
if o in ("-p", "--phone"):
clientdata["phone"] = a
if verbose:
print "parsed client data is ", clientdata
try:
myclient = client.create(**clientdata)
except exceptions.CreationFailedError, cfe:
usage()
print cfe
sys.exit(2)
if verbose:
print myclient
if __name__ == "__main__":
main()