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

« back to all changes in this revision

Viewing changes to remakeallusers.py

  • Committer: dcoles
  • Date: 2008-07-02 04:11:34 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:799
Setup: Added 3rd party (wgrant) packages for NLTK and matplotlib without TeX 
dependency. Also fixed typos.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
import common.makeuser
33
33
import optparse
34
34
import shutil
35
 
import logging
 
35
# Import modules from the website is tricky since they're in the www
 
36
# directory.
 
37
sys.path.append(os.path.join(os.getcwd(), 'www'))
36
38
 
37
39
p = optparse.OptionParser()
38
40
p.add_option('--incremental', '-i', action='store_true')
39
 
p.add_option('--verbose', '-v', action='store_true')
40
41
options, arguments = p.parse_args()
41
42
 
42
 
if options.verbose:
43
 
    logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s',
44
 
                        level=logging.DEBUG)
45
 
 
46
43
if os.getuid() != 0:
47
 
    print >> sys.stderr, "%s must be run as root" % sys.argv[0]
48
 
    sys.exit(1)
 
44
    print "Must run remakeallusers.py as root."
 
45
    sys.exit()
49
46
 
50
47
try:
51
48
    db = common.db.DB()
54
51
    def repack(flds):
55
52
        return (flds['login'], flds['unixid'])
56
53
    uids = dict(map(repack,res))
 
54
 
57
55
except Exception, message:
58
 
    logging.error(str(message))
 
56
    print "Error: " + str(message)
59
57
    sys.exit(1)
60
58
 
61
 
logging.info("rebuild started")
 
59
# First check that our __templateuser__ directory exits, if not create it
 
60
templateuserdir = os.path.join(conf.jail_base, '__templateuser__')
 
61
stagingdir = templatedir = os.path.join(conf.jail_base, '__staging__')
 
62
if not os.path.isdir(templateuserdir):
 
63
    os.mkdir(templateuserdir)
 
64
 
 
65
# Generate manifest of files that differ between template user and staging
 
66
if options.incremental:
 
67
    print "Incremental Rebuild selected"
 
68
    manifest = common.makeuser.generate_manifest(stagingdir, templateuserdir)
 
69
    print "Generated change manifest"
 
70
    print "Adding/Updating: %s\nRemoving: %s" % manifest
 
71
else:
 
72
    # Force a full rebuild
 
73
    manifest = None
62
74
 
63
75
list.sort(key=lambda user: user.login)
64
76
for user in list:
66
78
 
67
79
    try:
68
80
        # Resolve the user's login into a UID
 
81
        # Create the user if it does not exist
69
82
        try:
70
83
            uid = uids[login]
71
84
        except KeyError:
72
 
            raise Exception("user %s does not have a unixid in the database"
 
85
            raise Exception("User %s does not have a unixid in the database"
73
86
                % login)
74
87
        # Remake the user's jail
75
 
        common.makeuser.make_jail(login, uid)
 
88
        common.makeuser.make_jail(login, uid, manifest=manifest)
76
89
    except Exception, message:
77
 
        logging.warning(str(message))
 
90
        print "Error: " + str(message)
78
91
        continue
79
92
 
80
 
    logging.debug("recreated user %s's jail." % login)
 
93
    print "Successfully recreated user %s's jail." % login
81
94
    
82
 
logging.info("rebuild completed successfully")
 
95
# Update the template user directory
 
96
print "Updating templateuser directory"
 
97
shutil.rmtree(templateuserdir)
 
98
#common.makeuser.linktree(stagingdir, templateuserdir)
 
99
common.makeuser.make_jail('__templateuser__', 0, manifest=manifest)
 
100
shutil.rmtree(os.path.join(templateuserdir, 'home'))
 
101
 
 
102
print "Done!"