106 lines
3.4 KiB
Python
106 lines
3.4 KiB
Python
|
#!/usr/bin/env python
|
||
|
# -*- coding: UTF-8 -*-
|
||
|
#
|
||
|
# This file is part of gnuviechadmin.
|
||
|
#
|
||
|
# Author: Jan Dittberner <jan@dittberner.info>
|
||
|
# Copyright (c) 2007 Jan Dittberner
|
||
|
# Version: $Id$
|
||
|
|
||
|
import getopt, sys
|
||
|
from sqlalchemy import *
|
||
|
|
||
|
from gnuviechadmin import client
|
||
|
|
||
|
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
|
||
|
myclient = client.Client(clientdata)
|
||
|
if not myclient:
|
||
|
usage()
|
||
|
sys.exit(2)
|
||
|
sess = create_session()
|
||
|
sess.save(myclient)
|
||
|
sess.flush()
|
||
|
if verbose:
|
||
|
print myclient
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
main()
|