[gnome-games/applygsoc2009: 22/76] Make profile work



commit 3312cf35164bf762f31be38b107660acf13f735f
Author: Pablo Castellano <pablog src gnome org>
Date:   Thu Aug 26 11:19:40 2010 +0200

    Make profile work

 gnome-sudoku/src/lib/gnome_sudoku.py |   32 ++++++++++++++++++++++++++++++--
 gnome-sudoku/src/lib/main.py         |   33 ++-------------------------------
 2 files changed, 32 insertions(+), 33 deletions(-)
---
diff --git a/gnome-sudoku/src/lib/gnome_sudoku.py b/gnome-sudoku/src/lib/gnome_sudoku.py
index 1271ed1..65632bd 100644
--- a/gnome-sudoku/src/lib/gnome_sudoku.py
+++ b/gnome-sudoku/src/lib/gnome_sudoku.py
@@ -1,6 +1,10 @@
 # -*- coding: utf-8 -*-
+import optparse
 import sys
 
+import main
+import defaults
+
 # Ignore any exceptions writing to stdout using print statements
 class SafeStdout:
     def __init__(self):
@@ -17,6 +21,30 @@ class SafeStdout:
 
 sys.stdout = SafeStdout()
 
+def profile_me (func):
+    import tempfile, hotshot, hotshot.stats, os.path
+    pname = os.path.join (tempfile.gettempdir(), 'GNOME_SUDOKU_HOTSHOT_PROFILE')
+    prof = hotshot.Profile (pname)
+    prof.runcall (func)
+    stats = hotshot.stats.load (pname)
+    stats.strip_dirs ()
+    stats.sort_stats ('time', 'calls').print_stats()
+
 def start_game ():
-    import main
-    main.start_game()
+    parser = optparse.OptionParser(
+        version = defaults.VERSION,
+        option_list = [
+            optparse.make_option("-v", const=True, action="store_const",
+                dest="debug", help="Print debug information",
+                default=False),
+            optparse.make_option("-p", const=True, action="store_const",
+                dest="profile", help="Profile gnome-sudoku",
+                default=False)])
+
+    options, args = parser.parse_args()
+
+    if options.profile:
+        print 'Profiling GNOME Sudoku'
+        profile_me(lambda: main.start_game(options.debug))
+    else:
+        main.start_game(options.debug)
diff --git a/gnome-sudoku/src/lib/main.py b/gnome-sudoku/src/lib/main.py
index 2f5960d..df4b230 100644
--- a/gnome-sudoku/src/lib/main.py
+++ b/gnome-sudoku/src/lib/main.py
@@ -7,7 +7,6 @@ except ImportError, err:
 
 import os.path
 import threading
-import optparse
 
 import gobject
 import gtk
@@ -935,45 +934,17 @@ class TrackerBox (gtk.VBox):
         # The notes already have tracker info in them, so just store the list
         self.main_ui.gsd.apply_notelist(self.main_ui.cleared_notes.pop())
 
-def start_game ():
-parser = optparse.OptionParser(
-    version = VERSION,
-    option_list = [
-        optparse.make_option("-v", const=True, action="store_const",
-           dest="debug", help="Print debug information",
-           default=False),
-        optparse.make_option("-p", const=True, action="store_const",
-           dest="profile", help="Profile gnome-sudoku",
-           default=False)])
-
-    options, args = parser.parse_args()
-
-    if options.debug:
+def start_game (debug=False):
+    if debug:
         print 'Starting GNOME Sudoku in debug mode'
 
     ##  You must call g_thread_init() before executing any other GLib
     ##  functions in a threaded GLib program.
     gobject.threads_init()
 
-    if options.profile:
-        options.profile = False
-        profile_me()
-        return
-
     u = UI()
 	try:
     	gtk.main()
     except KeyboardInterrupt:
         # properly quit on a keyboard interrupt...
         u.quit_cb()
-
-def profile_me ():
-    print 'Profiling GNOME Sudoku'
-    import tempfile, hotshot, hotshot.stats
-    pname = os.path.join(tempfile.gettempdir(), 'GNOME_SUDOKU_HOTSHOT_PROFILE')
-    prof = hotshot.Profile(pname)
-    prof.runcall(start_game)
-    stats = hotshot.stats.load(pname)
-    stats.strip_dirs()
-    stats.sort_stats('time', 'calls').print_stats()
-



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]