gump-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From leosim...@apache.org
Subject svn commit: r159159 - in gump/branches/Gump3/pygump: gump.log.config main.py python/gump/config.py python/gump/util/sysinfo.py
Date Sun, 27 Mar 2005 18:18:03 GMT
Author: leosimons
Date: Sun Mar 27 10:18:01 2005
New Revision: 159159

URL: http://svn.apache.org/viewcvs?view=rev&rev=159159
Log:
* creating a proper logging config file

* importing the new logging config file during configuration

* changing log names everywhere to use '.' as seperator instead of '-' since the logging framework
assumes '.' in several places

* updating main.py to use the subprocess module that is new in python 2.4 to make the task
of running svn much cleaner (and safer)

* updating sysinfo.py to also use the subprocess module

* updating the main.py code to check for python version >= 2.4

Note that if 2.4 turns out to be a problem, we can backport the subprocess module from http://www.lysator.liu.se/~astrand/popen5/
and use it with 2.3.

Modified:
    gump/branches/Gump3/pygump/gump.log.config
    gump/branches/Gump3/pygump/main.py
    gump/branches/Gump3/pygump/python/gump/config.py
    gump/branches/Gump3/pygump/python/gump/util/sysinfo.py

Modified: gump/branches/Gump3/pygump/gump.log.config
URL: http://svn.apache.org/viewcvs/gump/branches/Gump3/pygump/gump.log.config?view=diff&r1=159158&r2=159159
==============================================================================
--- gump/branches/Gump3/pygump/gump.log.config (original)
+++ gump/branches/Gump3/pygump/gump.log.config Sun Mar 27 10:18:01 2005
@@ -1,26 +1,71 @@
 # not used atm..
 [loggers]
-keys=root
+keys=root,engine,modeller,walker,plugin,plugin_dynagumper,util_db
 
 [handlers]
-keys=stdout
+keys=stdout,filehandler
 
 [formatters]
-keys=simple
+keys=simple,fileformatter
 
 [logger_root]
-level=INFO
-handlers=stdout
+level=DEBUG
+handlers=stdout,filehandler
 propagate=1
-qualname=gump
+
+[logger_engine]
+level=DEBUG
+handlers=stdout,filehandler
+propagate=1
+qualname=engine
+
+[logger_modeller]
+level=DEBUG
+handlers=stdout,filehandler
+propagate=1
+qualname=modeller
+
+[logger_walker]
+level=DEBUG
+handlers=stdout,filehandler
+propagate=1
+qualname=walker
+
+[logger_plugin]
+level=DEBUG
+handlers=stdout,filehandler
+propagate=1
+qualname=plugin
+
+[logger_util_db]
+level=DEBUG
+handlers=stdout,filehandler
+propagate=1
+qualname=util.db
+
+[logger_plugin_dynagumper]
+level=DEBUG
+handlers=stdout,filehandler
+propagate=1
+qualname=plugin.dynagumper
 
 [handler_stdout]
+level=DEBUG
 class=StreamHandler
-level=NOTSET
 formatter=simple
 args=(sys.stdout,)
 
+[handler_filehandler]
+level=DEBUG
+#class=TimedRotatingFileHandler
+class=FileHandler
+formatter=fileformatter
+args=('work/log/run.log', 'w')
+#args=('work/log/run.log', 'W', '0', 10)
+
 [formatter_simple]
-format=%(message)s
-datefmt=
+format=%(levelname)s - %(message)s
 
+[formatter_fileformatter]
+format=%(levelname)s [%(name)s] %(asctime)s: %(pathname)s:%(lineno)d: %(message)s
+datefmt=%Y-%m-%d@%H:%M:%S

Modified: gump/branches/Gump3/pygump/main.py
URL: http://svn.apache.org/viewcvs/gump/branches/Gump3/pygump/main.py?view=diff&r1=159158&r2=159159
==============================================================================
--- gump/branches/Gump3/pygump/main.py (original)
+++ gump/branches/Gump3/pygump/main.py Sun Mar 27 10:18:01 2005
@@ -36,6 +36,9 @@
 import time
 from xml.dom import minidom
 import smtplib
+from subprocess import Popen
+from subprocess import PIPE
+from subprocess import STDOUT
 
 # for log messages...
 SEP = "------------------------------------------------------------------------------\n"
@@ -220,8 +223,8 @@
 def _check_version():
     """Raises exception if python version < 2.3."""
     (major, minor, micro, releaselevel, serial) = sys.version_info
-    if not major >=2 and minor >= 3:
-        raise Error, 'CRITICAL: Gump requires Python 2.3 or above. The ' + \
+    if not major >=2 and minor >= 4:
+        raise Error, 'CRITICAL: Gump requires Python 2.4 or above. The ' + \
                 'current version is %s.' % sys.version()
 
 
