1
0
Fork 0
gnuviechadmin-historic/gnuviechadmin/cli/client.py

111 lines
3.8 KiB
Python
Raw Normal View History

# -*- 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 CliCommand, sys
from gnuviechadmin import client
class ClientCli(CliCommand.CliCommand):
"""Command line interface command for client creation."""
def shortopts(self):
return "f:l:a:z:c:e:p:o:t:m:x:"
def longopts(self):
return ["firstname=", "lastname=", "address=", "zip=",
"city=", "email=", "phone=", "address2=", "organisation=",
"country=", "title=", "mobile=", "fax="]
def usage(self):
print """Usage: %s client [-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 handleoption(self, o, a):
if o in ("-f", "--firstname"):
self.data["firstname"] = a
elif o in ("-l", "--lastname"):
self.data["lastname"] = a
elif o in ("-a", "--address"):
self.data["address1"] = a
elif o in ("-z", "--zip"):
self.data["zip"] = a
elif o in ("-c", "--city"):
self.data["city"] = a
elif o == "--country":
self.data["country"] = a
elif o in ("-t", "--title"):
self.data["title"] = a
elif o in ("-m", "--mobile"):
self.data["mobile"] = a
elif o in ("-e", "--email"):
self.data["email"] = a
elif o in ("-o", "--organisation"):
self.data["organisation"] = a
elif o in ("-x", "--fax"):
self.data["fax"] = a
elif o in ("-p", "--phone"):
self.data["phone"] = a
def checkrequired(self):
required = ['firstname', 'lastname', 'address1', 'zip', 'city',
'phone', 'email']
if self.verbose:
print self.data
for req in required:
if not req in self.data:
return False
return True
def execute(self):
myclient = client.create(**self.data)
if self.verbose:
print myclient
def __init__(self, argv):
self.data = {}
CliCommand.CliCommand.__init__(self, argv)