2007-12-10 16:12:58 -05:00
|
|
|
# Authors: Rob Crittenden <rcritten@redhat.com>
|
|
|
|
|
#
|
|
|
|
|
# Copyright (C) 2007 Red Hat
|
|
|
|
|
# see file 'COPYING' for use and warranty information
|
|
|
|
|
#
|
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
|
# modify it under the terms of the GNU General Public License as
|
2008-02-04 15:15:52 -05:00
|
|
|
# published by the Free Software Foundation; version 2 only
|
2007-12-10 16:12:58 -05:00
|
|
|
#
|
|
|
|
|
# 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
import string
|
|
|
|
|
import tempfile
|
|
|
|
|
import logging
|
|
|
|
|
import subprocess
|
|
|
|
|
import os
|
2008-08-06 13:00:36 -04:00
|
|
|
import ipa.ipavalidate as ipavalidate
|
2007-12-10 16:12:58 -05:00
|
|
|
|
|
|
|
|
def select_user(counter, users):
|
2008-02-20 09:32:25 -05:00
|
|
|
"""counter is the number of User objects in users
|
|
|
|
|
users is a list of User objects
|
|
|
|
|
|
|
|
|
|
This purposely doesn't catch KeyboardInterrupt
|
|
|
|
|
"""
|
2007-12-10 16:12:58 -05:00
|
|
|
i = 1
|
|
|
|
|
print "%s entries were found. Which one would you like to display?" % counter
|
|
|
|
|
for ent in users:
|
2008-08-21 10:32:40 -04:00
|
|
|
if (ent.getValues('givenname')) is not None:
|
|
|
|
|
print "%s: %s %s (%s)" % (i, ent.getValues('givenname'), ent.getValues('sn'), ent.getValues('uid'))
|
|
|
|
|
else:
|
|
|
|
|
print "%s: %s (%s)" % (i, ent.getValues('sn'), ent.getValues('uid'))
|
2007-12-10 16:12:58 -05:00
|
|
|
i += 1
|
|
|
|
|
while True:
|
|
|
|
|
resp = raw_input("Choose one: (1 - %s), 0 for all, q to quit: " % counter)
|
|
|
|
|
if resp == "q":
|
|
|
|
|
return "q"
|
|
|
|
|
if resp == "0":
|
|
|
|
|
userindex = -1
|
2008-02-20 09:32:25 -05:00
|
|
|
break
|
2007-12-10 16:12:58 -05:00
|
|
|
try:
|
|
|
|
|
userindex = int(resp) - 1
|
2008-02-20 09:32:25 -05:00
|
|
|
if (userindex >= 0 and userindex < counter):
|
|
|
|
|
break
|
2007-12-10 16:12:58 -05:00
|
|
|
except:
|
|
|
|
|
# fall through to the error msg
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
print "Please enter a number between 1 and %s" % counter
|
|
|
|
|
|
|
|
|
|
return userindex
|
|
|
|
|
|
|
|
|
|
def select_group(counter, groups):
|
2008-02-20 09:32:25 -05:00
|
|
|
"""counter is the number of Group objects in users
|
|
|
|
|
users is a list of Group objects
|
|
|
|
|
|
|
|
|
|
This purposely doesn't catch KeyboardInterrupt
|
|
|
|
|
"""
|
2007-12-10 16:12:58 -05:00
|
|
|
i = 1
|
|
|
|
|
print "%s entries were found. Which one would you like to display?" % counter
|
|
|
|
|
for ent in groups:
|
|
|
|
|
print "%s: %s" % (i, ent.getValues('cn'))
|
|
|
|
|
i += 1
|
|
|
|
|
while True:
|
|
|
|
|
resp = raw_input("Choose one: (1 - %s), 0 for all, q to quit: " % counter)
|
|
|
|
|
if resp == "q":
|
|
|
|
|
return "q"
|
|
|
|
|
if resp == "0":
|
|
|
|
|
groupindex = -1
|
2008-02-20 09:32:25 -05:00
|
|
|
break
|
2007-12-10 16:12:58 -05:00
|
|
|
try:
|
|
|
|
|
groupindex = int(resp) - 1
|
2008-02-20 09:32:25 -05:00
|
|
|
if (groupindex >= 0 and groupindex < counter):
|
|
|
|
|
break
|
2007-12-10 16:12:58 -05:00
|
|
|
except:
|
|
|
|
|
# fall through to the error msg
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
print "Please enter a number between 1 and %s" % counter
|
|
|
|
|
|
|
|
|
|
return groupindex
|
2008-08-06 13:00:36 -04:00
|
|
|
|
|
|
|
|
def check_name(name):
|
|
|
|
|
"""Helper to ensure that a user or group name is legal"""
|
|
|
|
|
|
|
|
|
|
if (not ipavalidate.GoodName(name, notEmpty=True)):
|
|
|
|
|
raise ValueError("may only include letters, numbers, _, -, . and $")
|
|
|
|
|
|
|
|
|
|
return
|