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

« back to all changes in this revision

Viewing changes to remakeallusers.py

  • Committer: William Grant
  • Date: 2008-07-02 05:11:10 UTC
  • Revision ID: wgrant@ivle-dev-20080702051110-dgd9p3vgnzslnl3z
remakeallusers.py: Clean up, removing obsolete bits, and using Python's
    logging module. This allows us to be quiet by default (pass -v to
    see what's happening), and gives nice timestamps (the main reason).

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