* enable sysuser command * argument parsing via argparse * mark strings as translatable * pass parsed configuration where appropriate
This commit is contained in:
		
							parent
							
								
									0ac89c5f7b
								
							
						
					
					
						commit
						1435a88a5a
					
				
					 4 changed files with 62 additions and 47 deletions
				
			
		|  | @ -19,20 +19,19 @@ | |||
| # | ||||
| # Version: $Id$ | ||||
| 
 | ||||
| from gnuviechadmin.exceptions import * | ||||
| from gnuviechadmin.exceptions import CannotDeleteError | ||||
| from gnuviechadmin.util import passwordutils, getenttools | ||||
| from settings import config | ||||
| from BackendTo import * | ||||
| from BackendEntity import * | ||||
| from BackendEntityHandler import * | ||||
| from gnuviechadmin.backend.BackendTo import Sysuser | ||||
| from gnuviechadmin.backend.BackendEntity import BackendEntity | ||||
| from gnuviechadmin.backend.BackendEntityHandler import BackendEntityHandler | ||||
| import os | ||||
| 
 | ||||
| 
 | ||||
| class SysuserEntity(BackendEntity): | ||||
|     """Entity class for system users.""" | ||||
| 
 | ||||
|     def __init__(self, delegate, verbose = False, **kwargs): | ||||
|         BackendEntity.__init__(self, delegate, verbose) | ||||
|     def __init__(self, config, delegate, verbose = False, **kwargs): | ||||
|         BackendEntity.__init__(self, config, delegate, verbose) | ||||
|         for (key, value) in kwargs.items(): | ||||
|             self.__setattr__(key, value) | ||||
|         if not self.delegateto.username: | ||||
|  | @ -160,5 +159,6 @@ class SysuserEntity(BackendEntity): | |||
| class SysuserHandler(BackendEntityHandler): | ||||
|     """BackendEntityHandler for Sysuser entities.""" | ||||
| 
 | ||||
|     def __init__(self, verbose = False): | ||||
|         BackendEntityHandler.__init__(self, SysuserEntity, Sysuser, verbose) | ||||
|     def __init__(self, config, verbose = False): | ||||
|         BackendEntityHandler.__init__(self, SysuserEntity, Sysuser, | ||||
|                                       config, verbose) | ||||
|  |  | |||
|  | @ -47,7 +47,7 @@ class CommandLineInterface(object): | |||
|         from gnuviechadmin.cli.sysuser import SysuserCli | ||||
|         from gnuviechadmin.cli.domain import DomainCli | ||||
|         from gnuviechadmin.cli.record import RecordCli | ||||
|         for command in [ClientCli]: | ||||
|         for command in [ClientCli, SysuserCli]: | ||||
|             command.setup_argparser(subparsers) | ||||
|         self.parsedargs = parser.parse_args(args[1:]) | ||||
|          | ||||
|  |  | |||
|  | @ -59,7 +59,7 @@ class ClientCli(CliCommand.CliCommand): | |||
|             help = _("the city of the client's address")) | ||||
|         cmdparser.add_argument( | ||||
|             '--country', | ||||
|             help = _("the client's country"), default='de') | ||||
|             help = _("the client's country")) | ||||
|         cmdparser.add_argument( | ||||
|             '-e', '--email', required = True, | ||||
|             help = _("the client's email address")) | ||||
|  | @ -105,4 +105,3 @@ class ClientCli(CliCommand.CliCommand): | |||
| 
 | ||||
|     def __init__(self, args, config): | ||||
|         CliCommand.CliCommand.__init__(self, args, config) | ||||
| 
 | ||||
