Mercurial > hg > graal-compiler
comparison mxtool/mx.py @ 11511:3110bea9a6b0
mx: add helper method for yes/no question
author | Gilles Duboscq <duboscq@ssw.jku.at> |
---|---|
date | Mon, 02 Sep 2013 11:40:24 +0200 |
parents | 2d228d304247 |
children | dc3c8df55905 |
comparison
equal
deleted
inserted
replaced
11510:231958c9ddf9 | 11511:3110bea9a6b0 |
---|---|
917 javaHome = None | 917 javaHome = None |
918 else: | 918 else: |
919 break | 919 break |
920 | 920 |
921 envPath = join(_mainSuite.dir, 'mx', 'env') | 921 envPath = join(_mainSuite.dir, 'mx', 'env') |
922 answer = raw_input('Persist this setting by adding "JAVA_HOME=' + javaHome + '" to ' + envPath + '? [Yn]: ') | 922 if ask_yes_no('Persist this setting by adding "JAVA_HOME=' + javaHome + '" to ' + envPath, 'y'): |
923 if not answer.lower().startswith('n'): | |
924 with open(envPath, 'a') as fp: | 923 with open(envPath, 'a') as fp: |
925 print >> fp, 'JAVA_HOME=' + javaHome | 924 print >> fp, 'JAVA_HOME=' + javaHome |
926 | 925 |
927 return javaHome | 926 return javaHome |
928 | 927 |
2926 dirnames[:] = [] | 2925 dirnames[:] = [] |
2927 else: | 2926 else: |
2928 projectConfigFiles = frozenset(['.classpath', 'nbproject']) | 2927 projectConfigFiles = frozenset(['.classpath', 'nbproject']) |
2929 indicators = projectConfigFiles.intersection(files) | 2928 indicators = projectConfigFiles.intersection(files) |
2930 if len(indicators) != 0: | 2929 if len(indicators) != 0: |
2931 if not sys.stdout.isatty() or raw_input(currentDir + ' looks like a removed project -- delete it? [yn]: ') == 'y': | 2930 if not sys.stdout.isatty() or ask_yes_no(currentDir + ' looks like a removed project -- delete it', 'n'): |
2932 shutil.rmtree(currentDir) | 2931 shutil.rmtree(currentDir) |
2933 log('Deleted ' + currentDir) | 2932 log('Deleted ' + currentDir) |
2934 | 2933 |
2935 def javadoc(args, parser=None, docDir='javadoc', includeDeps=True): | 2934 def javadoc(args, parser=None, docDir='javadoc', includeDeps=True): |
2936 """generate javadoc for some/all Java projects""" | 2935 """generate javadoc for some/all Java projects""" |
3407 projectsFile = join(s.dir, 'mx', 'projects') | 3406 projectsFile = join(s.dir, 'mx', 'projects') |
3408 if exists(projectsFile): | 3407 if exists(projectsFile): |
3409 log(projectsFile) | 3408 log(projectsFile) |
3410 for p in s.projects: | 3409 for p in s.projects: |
3411 log('\t' + p.name) | 3410 log('\t' + p.name) |
3411 | |
3412 def ask_yes_no(question, default=None): | |
3413 """""" | |
3414 assert not default or default == 'y' or default == 'n' | |
3415 if not sys.stdout.isatty(): | |
3416 if default: | |
3417 return default | |
3418 else: | |
3419 abort("Can not answer '" + question + "?' if stdout is not a tty") | |
3420 questionMark = '? [yn]: ' | |
3421 if default: | |
3422 questionMark = questionMark.replace(default, default.upper()) | |
3423 answer = raw_input(question + questionMark) or default | |
3424 while not answer: | |
3425 answer = raw_input(question + questionMark) | |
3426 return answer.lower().startswith('y') | |
3412 | 3427 |
3413 def add_argument(*args, **kwargs): | 3428 def add_argument(*args, **kwargs): |
3414 """ | 3429 """ |
3415 Define how a single command-line argument. | 3430 Define how a single command-line argument. |
3416 """ | 3431 """ |