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

« back to all changes in this revision

Viewing changes to setup/configure.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:
33
33
import hashlib
34
34
import uuid
35
35
 
36
 
from setup.util import query_user
37
36
import ivle.config
38
37
 
39
38
import configobj
222
221
    """
223
222
# The password for the usrmgt-server.""", ask=False))
224
223
 
 
224
def query_user(default, prompt):
 
225
    """Prompts the user for a string, which is read from a line of stdin.
 
226
    Exits silently if EOF is encountered. Returns the string, with spaces
 
227
    removed from the beginning and end.
 
228
 
 
229
    Returns default if a 0-length line (after spaces removed) was read.
 
230
    """
 
231
    if default is None:
 
232
        # A default of None means the value will be computed specially, so we
 
233
        # can't really tell you what it is
 
234
        defaultstr = "computed"
 
235
    elif isinstance(default, basestring):
 
236
        defaultstr = '"%s"' % default
 
237
    else:
 
238
        defaultstr = repr(default)
 
239
    sys.stdout.write('%s\n    (default: %s)\n>' % (prompt, defaultstr))
 
240
    try:
 
241
        val = sys.stdin.readline()
 
242
    except KeyboardInterrupt:
 
243
        # Ctrl+C
 
244
        sys.stdout.write("\n")
 
245
        sys.exit(1)
 
246
    sys.stdout.write("\n")
 
247
    # If EOF, exit
 
248
    if val == '': sys.exit(1)
 
249
    # If empty line, return default
 
250
    val = val.strip()
 
251
    if val == '': return default
 
252
    return val
 
253
 
225
254
def configure(args):
226
255
    # Call the real function
227
256
    return __configure(args)