@@ -268,36 +271,19 @@
 
 def _svn_update(log, options):
     """Updates pygump itself from SVN."""
-    command = "sh -c 'svn update --non-interactive "
-    if not options.debug: command += "-q " # suppress output
-    svnlogfile = os.path.join( options.logdir, "svnuplog.txt" )
+    command = ["svn", "update", "--non-interactive"]
+    if not options.debug: command.append("-q") # suppress output
     
-    command += os.path.join(options.homedir,'pygump')
-    
-    command += " >" + svnlogfile + " 2>&1'"
-
-    try:
-        result = os.system(command)
-        if not os.name == 'dos' and not os.name == 'nt':
-            result = (((result & 0xFF00) >> 8) & 0xFF)
-            
-        if result: # any not 0 is bad...
-            msg = "An error occurred while self-updating pygump from svn"
-            log.error( msg + ":")
-            log.target.write(SEP); print SEP,
-            
-            svnlog=open(svnlogfile,'r')
-            line = svnlog.readline()
-            while line:
-                log.target.write(line); print line,
-                line = svnlog.readline()
-    
-            svnlog.close()
-            log.target.write(SEP); print SEP,
-            raise Error, msg
-    finally:
-        os.remove(svnlogfile)
-
+    p = Popen(command,stdout=PIPE,stderr=STDOUT)
+    p.wait()
+    if p.returncode:
+        msg = "An error occurred while self-updating pygump from svn"
+        log.error( msg + ":")
+        log.target.write(SEP); print SEP,
+        svnlog = p.communicate()[0]
+        log.target.write(svnlog); print svnlog
+        log.target.write(SEP); print SEP,
+        raise Error, msg
 
 def _send_email(toaddr,fromaddr,subject,data,server,port=25):
     """Utility method for sending out e-mails."""

Modified: gump/branches/Gump3/pygump/python/gump/config.py
URL: http://svn.apache.org/viewcvs/gump/branches/Gump3/pygump/python/gump/config.py?view=diff&r1=159158&r2=159159
==============================================================================
--- gump/branches/Gump3/pygump/python/gump/config.py (original)
+++ gump/branches/Gump3/pygump/python/gump/config.py Sun Mar 27 10:18:01 2005
@@ -75,6 +75,10 @@
     config.database_user = settings.databaseuser
     config.database_password = settings.databasepassword
     
+    # set up logging
+    from logging.config import fileConfig
+    fileConfig('gump.log.config')
+    
     return config
 
 
@@ -104,7 +108,7 @@
     # TODO: append more plugins here...
 
     from gump.plugins import LoggingPlugin
-    log = get_logger(config, "plugin-log")
+    log = get_logger(config, "plugin")
     plugins.append(LoggingPlugin(log))
     
     post_process_plugins = []
@@ -112,9 +116,9 @@
     post_process_plugins.append(TimerPlugin("run_end"))
 
     from gump.plugins.dynagumper import Dynagumper
-    log = get_logger(config, "util-db")
+    log = get_logger(config, "util")
     db = get_db(log,config)
-    log = get_logger(config, "plugin-dynagumper")
+    log = get_logger(config, "plugin.dynagumper")
     post_process_plugins.append(Dynagumper(db, log))
     
     return (pre_process_plugins, plugins, post_process_plugins)
@@ -136,7 +140,7 @@
     # TODO: implement an error handler that does actual recovery...
     
     from gump.plugins import LoggingErrorHandler
-    log = get_logger(config, "plugin-error-handler")
+    log = get_logger(config, "plugin.error-handler")
     return LoggingErrorHandler(log)
 
 ###

Modified: gump/branches/Gump3/pygump/python/gump/util/sysinfo.py
URL: http://svn.apache.org/viewcvs/gump/branches/Gump3/pygump/python/gump/util/sysinfo.py?view=diff&r1=159158&r2=159159
==============================================================================
--- gump/branches/Gump3/pygump/python/gump/util/sysinfo.py (original)
+++ gump/branches/Gump3/pygump/python/gump/util/sysinfo.py Sun Mar 27 10:18:01 2005
@@ -20,110 +20,59 @@
 __copyright__ = "Copyright (c) 2005 The Apache Software Foundation"
 __license__   = "http://www.apache.org/licenses/LICENSE-2.0"
 
