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$
|
|
|
|
"""This is the gnuviechadmin.cli package.
|
|
|
|
|
|
|
|
This package provides modules for the command line interface of the
|
|
|
|
gnuviechadmin server administration suite."""
|
|
|
|
|
2007-07-05 11:00:34 +02:00
|
|
|
__all__ = ["client", "sysuser", "domain", "record"]
|
2009-07-19 01:03:23 +02:00
|
|
|
|
|
|
|
from logging import getLogger
|
|
|
|
from sys import exit
|
|
|
|
|
|
|
|
|
|
|
|
class CommandLineInterface(object):
|
|
|
|
|
|
|
|
def __init__(self, config, args):
|
|
|
|
self.log = getLogger(__name__)
|
|
|
|
self.config = config
|
|
|
|
if len(args) < 2:
|
|
|
|
self._usage(args[0])
|
|
|
|
exit(1)
|
|
|
|
self.commands = [command for command in self._get_commands() \
|
|
|
|
if command.name == args[1]]
|
|
|
|
self.cmdargs = args[2:]
|
|
|
|
|
|
|
|
|
|
|
|
def _usage(self, callee):
|
|
|
|
print """%s <command> [commandargs]
|
|
|
|
|
|
|
|
where command is one of
|
|
|
|
""" % callee
|
|
|
|
for command in self._get_commands():
|
|
|
|
print "%10s - %s" % (command.name, command.description)
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
for cmd in self.commands:
|
|
|
|
cmd(self.cmdargs, self.config)
|
|
|
|
|
|
|
|
def _get_commands(self):
|
|
|
|
from gnuviechadmin.cli.client import ClientCli
|
|
|
|
from gnuviechadmin.cli.sysuser import SysuserCli
|
|
|
|
from gnuviechadmin.cli.domain import DomainCli
|
|
|
|
from gnuviechadmin.cli.record import RecordCli
|
|
|
|
return [ClientCli, SysuserCli, DomainCli, RecordCli]
|