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

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: mattgiuca
  • Date: 2007-12-21 03:21:27 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:120
setup.py: Added command-line argument mode for conf. This completely works!

Show diffs side-by-side

added added

removed removed

Lines of Context:
57
57
# Copy www/ to $target.
58
58
# Copy jail/ to jails template directory (unless --nojail specified).
59
59
 
60
 
# TODO: List in help, and handle, args for the conf operation
61
 
 
62
60
import os
63
61
import stat
64
62
import shutil
68
66
import errno
69
67
import mimetypes
70
68
import compileall
 
69
import getopt
71
70
 
72
71
# Try importing existing conf, but if we can't just set up defaults
73
72
# The reason for this is that these settings are used by other phases
104
103
# Main function skeleton from Guido van Rossum
105
104
# http://www.artima.com/weblogs/viewpost.jsp?thread=4829
106
105
 
107
 
class Usage(Exception):
108
 
    def __init__(self, msg):
109
 
        self.msg = msg
110
 
 
111
106
def main(argv=None):
112
107
    if argv is None:
113
108
        argv = sys.argv
133
128
 
134
129
    # Call the requested operation's function
135
130
    try:
136
 
        return {
 
131
        oper_func = {
137
132
            'help' : help,
138
133
            'conf' : conf,
139
134
            'build' : build,
140
135
            'listmake' : listmake,
141
136
            'install' : install,
142
 
        }[operation](argv[2:])
 
137
        }[operation]
143
138
    except KeyError:
144
139
        print >>sys.stderr, (
145
140
            """Invalid operation '%s'. Try python setup.py help."""
146
141
            % operation)
147
 
 
148
 
    try:
149
 
        try:
150
 
            opts, args = getopt.getopt(argv[1:], "h", ["help"])
151
 
        except getopt.error, msg:
152
 
            raise Usage(msg)
153
 
        # more code, unchanged
154
 
    except Usage, err:
155
 
        print >>sys.stderr, err.msg
156
 
        print >>sys.stderr, "for help use --help"
157
 
        return 2
 
142
    return oper_func(argv[2:])
158
143
 
159
144
# Operation functions
160
145
 
188
173
        print """python setup.py conf [args]
189
174
Configures IVLE with machine-specific details, most notably, various paths.
190
175
Either prompts the administrator for these details or accepts them as
191
 
command-line args.
 
176
command-line args. Will be interactive only if there are no arguments given.
 
177
Takes defaults from existing conf file if it exists.
192
178
Creates www/conf/conf.py and trampoline/conf.h.
193
179
Args are:
 
180
    --root_dir
 
181
    --ivle_install_dir
 
182
    --jail_base
 
183
    --allowed_uids
 
184
As explained in the interactive prompt or conf.py.
194
185
"""
195
186
    elif operation == 'build':
196
187
        print """python -O setup.py build [--dry|-n]
305
296
    conf_hfile = os.path.join(cwd, "trampoline/conf.h")
306
297
 
307
298
    # Fixed config options that we don't ask the admin
308
 
 
309
299
    default_app = "dummy"
310
300
 
311
 
    print """This tool will create the following files:
 
301
    # Get command-line arguments to avoid asking questions.
 
302
 
 
303
    (opts, args) = getopt.gnu_getopt(args, "", ['root_dir=',
 
304
                    'ivle_install_dir=', 'jail_base=', 'allowed_uids='])
 
305
 
 
306
    if args != []:
 
307
        print >>sys.stderr, "Invalid arguments:", string.join(args, ' ')
 
308
        return 2
 
309
 
 
310
    if opts == []:
 
311
        # Interactive mode. Prompt the user for all the values.
 
312
 
 
313
        print """This tool will create the following files:
312
314
    %s
313
315
    %s
314
316
prompting you for details about your configuration. The file will be
317
319
Please hit Ctrl+C now if you do not wish to do this.
318
320
""" % (conffile, conf_hfile)
319
321
 
320
 
    # Get information from the administrator
321
 
    # If EOF is encountered at any time during the questioning, just exit
322
 
    # silently
 
322
        # Get information from the administrator
 
323
        # If EOF is encountered at any time during the questioning, just exit
 
324
        # silently
323
325
 
324
 
    root_dir = query_user(root_dir,
325
 
    """Root directory where IVLE is located (in URL space):""")
326
 
    ivle_install_dir = query_user(ivle_install_dir,
327
 
    'Root directory where IVLE will be installed (on the local file '
328
 
    'system):')
329
 
    jail_base = query_user(jail_base,
330
 
    """Root directory where the jails (containing user files) are stored
 
326
        root_dir = query_user(root_dir,
 
327
        """Root directory where IVLE is located (in URL space):""")
 
328
        ivle_install_dir = query_user(ivle_install_dir,
 
329
        'Root directory where IVLE will be installed (on the local file '
 
330
        'system):')
 
331
        jail_base = query_user(jail_base,
 
332
        """Root directory where the jails (containing user files) are stored
331
333
(on the local file system):""")
332
 
    allowed_uids = query_user(allowed_uids,
333
 
    """UID of the web server process which will run IVLE.
 
334
        allowed_uids = query_user(allowed_uids,
 
335
        """UID of the web server process which will run IVLE.
334
336
Only this user may execute the trampoline. May specify multiple users as
335
337
a comma-separated list.
336
338
    (eg. "1002,78")""")
337
339
 
 
340
    else:
 
341
        opts = dict(opts)
 
342
        # Non-interactive mode. Parse the options.
 
343
        if '--root_dir' in opts:
 
344
            root_dir = opts['--root_dir']
 
345
        if '--ivle_install_dir' in opts:
 
346
            ivle_install_dir = opts['--ivle_install_dir']
 
347
        if '--jail_base' in opts:
 
348
            jail_base = opts['--jail_base']
 
349
        if '--allowed_uids' in opts:
 
350
            allowed_uids = opts['--allowed_uids']
 
351
 
338
352
    # Error handling on input values
339
 
 
340
353
    try:
341
354
        allowed_uids = map(int, allowed_uids.split(','))
342
355
    except ValueError: