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