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

« back to all changes in this revision

Viewing changes to bin/ivle-loadsampledata

  • Committer: William Grant
  • Date: 2009-12-14 04:09:57 UTC
  • Revision ID: me@williamgrant.id.au-20091214040957-lpj8koijlkgs616n
So like Python, yet so unlike it, configobj's list syntax is Different®.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 
24
24
import sys
25
25
import os
26
 
import shutil
27
26
import optparse
28
27
import subprocess
29
28
import logging
30
29
import readline
31
 
import warnings
32
30
 
33
31
import psycopg2
34
32
 
35
33
from ivle.config import Config
36
 
import ivle.svn
37
34
 
38
35
logging.basicConfig(
39
36
    format='%(asctime)s %(levelname)s %(message)s',
44
41
    Return None if the program had a 0 return code.
45
42
    Return the string stderr if the program failed.
46
43
    """
47
 
    kwargs['stderr'] = subprocess.PIPE
48
 
 
49
 
    proc = subprocess.Popen(*popenargs, **kwargs)
 
44
    proc = subprocess.Popen(*popenargs, stderr=subprocess.PIPE, **kwargs)
50
45
    _, stderr = proc.communicate()
51
46
    if proc.returncode == 0:
52
47
        return None
105
100
 
106
101
        # Unmount all the jails
107
102
        logging.info("Unmounting all users.")
108
 
        subprocess.check_call(["ivle-mountallusers", "-u"])
 
103
        subprocess.check_call(["bin/ivle-mountallusers", "-u"])
109
104
 
110
105
        # Drop database
111
106
        logging.info("Dropping database \"%s\"." % dbconfig["name"])
138
133
 
139
134
# Build or rebuild all of the users' filesystems and subversion repos
140
135
logging.info("Creating data directories.")
141
 
subprocess.check_call(["ivle-createdatadirs"])
 
136
subprocess.check_call(["bin/ivle-createdatadirs"])
142
137
 
143
138
# Move all of the users' filesystems and subversion repos out of the way
144
139
# (This will clean out the user dirs because there are no users in the DB.)
145
140
logging.info("Moving existing user filesystems and repos out of the way.")
146
 
subprocess.check_call(["ivle-refreshfilesystem"])
 
141
subprocess.check_call(["bin/ivle-refreshfilesystem"])
147
142
 
148
143
# Populate with sample data
149
144
logging.info("Populating database with sample data.")
158
153
# Build all of the users' filesystems and subversion repos
159
154
# (This will create fresh user dirs and repos because the jails were empty.)
160
155
logging.info("Building sample users' filesystems and repos.")
161
 
subprocess.check_call(["ivle-refreshfilesystem"])
162
 
 
163
 
config = Config()
164
 
dbconfig = config['database']
165
 
 
166
 
# Populate some of the users' Subversion repos
167
 
def temp_checkout(svnclient, username):
168
 
    """Checkout user `username`'s repo to a temporary directory.
169
 
    @return: The temporary workspace directory.
170
 
    """
171
 
    # Do the checkout over HTTP, since we then use the user's own credentials
172
 
    repourl = config['urls']['svn_addr'] + '/users/' + username
173
 
    # Ignore warnings about the use of tempnam
174
 
    warnings.simplefilter('ignore')
175
 
    tempdir = os.tempnam()
176
 
    warnings.resetwarnings()
177
 
    svnclient.checkout(repourl, tempdir)
178
 
    return tempdir
179
 
 
180
 
logging.info("Populating student repositories")
181
 
def svnload(dumpfile, repo):
182
 
    """Run svnadmin load.
183
 
    @param dumpfile: Dump file to load from, relative to examples/userrepos.
184
 
    @param repo: Repo to write to, relative to /var/lib/ivle/svn/repositories.
185
 
    """
186
 
    f = open(os.path.join("examples/userrepos", dumpfile), "rb")
187
 
    repo = os.path.join(config['paths']['svn']['repo_path'], repo)
188
 
    errmsg = runprog_stderr(["sudo", "-u", "www-data", "svnadmin", "load",
189
 
                             repo], stdin=f)
190
 
    if errmsg is not None:
191
 
        logging.error(errmsg)
192
 
    f.close()
193
 
 
194
 
# Load the known SVN dump files
195
 
svnload("studenta.dump", "users/studenta")
196
 
svnload("group1.dump", "groups/ivle-102_2009_2_group1")
 
156
subprocess.check_call(["bin/ivle-refreshfilesystem"])