~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to bin/ivle-remakeuser

  • Committer: me at id
  • Date: 2009-01-15 01:29:07 UTC
  • mto: This revision was merged to the branch mainline in revision 1090.
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:branches%2Fstorm:1147
ivle.makeuser: Don't create a local.auth. It wasn't used anywhere, and seems
    to have only been there for historical reasons.
setup.configure: Remove svn_auth_local from the config.py boilerplate; it was
    used solely by ivle.makeuser.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
import optparse
30
30
import logging
31
31
 
32
 
import ivle.database
 
32
import ivle.db
33
33
import ivle.makeuser
34
34
 
35
35
p = optparse.OptionParser()
48
48
                          os.path.basename(sys.argv[0])
49
49
    sys.exit(1)
50
50
 
51
 
store = ivle.database.get_store()
52
 
 
53
 
if options.all:
54
 
    users = store.find(ivle.database.User).order_by(ivle.database.User.login)
55
 
else:
56
 
    if len(arguments) == 0:
57
 
        print >> sys.stderr, "must be run with -a or a username"
58
 
        sys.exit(1)
59
 
    users = [ivle.database.User.get_by_login(store, arguments[0])]
 
51
try:
 
52
    db = ivle.db.DB()
 
53
    if options.all:
 
54
        list = db.get_users()
 
55
    else:
 
56
        if len(arguments) == 0:
 
57
            print >> sys.stderr, "must be run with -a or a username"
 
58
            sys.exit(1)
 
59
        list = [db.get_user(arguments[0])]
 
60
    res = db.get_all('login', ['login', 'unixid'])
 
61
    def repack(flds):
 
62
        return (flds['login'], flds['unixid'])
 
63
    uids = dict(map(repack,res))
 
64
except Exception, message:
 
65
    logging.error(str(message))
 
66
    sys.exit(1)
60
67
 
61
68
logging.info("rebuild started")
62
69
 
63
 
for user in users:
 
70
list.sort(key=lambda user: user.login)
 
71
for user in list:
 
72
    login = user.login
 
73
 
64
74
    try:
65
 
        ivle.makeuser.make_jail(user)
 
75
        # Resolve the user's login into a UID
 
76
        try:
 
77
            uid = uids[login]
 
78
        except KeyError:
 
79
            raise Exception("user %s does not have a unixid in the database"
 
80
                % login)
 
81
        # Remake the user's jail
 
82
        ivle.makeuser.make_jail(login, uid)
66
83
    except Exception, message:
67
84
        logging.warning(str(message))
68
85
        continue
69
86
 
70
 
    logging.debug("recreated user %s's jail." % user.login)
 
87
    logging.debug("recreated user %s's jail." % login)
71
88
    
72
89
logging.info("rebuild completed successfully")