206
# We build two separate lists, by walking www and console
207
list_www = build_list_py_files('www')
208
list_console = build_list_py_files('console')
209
# Make sure that the files generated by conf are in the list
210
# (since listmake is typically run before conf)
211
if "www/conf/conf.py" not in list_www:
212
list_www.append("www/conf/conf.py")
213
# Write these out to a file
215
# the files that will be created/overwritten
216
listfile = os.path.join(cwd, "install_list.py")
219
file = open(listfile, "w")
221
file.write("""# IVLE Configuration File
223
# Provides lists of all Python files to be installed by `setup.py install'.
225
# List of all installable Python files in www directory.
227
writelist_pretty(file, list_www)
229
# List of all installable Python files in console directory.
231
writelist_pretty(file, list_console)
234
except IOError, (errno, strerror):
235
print "IO error(%s): %s" % (errno, strerror)
238
print "Successfully wrote install_list.py"
241
print ("You may modify the set of installable files before cutting the "
248
def build_list_py_files(dir):
249
"""Builds a list of all py files found in a directory and its
250
subdirectories. Returns this as a list of strings."""
252
for (dirpath, dirnames, filenames) in os.walk(dir):
253
# Exclude directories beginning with a '.' (such as '.svn')
254
filter_mutate(lambda x: x[0] != '.', dirnames)
255
# All *.py files are added to the list
256
pylist += [os.path.join(dirpath, item) for item in filenames
257
if item.endswith('.py')]
260
def writelist_pretty(file, list):
261
"""Writes a list one element per line, to a file."""
267
file.write(' %s,\n' % repr(elem))
206
271
global root_dir, ivle_install_dir, jail_base, allowed_uids
207
272
# Set up some variables
384
445
dry: Bool. If True, prints but does not execute.
386
447
print prog, string.join(args, ' ')
388
ret = os.spawnvp(os.P_WAIT, prog, args)
390
raise RunError(prog, ret)
449
ret = os.spawnvp(os.P_WAIT, prog, args)
451
raise RunError(prog, ret)
392
453
def action_mkdir(path):
393
454
"""Calls mkdir. Silently ignored if the directory already exists.
394
455
Creates all parent directories as necessary."""
395
456
print "mkdir -p", path
397
459
os.makedirs(path)
398
460
except OSError, (err, msg):
421
483
if val == '': return default
486
def filter_mutate(function, list):
487
"""Like built-in filter, but mutates the given list instead of returning a
488
new one. Returns None."""
491
# Delete elements which do not match
492
if not function(list[i]):
424
496
if __name__ == "__main__":