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

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: mattgiuca
  • Date: 2007-12-21 01:30:40 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:114
setup.py: Wrote listmake (and ancillary functions).

Show diffs side-by-side

added added

removed removed

Lines of Context:
202
202
            % operation)
203
203
    return 1
204
204
 
 
205
def listmake(args):
 
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
 
214
    cwd = os.getcwd()
 
215
    # the files that will be created/overwritten
 
216
    listfile = os.path.join(cwd, "install_list.py")
 
217
 
 
218
    try:
 
219
        file = open(listfile, "w")
 
220
 
 
221
        file.write("""# IVLE Configuration File
 
222
# install_list.py
 
223
# Provides lists of all Python files to be installed by `setup.py install'.
 
224
 
 
225
# List of all installable Python files in www directory.
 
226
list_www = """)
 
227
        writelist_pretty(file, list_www)
 
228
        file.write("""
 
229
# List of all installable Python files in console directory.
 
230
list_console = """)
 
231
        writelist_pretty(file, list_console)
 
232
 
 
233
        file.close()
 
234
    except IOError, (errno, strerror):
 
235
        print "IO error(%s): %s" % (errno, strerror)
 
236
        sys.exit(1)
 
237
 
 
238
    print "Successfully wrote install_list.py"
 
239
 
 
240
    print
 
241
    print ("You may modify the set of installable files before cutting the "
 
242
            "distribution:")
 
243
    print listfile
 
244
    print
 
245
 
 
246
    return 0
 
247
 
 
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."""
 
251
    pylist = []
 
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')]
 
258
    return pylist
 
259
 
 
260
def writelist_pretty(file, list):
 
261
    """Writes a list one element per line, to a file."""
 
262
    if list == []:
 
263
        file.write("[]\n")
 
264
    else:
 
265
        file.write('[\n')
 
266
        for elem in list:
 
267
            file.write('    %s,\n' % repr(elem))
 
268
        file.write(']\n')
 
269
 
205
270
def conf(args):
206
271
    global root_dir, ivle_install_dir, jail_base, allowed_uids
207
272
    # Set up some variables
352
417
 
353
418
    return 0
354
419
 
355
 
def listmake(args):
356
 
    print "Listmake"
357
 
    return 0
358
 
 
359
420
def install(args):
360
421
    print "Install"
361
422
    return 0
384
445
    dry: Bool. If True, prints but does not execute.
385
446
    """
386
447
    print prog, string.join(args, ' ')
387
 
    if not dry:
388
 
        ret = os.spawnvp(os.P_WAIT, prog, args)
389
 
        if ret != 0:
390
 
            raise RunError(prog, ret)
 
448
    if dry: return
 
449
    ret = os.spawnvp(os.P_WAIT, prog, args)
 
450
    if ret != 0:
 
451
        raise RunError(prog, ret)
391
452
 
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
 
457
    if dry: return
396
458
    try:
397
459
        os.makedirs(path)
398
460
    except OSError, (err, msg):
421
483
    if val == '': return default
422
484
    return val
423
485
 
 
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."""
 
489
    i = len(list)-1
 
490
    while i >= 0:
 
491
        # Delete elements which do not match
 
492
        if not function(list[i]):
 
493
            del list[i]
 
494
        i -= 1
 
495
 
424
496
if __name__ == "__main__":
425
497
    sys.exit(main())