|  |  | |||
|  | @ -30,54 +30,70 @@ class SysuserCli(CliCommand): | |||
|     This class implements `gnuviechadmin.cli.CliCommand.CliCommand`. | ||||
|     """ | ||||
| 
 | ||||
|     name = "sysuser" | ||||
|     description = "manage system users" | ||||
|     _optionmap = { | ||||
|         "create": ("create a new system user with the given options.", | ||||
|                    [(["-n", "--username"], "username", | ||||
|                      "the system user name", False), | ||||
|                     (["-t", "--usertype"], "usertype", | ||||
|                      "the numeric user type", False), | ||||
|                     (["-h", "--home"], "home", | ||||
|                      "the home directory", False), | ||||
|                     (["-s", "--shell"], "shell", | ||||
|                      "true if the user should get shell access", False), | ||||
|                     (["-p", "--password"], "clearpass", | ||||
|                      "the password for the user", False), | ||||
|                     (["-c", "--clientid"], "clientid", | ||||
|                      "the client id", True)]), | ||||
|         "list": ("list existing system users.", []), | ||||
|         "delete": ("delete a system user.", | ||||
|                    [(["-s", "--sysuserid"], "sysuserid", | ||||
|                      "the system user id", True)])} | ||||
|     @staticmethod | ||||
|     def setup_argparser(subparsers): | ||||
|         parser = subparsers.add_parser( | ||||
|             'sysuser', | ||||
|             help = _('manage system users')) | ||||
|         parser.set_defaults(commandclass=SysuserCli) | ||||
|         cmdsub = parser.add_subparsers( | ||||
|             title = _('sysuser subcommands'), | ||||
|             dest = 'subcommand') | ||||
|         cmdparser = cmdsub.add_parser( | ||||
|             'create', | ||||
|             help = _('create a new system user with the given options.')) | ||||
|         cmdparser.add_argument( | ||||
|             '-n', '--username', | ||||
|             help = _('the system user name')) | ||||
|         cmdparser.add_argument( | ||||
|             '-t', '--usertype', | ||||
|             help = _('the numeric user type')) | ||||
|         cmdparser.add_argument( | ||||
|             '--home', | ||||
|             help = _('the home directory')) | ||||
|         cmdparser.add_argument( | ||||
|             '-s', '--shell', | ||||
|             help = _('true if the user should get shell access')) | ||||
|         cmdparser.add_argument( | ||||
|             '-p', '--password', dest = 'clearpass', | ||||
|             help = _('the password for the user')) | ||||
|         cmdparser.add_argument( | ||||
|             '-c', '--clientid', required = True, | ||||
|             help = _('the client id')) | ||||
|         cmdparser = cmdsub.add_parser( | ||||
|             'list', | ||||
|             help = _('list existing system users.')) | ||||
|         cmdparser = cmdsub.add_parser( | ||||
|             'delete', | ||||
|             help = _('delete a system user.')) | ||||
|         cmdparser.add_argument( | ||||
|             '-s', '--sysuserid', required = True, | ||||
|             help = _('the system user id')) | ||||
| 
 | ||||
|     def _execute(self, subcommand): | ||||
|     def _execute(self): | ||||
|         """Executes `subcommand`. | ||||
| 
 | ||||
|         This method implements `CliCommand._execute()`. | ||||
|         """ | ||||
|         self.logger.debug("execute %s with data %s", subcommand, | ||||
|                           str(self._data)) | ||||
|         self.logger.debug("execute %s", self.args) | ||||
|         from gnuviechadmin.backend import sysuser | ||||
|         from gnuviechadmin import exceptions | ||||
|         if subcommand == "create": | ||||
|         sh = sysuser.SysuserHandler(self.config, self.args.verbose) | ||||
|         if self.args.subcommand == "create": | ||||
|             try: | ||||
|                 mysysuser = sysuser.SysuserHandler(self._verbose).create( | ||||
|                     **self._data) | ||||
|                 if self._verbose: | ||||
|                 mysysuser = sh.create(**self.args.__dict__) | ||||
|                 if self.args.verbose: | ||||
|                     print mysysuser | ||||
|             except exceptions.CreationFailedError, cfe: | ||||
|                 self._usage() | ||||
|                 print cfe | ||||
|                 sys.exit(2) | ||||
|         elif subcommand == "list": | ||||
|             sysusers = sysuser.SysuserHandler(self._verbose).fetchall() | ||||
|         elif self.args.subcommand == "list": | ||||
|             sysusers = sh.fetchall() | ||||
|             for su in sysusers: | ||||
|                 print su | ||||
|         elif subcommand == "delete": | ||||
|             sysuser.SysuserHandler(self._verbose).delete( | ||||
|                 self._data["sysuserid"]) | ||||
|         elif self.args.subcommand == "delete": | ||||
|             sh.delete(self.args.sysuserid) | ||||
| 
 | ||||
|     def __init__(self, argv): | ||||
|     def __init__(self, args, config): | ||||
|         """Constructor for the sysuser command.""" | ||||
|         CliCommand.CliCommand.__init__(self, argv) | ||||
|         CliCommand.__init__(self, args, config) | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue