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

« back to all changes in this revision

Viewing changes to setup/util.py

setup.util: Moved query_user to setup.configure. (It's the only user of this
    code).
    configure no longer has a dependency on setup.util.

Show diffs side-by-side

added added

removed removed

Lines of Context:
235
235
    if not dry:
236
236
        os.chmod(file, stat.S_IRUSR | stat.S_IWUSR)
237
237
 
238
 
def query_user(default, prompt):
239
 
    """Prompts the user for a string, which is read from a line of stdin.
240
 
    Exits silently if EOF is encountered. Returns the string, with spaces
241
 
    removed from the beginning and end.
242
 
 
243
 
    Returns default if a 0-length line (after spaces removed) was read.
244
 
    """
245
 
    if default is None:
246
 
        # A default of None means the value will be computed specially, so we
247
 
        # can't really tell you what it is
248
 
        defaultstr = "computed"
249
 
    elif isinstance(default, basestring):
250
 
        defaultstr = '"%s"' % default
251
 
    else:
252
 
        defaultstr = repr(default)
253
 
    sys.stdout.write('%s\n    (default: %s)\n>' % (prompt, defaultstr))
254
 
    try:
255
 
        val = sys.stdin.readline()
256
 
    except KeyboardInterrupt:
257
 
        # Ctrl+C
258
 
        sys.stdout.write("\n")
259
 
        sys.exit(1)
260
 
    sys.stdout.write("\n")
261
 
    # If EOF, exit
262
 
    if val == '': sys.exit(1)
263
 
    # If empty line, return default
264
 
    val = val.strip()
265
 
    if val == '': return default
266
 
    return val
267
 
 
268
238
def filter_mutate(function, list):
269
239
    """Like built-in filter, but mutates the given list instead of returning a
270
240
    new one. Returns None."""