1
0
Fork 0
gnuviechadmin-historic/testdb/addsysuser.py

73 lines
2.3 KiB
Python

#!/usr/bin/env python
#
# 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 getopt
import sys
from gnuviechadmin.dblayer import *
def usage():
print """Usage information:
=====================
%(process)s -h|--help
- prints this help text
%(process)s --type=admin|reseller|client --clientid=<clientid> \
[--name=<name>] [--home=<home>] [--shell=<shell>] [--password] \
[--sysuid=<uid>]
- adds a new system user
""" % {'process': sys.argv[0]}
if __name__ == "__main__":
try:
(options, args) = getopt.getopt(sys.argv[1:], "h",
['help', 'type=', 'clientid=',
'name=', 'home=', 'shell=',
'password=', 'sysuid='])
except getopt.GetoptError:
usage()
sys.exit(1)
if (not options or
'-h' in dict(options) or
'--help' in dict(options) or
not '--type' in dict(options) or
not '--clientid' in dict(options) or
not dict(options)['--type'].strip() or
not dict(options)['--clientid'].strip() or
not dict(options)['--type'].strip() in ('admin', 'reseller',
'client')):
usage()
sys.exit(1)
query = session.query(Client)
client = query.get_by(clientid = dict(options)['--clientid'].strip())
if not client:
print "Invalid client"
allclients = query.select()
if allclients:
print "Valid clients are:\n- %s" % "\n- ".join(
[str(client) for client in allclients])
else:
print "No clients defined yet."
sys.exit(1)
print client.sysusers