From e383f75b7c735d034bc6e2fc7f63e1e1d8f36269 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 25 Feb 2013 22:51:32 -0500 Subject: [PATCH] swc-installation-test-2.py: Add --help and --verbose The system information is useful for troubleshooting a student's installation problems, but it is probably less useful for the student themselves. Turn off this troubleshooting information by default and require the --verbose option to re-enable it. If we didn't have to maintain support for Python 2.6, we could use argparse instead of optparse. The optparse module is deprecated for 2.7, 3.2, and later, but it is still part of the stdandard library. Also update the README to point out --verbose. --- setup/README.md | 24 +++++++++++++++++++++--- setup/swc-installation-test-2.py | 19 +++++++++++++++---- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/setup/README.md b/setup/README.md index aba09a9..ee383e3 100644 --- a/setup/README.md +++ b/setup/README.md @@ -21,11 +21,29 @@ If you see something like: $ python swc-installation-test-2.py check virtual-shell... fail … - For instructings on installing a particular package, - see the failure message for that package printed above. + check for command line shell (virtual-shell) failed: + command line shell (virtual-shell) requires at least one of the following dependencies + For instructions on installing an up-to-date version, see + http://software-carpentry.org/setup/ + causes: + check for Bourne Again Shell (bash) failed: + could not find 'bash' executable for Bourne Again Shell (bash) + For instructions on installing an up-to-date version, see + http://software-carpentry.org/setup/ … -follow the suggestions to try and install any missing software. +follow the suggestions to try and install any missing software. For +additional troubleshooting information, you can use the `--verbose` +option: + + $ python swc-installation-test-2.py --verbose + check virtual-shell... fail + … + ================== + System information + ================== + os.name : posix + … Instructors =========== diff --git a/setup/swc-installation-test-2.py b/setup/swc-installation-test-2.py index 16a10ee..8449429 100755 --- a/setup/swc-installation-test-2.py +++ b/setup/swc-installation-test-2.py @@ -799,8 +799,18 @@ def print_suggestions(instructor_fallback=True): if __name__ == '__main__': + import optparse as _optparse + + parser = _optparse.OptionParser(usage='%prog [options] [check...]') + epilog = __doc__ + parser.format_epilog = lambda formatter: '\n' + epilog + parser.add_option( + '-v', '--verbose', action='store_true', + help=('print additional information to help troubleshoot ' + 'installation issues')) + options,args = parser.parse_args() try: - passed = check(_sys.argv[1:]) + passed = check(args) except InvalidCheck as e: print("I don't know how to check for {0!r}".format(e.check)) print('I do know how to check for:') @@ -812,7 +822,8 @@ if __name__ == '__main__': print(' {0}'.format(key)) _sys.exit(1) if not passed: - print() - print_system_info() - print_suggestions(instructor_fallback=True) + if options.verbose: + print() + print_system_info() + print_suggestions(instructor_fallback=True) _sys.exit(1) -- 2.26.2