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

« back to all changes in this revision

Viewing changes to bin/ivle-refreshfilesystem

  • Committer: mattgiuca
  • Date: 2007-12-07 03:52:26 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:13
notes/misc.txt: Added notes from today's meeting. (Steven Bird)
notes/README: Explain that this is markdown.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
# IVLE - Informatics Virtual Learning Environment
3
 
# Copyright (C) 2007-2009 The University of Melbourne
4
 
#
5
 
# This program is free software; you can redistribute it and/or modify
6
 
# it under the terms of the GNU General Public License as published by
7
 
# the Free Software Foundation; either version 2 of the License, or
8
 
# (at your option) any later version.
9
 
#
10
 
# This program is distributed in the hope that it will be useful,
11
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
# GNU General Public License for more details.
14
 
#
15
 
# You should have received a copy of the GNU General Public License
16
 
# along with this program; if not, write to the Free Software
17
 
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 
 
19
 
"""Refresh parts of the filesystem that are generated from the database.
20
 
 
21
 
In particular:
22
 
 - missing user jails are created
23
 
 - missing user and group Subversion repositories are created
24
 
 - the Subversion password file is updated
25
 
 - the Subversion authorisation files are rewritten
26
 
"""
27
 
 
28
 
import datetime
29
 
import os
30
 
import os.path
31
 
import shutil
32
 
import sys
33
 
 
34
 
from ivle.config import Config
35
 
from ivle.database import get_store, ProjectGroup, User
36
 
import ivle.makeuser
37
 
# Python 2.5's shutil.rmtree follows symlinks!
38
 
from ivle.util import safe_rmtree
39
 
 
40
 
junk_directory_suffix = (
41
 
    '-removed-%s' % datetime.datetime.now().strftime('%Y%m%d-%H%M%S'))
42
 
 
43
 
def get_junk_dir(path):
44
 
    return os.path.normpath(path) + junk_directory_suffix
45
 
 
46
 
def junk(parent, name):
47
 
    """Move the named directory into a junk directory alongside the parent."""
48
 
    if not os.path.exists(get_junk_dir(parent)):
49
 
        os.makedirs(get_junk_dir(parent))
50
 
    shutil.move(
51
 
        os.path.join(parent, name),
52
 
        os.path.join(get_junk_dir(parent), name))
53
 
 
54
 
 
55
 
config = Config()
56
 
store = get_store(config)
57
 
 
58
 
active_users = store.find(User, state=u'enabled').order_by(User.login)
59
 
 
60
 
print >>sys.stderr, "Refreshing active user jails..."
61
 
for user in active_users:
62
 
    ivle.makeuser.make_jail(user, config)
63
 
 
64
 
present_jails = set(
65
 
    login for login in os.listdir(config['paths']['jails']['src'])
66
 
    if not (login.startswith('__') and login.endswith('__')))
67
 
 
68
 
print >>sys.stderr, "Junking extra user jails..."
69
 
for jail in present_jails - set(user.login for user in active_users):
70
 
    print ' - %s' % jail
71
 
    junk(config['paths']['jails']['src'], jail)
72
 
 
73
 
repo_root = config['paths']['svn']['repo_path']
74
 
 
75
 
print >>sys.stderr, "Creating missing Subversion user repositories..."
76
 
present_user_repos= set(
77
 
    login for login in os.listdir(os.path.join(repo_root, 'users')))
78
 
 
79
 
for repo in set(user.login for user in active_users) - present_user_repos:
80
 
    print ' - %s' % repo
81
 
    ivle.makeuser.make_svn_repo(
82
 
        os.path.join(repo_root, 'users', repo), throw_on_error=True)
83
 
 
84
 
print >>sys.stderr, "Junking extra Subversion user repositories..."
85
 
for repo in present_user_repos - set(user.login for user in active_users):
86
 
    print ' - %s' % repo
87
 
    junk(os.path.join(repo_root, 'users'), repo)
88
 
 
89
 
 
90
 
print >>sys.stderr, "Creating missing Subversion group repositories..."
91
 
present_group_repos = set(
92
 
    group for group in os.listdir(os.path.join(repo_root, 'groups')))
93
 
 
94
 
active_group_identifiers = set("_".join(
95
 
    [group.project_set.offering.subject.short_name,
96
 
     group.project_set.offering.semester.year,
97
 
     group.project_set.offering.semester.semester,
98
 
     group.name]) for group in store.find(ProjectGroup))
99
 
 
100
 
for repo in active_group_identifiers - present_group_repos:
101
 
    print ' - %s' % repo
102
 
    ivle.makeuser.make_svn_repo(
103
 
        os.path.join(repo_root, 'groups', repo), throw_on_error=True)
104
 
 
105
 
print >>sys.stderr, "Junking extra Subversion user repositories..."
106
 
for repo in present_group_repos - active_group_identifiers:
107
 
    print ' - %s' % repo
108
 
    junk(os.path.join(repo_root, 'groups'), repo)
109
 
 
110
 
 
111
 
print >>sys.stderr, "Rebuilding Subversion user configuration..."
112
 
ivle.makeuser.rebuild_svn_config(store, config)
113
 
print >>sys.stderr, "Rebuilding Subversion group configuration..."
114
 
ivle.makeuser.rebuild_svn_group_config(store, config)
115
 
 
116