1
0
Fork 0
gnuviechadmin-historic/gnuviechadmin/cli/client.py
Jan Dittberner 09180938f1 Code style changes
* make code PEP8 clean (addresses #18)
 * add copyright information to all python files


git-svn-id: file:///home/www/usr01/svn/gnuviechadmin/trunk@257 a67ec6bc-e5d5-0310-a910-815c51eb3124
2008-06-06 19:20:18 +00:00

84 lines
3.5 KiB
Python

# -*- coding: utf-8 -*-
#
# Copyright (C) 2007, 2008 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
import sys
class ClientCli(CliCommand.CliCommand):
"""Command line interface command for client management."""
name = "client"
description = "manage clients"
_optionmap = {
'create': ("creates a new client",
[(["-f", "--firstname"], "firstname",
"the client's first name", True),
(["-l", "--lastname"], "lastname",
"the client's last name", True),
(["-t", "--title"], "title",
"the client's title", False),
(["-a", "--address"], "address1",
"the address of the client", True),
(["--address2"], "address2",
"second line of the client's address", False),
(["-z", "--zip"], "zip",
"the zipcode of the client's address", True),
(["-c", "--city"], "city",
"the city of the client's address", True),
(["--country"], "country",
"the client's country", False),
(["-e", "--email"], "email",
"the client's email address", True),
(["-p", "--phone"], "phone",
"the client's phone number", True),
(["-m", "--mobile"], "mobile",
"the client's mobile phone number", False),
(["-x", "--fax"], "fax",
"the client's fax number", False)]),
'list': ("lists existing clients", []),
'delete': ("deletes the specified client if it has no dependent data",
[(["-c", "--clientid"], "clientid",
"the client id", True)])}
def _execute(self, subcommand):
self.logger.debug("execute %s with data %s", subcommand,
str(self._data))
from gnuviechadmin.backend import client
from gnuviechadmin import exceptions
if subcommand == "create":
try:
myclient = client.ClientHandler(self._verbose).create(
**self._data)
if self._verbose:
print myclient
except exceptions.CreationFailedError, cfe:
self._usage()
print cfe
sys.exit(2)
elif subcommand == "list":
clients = client.ClientHandler(self._verbose).fetchall()
for client in clients:
print client
elif subcommand == "delete":
client.ClientHandler(self._verbose).delete(self._data["clientid"])
def __init__(self, argv):
CliCommand.CliCommand.__init__(self, argv)