commit-gnue
[Top][All Lists]
Advanced

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

gnue/gnue-common/gnue/common GClientApp.py


From: Jason Cater
Subject: gnue/gnue-common/gnue/common GClientApp.py
Date: Fri, 11 May 2001 17:04:35 -0700

CVSROOT:        /home/cvs
Module name:    gnue
Changes by:     Jason Cater <address@hidden>    01/05/11 17:04:35

Modified files:
        gnue-common/gnue/common: GClientApp.py 

Log message:
        Added profiling support to the new GClientApp so profiling will be 
provided by default to all client apps.  Updated gfclient to reflect this 
change (it previously did its own profiling).

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/gnue/common/GClientApp.py.diff?cvsroot=OldCVS&tr1=1.2&tr2=1.3&r1=text&r2=text

Patches:
Index: gnue/gnue-common/gnue/common/GClientApp.py
diff -u gnue/gnue-common/gnue/common/GClientApp.py:1.2 
gnue/gnue-common/gnue/common/GClientApp.py:1.3
--- gnue/gnue-common/gnue/common/GClientApp.py:1.2      Fri May 11 14:59:04 2001
+++ gnue/gnue-common/gnue/common/GClientApp.py  Fri May 11 17:04:35 2001
@@ -35,6 +35,7 @@
 import string 
 import os
 
+
 class GClientApp:  
 
   # Attributes to be overwritten by subclasses
@@ -43,11 +44,22 @@
   COMMAND_OPTIONS = []  # Should be in same format as _base_options below
   SUMMARY = "A brief summary of the program goes here."
   USAGE = "%s [options] file" % sys.argv[0]
+
+
+  #  Run the program
+  #  Should be overwritten by subclasses
+  def run(self): 
+    pass
+
+
+  # Attributes that will be set by GClientApp after __init__ has run
+  OPTIONS = {}        # Will contain a hash containing command line options
+  ARGUMENTS = []      # Will contain an array of command line arguments
+  connections = None  # Will contain a GConnection object
+
 
-  # Attributes that will be set by 
-  OPTIONS = {}      # Will contain a hash containing command line options
-  ARGUMENTS = []    # Will contain an array of command line arguments
 
+
   def __init__(self): 
 
     # format of COMMAND_OPTIONS and _base_options: 
@@ -114,33 +126,58 @@
       self.printVersion()
       sys.exit()
 
-#    if self.OPTIONS['connections']: 
-#      self.connections_file = self.OPTIONS['connections']
-#    elif os.environ.has_key('GNUE_CONNECTIONS'):
-#      self.connections_file = self.OPTIONS['GNUE_CONNECTION']
-#    else: 
-#      self.handleStartupError(
-#          'Unable to load the connections definition file.\n' \
-#          + '\n   Please set the environmental variable GNUE_CONNECTIONS or ' 
\
-#          + '\n   use the "-f" command option.')
+    # Should we profile?
+    self._run = self.run
+    if self.OPTIONS['profile']: 
+      self.run = self._profile
 
+    # Setup debugging
     try: 
       GDebug.setDebug(int("%s" % self.OPTIONS['debug_level']),
           self.OPTIONS['debug_file'])
     except ValueError: 
       self.handleStartupError('The debug_level option ("-d") expects a 
numerical value.')
 
-
     GDebug.printMesg(1,"Run Options: %s" % opt)
     GDebug.printMesg(1,"Run Arguments: %s" % self.ARGUMENTS)
 
+   
+    # Get the connection definitions
+
+#    if self.OPTIONS['connections']: 
+#      self.connections_file = self.OPTIONS['connections']
+#    elif os.environ.has_key('GNUE_CONNECTIONS'):
+#      self.connections_file = self.OPTIONS['GNUE_CONNECTION']
+#    else: 
+#      self.handleStartupError(
+#          'Unable to load the connections definition file.\n' \
+#          + '\n   Please set the environmental variable GNUE_CONNECTIONS or ' 
\
+#          + '\n   use the "-f" command option.')
+#
+#    GDebug.printMesg(1, 'Connection Definition: "%s"' % self.connections_file)
+#
+#    try:
+#      self.connections = GConnections.GConnections(self.connections_file)
+#    except GConnections.InvalidFormatError, msg: 
+#      self.handleStartupError(
+#          'Unable to load the connections definition file.\n' \
+#          + '\n   The connections file is in an invalid format. ' \
+#          + '\n   %s' \
+#             % msg)
+#    except:
+#      self.handleStartupError(
+#          'Unable to load the connections definition file.\n' \
+#          + '\n   The connections file specified either does ' \
+#          + '\n   not exist or is not readable by your account.\n' \
+#          + '\n   Location: "%s"'
+#             % self.connections_file)
+
   #
   #  Display version information for this application
   #
   def printVersion(self): 
     print "\n%s\nVersion %s\n" % (self.NAME, self.VERSION)
-
-
+    
   #
   #  Display version information for this program
   #
@@ -193,6 +230,10 @@
     print "Report bugs to address@hidden"
 
 
+  #
+  #  Display a startup error and exit gracefully with a message on 
+  #  how to get help
+  #
   def handleStartupError(self, msg):
       self.printVersion()
 
@@ -204,5 +245,20 @@
         print '-' * 60
       print "\nFor help, type:\n   %s --help\n" % (sys.argv[0])
       sys.exit()
+
+  #
+  #  Run with profiling 
+  #
+  def _profile(self): 
+
+    import profile
+    prof = profile.Profile()
+    prof.runctx( 'self._run()', globals(), locals() )
+
+    import pstats
+    p = pstats.Stats('runstats')
+    p.sort_stats('time').print_stats(50)
+    p.sort_stats('cumulative').print_stats(50)
+
 
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]