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

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: mattgiuca
  • Date: 2007-12-20 23:09:08 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:107
setup.py: Added "action" functions which encapsulate calling OS functions.
Added most of the "build" operation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
import os
63
63
import sys
64
64
import getopt
 
65
import string
 
66
import errno
65
67
 
66
68
# Main function skeleton from Guido van Rossum
67
69
# http://www.artima.com/weblogs/viewpost.jsp?thread=4829
290
292
    return 0
291
293
 
292
294
def build(args):
293
 
    print "Build"
 
295
    dry = False     # Set to True later if --dry
 
296
 
 
297
    # Compile the trampoline
 
298
    action_runprog('gcc', ['-Wall', '-o', 'trampoline/trampoline',
 
299
        'trampoline/trampoline.c'], dry)
 
300
 
 
301
    # Create the jail and its subdirectories
 
302
    action_mkdir('jail')
 
303
    action_mkdir('jail/bin')
 
304
    action_mkdir('jail/lib')
 
305
    action_mkdir('jail/usr')
 
306
    action_mkdir('jail/usr/bin')
 
307
    action_mkdir('jail/usr/lib')
 
308
    action_mkdir('jail/opt')
 
309
    action_mkdir('jail/home')
 
310
    action_mkdir('jail/tmp')
 
311
 
 
312
    # TODO: Copy console into the jail
 
313
    # TODO: Copy operating system files into the jail
 
314
    # TODO: Compile .py files into .pyc files
 
315
 
294
316
    return 0
295
317
 
296
318
def listmake(args):
301
323
    print "Install"
302
324
    return 0
303
325
 
 
326
# The actions call Python os functions but print actions and handle dryness.
 
327
# May still throw os exceptions if errors occur.
 
328
 
 
329
def action_runprog(prog, args, dry):
 
330
    """Runs a unix program. Searches in $PATH. Synchronous (waits for the
 
331
    program to return). Runs in the current environment. First prints the
 
332
    action as a "bash" line.
 
333
 
 
334
    prog: String. Name of the program. (No path required, if in $PATH).
 
335
    args: [String]. Arguments to the program.
 
336
    dry: Bool. If True, prints but does not execute.
 
337
    """
 
338
    print prog, string.join(args, ' ')
 
339
    if not dry:
 
340
        os.spawnvp(os.P_WAIT, prog, args)
 
341
 
 
342
def action_mkdir(path):
 
343
    """Calls mkdir. Silently ignored if the directory already exists."""
 
344
    print "mkdir", path
 
345
    try:
 
346
        os.mkdir(path)
 
347
    except OSError, (err, msg):
 
348
        if err != errno.EEXIST:
 
349
            raise
 
350
 
304
351
def query_user(prompt):
305
352
    """Prompts the user for a string, which is read from a line of stdin.
306
353
    Exits silently if EOF is encountered. Returns the string, with spaces