From ab22724fc761c6f64489153153c3f39648b37f5e Mon Sep 17 00:00:00 2001 From: Aaron Griffith Date: Thu, 15 Mar 2012 04:03:46 -0400 Subject: [PATCH] moved nice_exit() back into util.py (Issue #647) --- overviewer.py | 33 +++------------------------------ overviewer_core/__init__.py | 2 +- overviewer_core/util.py | 27 +++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 31 deletions(-) diff --git a/overviewer.py b/overviewer.py index d8800ba..f8914f3 100755 --- a/overviewer.py +++ b/overviewer.py @@ -45,33 +45,6 @@ helptext = """ %prog [--rendermodes=...] [options] %prog --config= [options]""" -def is_bare_console(): - """Returns true if Overviewer is running in a bare console in - Windows, that is, if overviewer wasn't started in a cmd.exe - session. - """ - if platform.system() == 'Windows': - try: - import ctypes - GetConsoleProcessList = ctypes.windll.kernel32.GetConsoleProcessList - num = GetConsoleProcessList(ctypes.byref(ctypes.c_int(0)), ctypes.c_int(1)) - if (num == 1): - return True - - except Exception: - pass - return False - -def nice_exit(ret=0): - """Drop-in replacement for sys.exit that will automatically detect - bare consoles and wait for user input before closing. - """ - if ret and is_bare_console(): - print - print "Press [Enter] to close this window." - raw_input() - sys.exit(ret) - def main(): # bootstrap the logger with defaults logger.configure() @@ -156,7 +129,7 @@ def main(): if len(args) == 0 and not options.config: # first provide an appropriate error for bare-console users # that don't provide any options - if is_bare_console(): + if util.is_bare_console(): print "\n" print "The Overviewer is a console program. Please open a Windows command prompt" print "first and run Overviewer from there. Further documentation is available at" @@ -487,10 +460,10 @@ if __name__ == "__main__": multiprocessing.freeze_support() try: ret = main() - nice_exit(ret) + util.nice_exit(ret) except Exception, e: logging.exception("""An error has occurred. This may be a bug. Please let us know! See http://docs.overviewer.org/en/latest/index.html#help This is the error that occurred:""") - nice_exit(1) + util.nice_exit(1) diff --git a/overviewer_core/__init__.py b/overviewer_core/__init__.py index ec4081e..6dc50db 100644 --- a/overviewer_core/__init__.py +++ b/overviewer_core/__init__.py @@ -68,4 +68,4 @@ def check_c_overviewer(): if not sys.argv[0].endswith("setup.py"): ret = check_c_overviewer() if ret > 0: - util.exit(ret) + util.nice_exit(ret) diff --git a/overviewer_core/util.py b/overviewer_core/util.py index b00faa8..d22b4a7 100644 --- a/overviewer_core/util.py +++ b/overviewer_core/util.py @@ -82,6 +82,33 @@ def findGitVersion(): except Exception: return "unknown" +def is_bare_console(): + """Returns true if Overviewer is running in a bare console in + Windows, that is, if overviewer wasn't started in a cmd.exe + session. + """ + if platform.system() == 'Windows': + try: + import ctypes + GetConsoleProcessList = ctypes.windll.kernel32.GetConsoleProcessList + num = GetConsoleProcessList(ctypes.byref(ctypes.c_int(0)), ctypes.c_int(1)) + if (num == 1): + return True + + except Exception: + pass + return False + +def nice_exit(ret=0): + """Drop-in replacement for sys.exit that will automatically detect + bare consoles and wait for user input before closing. + """ + if ret and is_bare_console(): + print + print "Press [Enter] to close this window." + raw_input() + sys.exit(ret) + # http://docs.python.org/library/itertools.html def roundrobin(iterables): "roundrobin('ABC', 'D', 'EF') --> A D E B F C"