41
44
Return None if the program had a 0 return code.
42
45
Return the string stderr if the program failed.
44
proc = subprocess.Popen(*popenargs, stderr=subprocess.PIPE, **kwargs)
47
kwargs['stderr'] = subprocess.PIPE
49
proc = subprocess.Popen(*popenargs, **kwargs)
45
50
_, stderr = proc.communicate()
46
51
if proc.returncode == 0:
101
106
# Unmount all the jails
102
107
logging.info("Unmounting all users.")
103
subprocess.check_call(["bin/ivle-mountallusers", "-u"])
108
subprocess.check_call(["ivle-mountallusers", "-u"])
106
111
logging.info("Dropping database \"%s\"." % dbconfig["name"])
134
139
# Build or rebuild all of the users' filesystems and subversion repos
135
140
logging.info("Creating data directories.")
136
subprocess.check_call(["bin/ivle-createdatadirs"])
141
subprocess.check_call(["ivle-createdatadirs"])
138
143
# Move all of the users' filesystems and subversion repos out of the way
139
144
# (This will clean out the user dirs because there are no users in the DB.)
140
145
logging.info("Moving existing user filesystems and repos out of the way.")
141
subprocess.check_call(["bin/ivle-refreshfilesystem"])
146
subprocess.check_call(["ivle-refreshfilesystem"])
143
148
# Populate with sample data
144
149
logging.info("Populating database with sample data.")
153
158
# Build all of the users' filesystems and subversion repos
154
159
# (This will create fresh user dirs and repos because the jails were empty.)
155
160
logging.info("Building sample users' filesystems and repos.")
156
subprocess.check_call(["bin/ivle-refreshfilesystem"])
161
subprocess.check_call(["ivle-refreshfilesystem"])
164
dbconfig = config['database']
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.
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)
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.
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",
190
if errmsg is not None:
191
logging.error(errmsg)
194
# Load the known SVN dump files
195
svnload("studenta.dump", "users/studenta")
196
svnload("group1.dump", "groups/ivle-102_2009_2_group1")