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

« back to all changes in this revision

Viewing changes to bin/ivle-refreshfilesystem

  • Committer: William Grant
  • Date: 2009-12-08 02:02:12 UTC
  • mto: This revision was merged to the branch mainline in revision 1346.
  • Revision ID: grantw@unimelb.edu.au-20091208020212-g0arh0ztnubtmm0b
Move junked directories elsewhere -- don't delete them.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 - the Subversion authorisation files are rewritten
26
26
"""
27
27
 
 
28
import datetime
28
29
import os
 
30
import os.path
 
31
import shutil
29
32
import sys
30
33
 
31
34
from ivle.config import Config
34
37
# Python 2.5's shutil.rmtree follows symlinks!
35
38
from ivle.util import safe_rmtree
36
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
    os.makedirs(get_junk_dir(parent))
 
49
    shutil.move(
 
50
        os.path.join(parent, name),
 
51
        os.path.join(get_junk_dir(parent), name))
 
52
 
 
53
 
37
54
config = Config()
38
55
store = get_store(config)
39
56
 
43
60
for user in active_users:
44
61
    ivle.makeuser.make_jail(user, config)
45
62
 
46
 
print >>sys.stderr, "Purging extra user jails..."
47
63
present_jails = set(
48
64
    login for login in os.listdir(config['paths']['jails']['src'])
49
65
    if not (login.startswith('__') and login.endswith('__')))
50
66
 
 
67
print >>sys.stderr, "Junking extra user jails..."
51
68
for jail in present_jails - set(user.login for user in active_users):
52
69
    print ' - %s' % jail
53
 
    safe_rmtree(os.path.join(config['paths']['jails']['src'], jail))
 
70
    junk(config['paths']['jails']['src'], jail)
54
71
 
55
72
repo_root = config['paths']['svn']['repo_path']
56
73
 
57
 
print >>sys.stderr, "Creating missing Subversion user respositories..."
 
74
print >>sys.stderr, "Creating missing Subversion user repositories..."
58
75
present_user_repos= set(
59
76
    login for login in os.listdir(os.path.join(repo_root, 'users')))
60
77
 
63
80
    ivle.makeuser.make_svn_repo(
64
81
        os.path.join(repo_root, 'users', repo), throw_on_error=True)
65
82
 
66
 
print >>sys.stderr, "Purging extra Subversion user respositories..."
 
83
print >>sys.stderr, "Junking extra Subversion user repositories..."
67
84
for repo in present_user_repos - set(user.login for user in active_users):
68
85
    print ' - %s' % repo
69
 
    safe_rmtree(os.path.join(repo_root, 'users', repo))
70
 
 
71
 
 
72
 
print >>sys.stderr, "Creating missing Subversion group respositories..."
 
86
    junk(os.path.join(repo_root, 'users'), repo)
 
87
 
 
88
 
 
89
print >>sys.stderr, "Creating missing Subversion group repositories..."
73
90
present_group_repos = set(
74
91
    group for group in os.listdir(os.path.join(repo_root, 'groups')))
75
92
 
84
101
    ivle.makeuser.make_svn_repo(
85
102
        os.path.join(repo_root, 'groups', repo), throw_on_error=True)
86
103
 
87
 
print >>sys.stderr, "Purging extra Subversion user respositories..."
 
104
print >>sys.stderr, "Junking extra Subversion user repositories..."
88
105
for repo in present_group_repos - active_group_identifiers:
89
106
    print ' - %s' % repo
90
 
    safe_rmtree(os.path.join(repo_root, 'groups', repo))
 
107
    junk(os.path.join(repo_root, 'groups'), repo)
91
108
 
92
109
 
93
110
print >>sys.stderr, "Rebuilding Subversion user configuration..."