2008-04-05 23:22:12 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2007-02-28 22:15:20 +01:00
|
|
|
#
|
2009-07-19 01:03:23 +02:00
|
|
|
# Copyright (C) 2007, 2008, 2009 by Jan Dittberner.
|
2007-02-28 22:15:20 +01: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$
|
2008-06-06 21:20:18 +02:00
|
|
|
import CliCommand
|
|
|
|
import sys
|
2007-02-28 22:15:20 +01:00
|
|
|
|
|
|
|
|
|
|
|
class ClientCli(CliCommand.CliCommand):
|
2007-07-05 11:00:34 +02:00
|
|
|
"""Command line interface command for client management."""
|
2007-02-28 22:15:20 +01:00
|
|
|
|
2009-08-01 15:33:34 +02:00
|
|
|
@staticmethod
|
|
|
|
def setup_argparser(subparsers):
|
|
|
|
parser = subparsers.add_parser(
|
|
|
|
'client',
|
|
|
|
help = _('manage clients'))
|
|
|
|
parser.set_defaults(commandclass=ClientCli)
|
|
|
|
cmdsub = parser.add_subparsers(
|
|
|
|
title = _('client subcommands'), dest = 'subcommand')
|
|
|
|
cmdparser = cmdsub.add_parser(
|
|
|
|
'create',
|
|
|
|
help = _('creates a new client'))
|
|
|
|
cmdparser.add_argument(
|
|
|
|
'-f', '--firstname', required = True,
|
|
|
|
help = _("the client's first name"))
|
|
|
|
cmdparser.add_argument(
|
|
|
|
'-l', '--lastname', required = True,
|
|
|
|
help = _("the client's last name"))
|
|
|
|
cmdparser.add_argument(
|
|
|
|
'-t', '--title',
|
|
|
|
help = _("the client's title"))
|
|
|
|
cmdparser.add_argument(
|
|
|
|
'-a', '--address', dest = 'address1', required = True,
|
|
|
|
help = _("the address of the client"))
|
|
|
|
cmdparser.add_argument(
|
|
|
|
'--address2',
|
|
|
|
help = _("second line of the client's address"))
|
|
|
|
cmdparser.add_argument(
|
|
|
|
'-z', '--zip', required = True,
|
|
|
|
help = _("the zipcode of the client's address"))
|
|
|
|
cmdparser.add_argument(
|
|
|
|
'-c', '--city', required = True,
|
|
|
|
help = _("the city of the client's address"))
|
|
|
|
cmdparser.add_argument(
|
|
|
|
'--country',
|
2009-08-01 21:35:43 +02:00
|
|
|
help = _("the client's country"))
|
2009-08-01 15:33:34 +02:00
|
|
|
cmdparser.add_argument(
|
|
|
|
'-e', '--email', required = True,
|
|
|
|
help = _("the client's email address"))
|
|
|
|
cmdparser.add_argument(
|
|
|
|
'-p', '--phone', required = True,
|
|
|
|
help = _("the client's phone number"))
|
|
|
|
cmdparser.add_argument(
|
|
|
|
'-m', '--mobile',
|
|
|
|
help = _("the client's mobile phone number"))
|
|
|
|
cmdparser.add_argument(
|
|
|
|
'-x', '--fax',
|
|
|
|
help = _("the client's fax number"))
|
|
|
|
cmdparser = cmdsub.add_parser(
|
|
|
|
'list',
|
|
|
|
help = _('lists existing clients'))
|
|
|
|
cmdparser = cmdsub.add_parser(
|
|
|
|
'delete',
|
|
|
|
help = _(
|
|
|
|
'deletes the specified client if it has no dependent data'))
|
|
|
|
cmdparser.add_argument(
|
|
|
|
'-c', '--clientid', required = True,
|
|
|
|
help = _("the client id"))
|
2008-06-06 21:20:18 +02:00
|
|
|
|
2009-08-01 15:33:34 +02:00
|
|
|
def _execute(self):
|
|
|
|
self.logger.debug("execute %s", self.args)
|
2009-07-19 01:03:23 +02:00
|
|
|
from gnuviechadmin.backend.client import ClientHandler
|
|
|
|
from gnuviechadmin.exceptions import CreationFailedError
|
2009-08-01 15:33:34 +02:00
|
|
|
ch = ClientHandler(self.config, self.args.verbose)
|
|
|
|
if self.args.subcommand == "create":
|
2007-07-02 11:14:47 +02:00
|
|
|
try:
|
2009-08-01 17:10:28 +02:00
|
|
|
myclient = ch.create(**self.args.__dict__)
|
2009-08-01 15:33:34 +02:00
|
|
|
if self.args.verbose:
|
2009-08-01 17:10:28 +02:00
|
|
|
print unicode(myclient).encode('utf8')
|
2009-07-19 01:03:23 +02:00
|
|
|
except CreationFailedError, cfe:
|
2007-07-02 11:14:47 +02:00
|
|
|
print cfe
|
|
|
|
sys.exit(2)
|
2009-08-01 15:33:34 +02:00
|
|
|
elif self.args.subcommand == "list":
|
|
|
|
clients = ch.fetchall()
|
2007-07-02 11:14:47 +02:00
|
|
|
for client in clients:
|
2009-08-01 17:10:28 +02:00
|
|
|
print unicode(client).encode('utf8')
|
2009-08-01 15:33:34 +02:00
|
|
|
elif self.args.subcommand == "delete":
|
|
|
|
ch.delete(self.args.clientid)
|
|
|
|
|
|
|
|
def __init__(self, args, config):
|
|
|
|
CliCommand.CliCommand.__init__(self, args, config)
|