-import os
-from tempfile import mkstemp
-
-# This is what _system returns if os.system() for some very strange
-# reason would throw an exception.
-RESULT_IF_SYSTEM_CALL_FAILS = 10000
-
-def _safe_close(fd):
-    """Closes both file descriptors and python "files" properly
-    without throwing an exception."""
-    try:
-        if isinstance(fd,int):
-            os.close(fd)
-        else:
-            fd.close()
-    except:
-        pass
-
-def _safe_rm(filename):
-    """Deletes a file without throwing an exception."""
-    try:
-        os.remove(filename)
-    except:
-        pass
-    
-#TODO solidify and move elsewhere
-def _system(command):
-    """This is a utility method that can be used to execute arbitrary
-    commands sent to other programs, capturing standard out and standard
-    error. Note that this is a horribly inefficient way to execute
-    commands, so avoid it if you can.
-
-    Returns a tuple containing the exit code for the command, the standard
-    out log, and the standard error log."""
-    (f, scriptname) = mkstemp()
-    os.write(f,command)
-    _safe_close(f)
-    (f, soutname) = mkstemp()
-    _safe_close(f)
-    (f, serrname) = mkstemp()
-    _safe_close(f)
-    
-    try:
-        cmd = "sh -e '%s' >%s 2>%s" % (scriptname, soutname, serrname)
-    
-        result = RESULT_IF_SYSTEM_CALL_FAILS
-        try:
-            result = os.system(cmd)
-        except:
-            pass
-        if not os.name == 'dos' and not os.name == 'nt':
-            result = (((result & 0xFF00) >> 8) & 0xFF)
-        
-        f = open(soutname)
-        output = f.read()
-        _safe_close(f)
-        f = open(serrname)
-        error = f.read()
-        _safe_close(f)
-    
-        return (result, output, error)
-    finally:
-        _safe_rm(scriptname)
-        _safe_rm(soutname)
-        _safe_rm(serrname)
+from subprocess import Popen
+from subprocess import PIPE
 
 def amount_of_memory():
     """Returning an integer giving the amount of RAM memory in the system,
     in megabytes. Returns 0 if the amount of RAM cannot be determined."""
     amount = 0 # i.e., we don't know
-    cmd = 'cat /proc/meminfo | grep MemTotal | sed -e "s/[^0-9]//g"'
-    (result, output, error) = _system(cmd)
-    if not result: # exit status 0 is good!
-        try:
-            amount = int(output)
-        except:
-            pass
-    
+    cat = Popen(["cat", "/proc/meminfo"], stdout=PIPE)
+    if cat.wait():
+        return amount
+    grep = Popen(["grep", "MemTotal"], stdin=cat.stdout)
+    if grep.wait():
+        return amount
+    sed = Popen(["sed", "-e", "s/[^0-9]//g"], stdin=grep.stdout)
+    result = sed.wait()
+    if not result:
+        amount = int(sed.communicate()[0])
     return amount
     
 def amount_of_cpu_mhz():
     """Returning an integer giving the processor speed for this system,
     in MHz. Returns 0 if the processor speed cannot be determined."""
     amount = 0 # i.e., we don't know
-    cmd = "cat /proc/cpuinfo | grep MHz | sed -e 's/[^0-9]//g' | awk '!x[$0]++'"
-    (result, output, error) = _system(cmd)
-    if not result: # exit status 0 is good!
-        try:
-            amount = int(output)
-        except:
-            pass
-    
+    cat = Popen(["cat", "/proc/cpuinfo"], stdout=PIPE)
+    if cat.wait():
+        return amount
+    grep = Popen(["grep", "MHz"], stdin=cat.stdout)
+    if grep.wait():
+        return amount
+    sed = Popen(["sed", "-e", "s/[^0-9]//g"], stdin=grep.stdout)
+    if sed.wait():
+        return amount
+    awk = Popen(["awk", "!x[$0]++"], stdin=sed.stdout)
+    result = awk.wait()
+    if not result:
+        amount = int(sed.communicate()[0])
     return amount
 
 def number_of_cpus():
     """Returning an integer giving the number of CPUs in the system.
     Returns 0 if the number of CPUs cannot be determined."""
     amount = 0 # i.e., we don't know
-    cmd = 'cat /proc/cpuinfo | grep "^processor" | sed -e "s/[^0-9]//g" | grep -c ".*"'
-    (result, output, error) = _system(cmd)
-    if not result: # exit status 0 is good!
-        try:
-            amount = int(output)
-        except:
-            pass
-    
+    cat = Popen(["cat", "/proc/cpuinfo"], stdout=PIPE)
+    if cat.wait():
+        return amount
+    grep = Popen(["grep", "^processor"], stdin=cat.stdout)
+    if grep.wait():
+        return amount
+    sed = Popen(["sed", "-e", "s/[^0-9]//g"], stdin=grep.stdout)
+    if sed.wait():
+        return amount
+    grep2 = Popen(["grep", "-c", ".*"], stdin=sed.stdout)
+    result = grep2.wait()
+    if not result:
+        amount = int(sed.communicate()[0])
     return amount



Mime
View raw message