19
19
"""Refresh parts of the filesystem that are generated from the database.
21
In particular, the Subversion authorisation files are rewritten.
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
34
from ivle.config import Config
27
from ivle.database import get_store
35
from ivle.database import get_store, ProjectGroup, User
28
36
import ivle.makeuser
37
# Python 2.5's shutil.rmtree follows symlinks!
38
from ivle.util import safe_rmtree
40
junk_directory_suffix = (
41
'-removed-%s' % datetime.datetime.now().strftime('%Y%m%d-%H%M%S'))
43
def get_junk_dir(path):
44
return os.path.normpath(path) + junk_directory_suffix
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))
51
os.path.join(parent, name),
52
os.path.join(get_junk_dir(parent), name))
31
56
store = get_store(config)
58
active_users = store.find(User, state=u'enabled').order_by(User.login)
60
print >>sys.stderr, "Refreshing active user jails..."
61
for user in active_users:
62
ivle.makeuser.make_jail(user, config)
65
login for login in os.listdir(config['paths']['jails']['src'])
66
if not (login.startswith('__') and login.endswith('__')))
68
print >>sys.stderr, "Junking extra user jails..."
69
for jail in present_jails - set(user.login for user in active_users):
71
junk(config['paths']['jails']['src'], jail)
73
repo_root = config['paths']['svn']['repo_path']
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')))
79
for repo in set(user.login for user in active_users) - present_user_repos:
81
ivle.makeuser.make_svn_repo(
82
os.path.join(repo_root, 'users', repo), throw_on_error=True)
84
print >>sys.stderr, "Junking extra Subversion user repositories..."
85
for repo in present_user_repos - set(user.login for user in active_users):
87
junk(os.path.join(repo_root, 'users'), repo)
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')))
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))
100
for repo in active_group_identifiers - present_group_repos:
102
ivle.makeuser.make_svn_repo(
103
os.path.join(repo_root, 'groups', repo), throw_on_error=True)
105
print >>sys.stderr, "Junking extra Subversion user repositories..."
106
for repo in present_group_repos - active_group_identifiers:
108
junk(os.path.join(repo_root, 'groups'), repo)
33
111
print >>sys.stderr, "Rebuilding Subversion user configuration..."
34
112
ivle.makeuser.rebuild_svn_config(store, config)
35
113
print >>sys.stderr, "Rebuilding Subversion group configuration..."