From 7152902ff334cc28e18982aabf24e1b944f5b069 Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Sat, 5 Apr 2008 16:54:07 +0000 Subject: [PATCH] r1093@denkpolster: jan | 2008-04-05 18:54:02 +0200 correctly handle empty user lists in sysuser create * use prefix + 01 if list of users with prefix is empty (fixes #11) git-svn-id: file:///home/www/usr01/svn/gnuviechadmin/trunk@250 a67ec6bc-e5d5-0310-a910-815c51eb3124 --- gnuviechadmin/backend/sysuser.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/gnuviechadmin/backend/sysuser.py b/gnuviechadmin/backend/sysuser.py index 0b65529..ff58bcb 100644 --- a/gnuviechadmin/backend/sysuser.py +++ b/gnuviechadmin/backend/sysuser.py @@ -50,14 +50,18 @@ class SysuserEntity(BackendEntity): def _get_next_sysusername(self): prefix = config.get('sysuser', 'nameprefix') + self.logger.debug("looking for next user with prefix %s" % (prefix)) usernames = [user.username for user in \ getenttools.find_user_by_prefix(prefix)] - maxid = max([int(username[len(prefix):]) for username in usernames]) - maxid += 2 - for number in range(1, maxid): - username = "%s%02d" % (prefix, number) - if not username in usernames: - return username + if usernames: + maxid = max([int(username[len(prefix):]) for username in usernames]) + maxid += 2 + for number in range(1, maxid): + username = "%s%02d" % (prefix, number) + if not username in usernames: + return username + else: + return "%s%02d" % (prefix, 1) def _get_default_sysusertype(self): return 1