[rhmessaging-commits] rhmessaging commits: r1783 - in mgmt: cumin/bin and 4 other directories.

rhmessaging-commits at lists.jboss.org rhmessaging-commits at lists.jboss.org
Thu Mar 20 18:08:43 EDT 2008


Author: justi9
Date: 2008-03-20 18:08:42 -0400 (Thu, 20 Mar 2008)
New Revision: 1783

Added:
   mgmt/cumin-test-0/log/
Modified:
   mgmt/Makefile
   mgmt/cumin/bin/cumin
   mgmt/cumin/bin/cumin-bench
   mgmt/cumin/bin/cumin-test
   mgmt/cumin/python/cumin/__init__.py
   mgmt/cumin/python/cumin/charts.py
   mgmt/cumin/python/cumin/queue.py
   mgmt/cumin/python/cumin/util.py
   mgmt/cumin/python/cumin/widgets.py
   mgmt/cumin/python/wooly/widgets.py
   mgmt/mint/python/mint/__init__.py
Log:
bz435984 - Removes prints and uses instead the python logging facility
to log messages to the console (in debug mode) as well as to a file.
The file log location is controlled by --log option.

Consolidates command line configuration into the CuminConfig class.

Fixes a bug with Config where boolean parameters annoyingly always
required an explicit true value.



Modified: mgmt/Makefile
===================================================================
--- mgmt/Makefile	2008-03-19 18:26:52 UTC (rev 1782)
+++ mgmt/Makefile	2008-03-20 22:08:42 UTC (rev 1783)
@@ -12,6 +12,7 @@
 	mkdir -p dist/etc
 	mkdir -p dist/sql
 	mkdir -p dist/doc
+	mkdir -p dist/log
 	cp -a mint/python/mint/* dist/lib/python/mint
 	cp -a mint/sql/* dist/sql
 	cp -a cumin/python/wooly/* dist/lib/python/wooly

Modified: mgmt/cumin/bin/cumin
===================================================================
--- mgmt/cumin/bin/cumin	2008-03-19 18:26:52 UTC (rev 1782)
+++ mgmt/cumin/bin/cumin	2008-03-20 22:08:42 UTC (rev 1783)
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 
-import sys, os, socket
+import sys, os, socket, logging
 
 from cumin import *
 from cumin.util import *
@@ -9,8 +9,9 @@
     print """Usage: cumin OPTIONS...
 Options:
     -h, --help            Print this message
-    --data URL            Connect to database at URL
+    --data URI            Connect to database at URI
                           (default postgesql://cumin@localhost/cumin)
+    --spec PATH           Use AMQP spec file at PATH
     --addr ADDR           Run web server at address ADDR (default localhost)
     --port PORT           Run web server on port PORT (default 8080)
     --ssl yes             Serve pages using SSL (default no)
@@ -20,6 +21,7 @@
 
 def do_main(home, data, spec, addr, port, ssl, debug):
     app = Cumin(home, data, spec)
+    log = logging.getLogger("cumin.config")
 
     if debug:
         app.enable_debug()
@@ -43,15 +45,13 @@
         if os.path.isfile(cpath):
             server.set_ssl_cert_path(cpath)
         else:
-            print "Error: SSL certificate file '%s' not found" % cpath
-            print "Files '%s' and '%s' are required for SSL" % (cpath, kpath)
+            log.error("SSL certificate file '%s' not found" % cpath)
             sys.exit(1)
 
         if os.path.isfile(kpath):
             server.set_ssl_key_path(kpath)
         else:
-            print "Error: SSL key file '%s' not found" % kpath
-            print "Files '%s' and '%s' are required for SSL" % (cpath, kpath)
+            log.error("SSL key file '%s' not found" % kpath)
             sys.exit(1)
 
     try:
@@ -64,33 +64,23 @@
     if "-h" in sys.argv or "--help" in sys.argv:
         usage()
 
-    home = os.environ.get("CUMIN_HOME", os.path.normpath("/usr/share/cumin"))
-    spec = os.environ.get("AMQP_SPEC",
-                   os.path.normpath("/usr/share/amqp/amqp.0-10-preview.xml"))
-
-    config = Config()
-    config.add_param("home", "s", home)
-    config.add_param("data", "s", "postgresql://cumin@localhost/cumin")
-    config.add_param("spec", "s", spec)
+    config = CuminConfig()
     config.add_param("addr", "s", "localhost")
     config.add_param("port", "i", 8080)
     config.add_param("ssl", "b", False)
-    config.add_param("debug", "b", False)
+    config.init()
 
-    config.load_file(os.path.join(home, "etc", "cumin.conf"))
-    config.load_file(os.path.join(os.path.expanduser("~"), ".cumin.conf"))
-    config.load_args(sys.argv)
-
-    config.prt()
-
-    home = config.get("home")
+    home = config.home
     data = config.get("data")
     spec = config.get("spec")
     addr = config.get("addr")
     port = config.get("port")
     ssl = config.get("ssl")
     debug = config.get("debug")
-    
+
+    if debug:
+        config.prt()
+
     do_main(home, data, spec, addr, port, ssl, debug)
 
 if __name__ == "__main__":

Modified: mgmt/cumin/bin/cumin-bench
===================================================================
--- mgmt/cumin/bin/cumin-bench	2008-03-19 18:26:52 UTC (rev 1782)
+++ mgmt/cumin/bin/cumin-bench	2008-03-20 22:08:42 UTC (rev 1783)
@@ -44,24 +44,15 @@
     if "-h" in sys.argv or "--help" in sys.argv:
         usage()
 
-    home = os.environ.get("CUMIN_HOME", os.path.normpath("/usr/share/cumin"))
-    spec = os.environ.get("AMQP_SPEC",
-                   os.path.normpath("/usr/share/amqp/amqp.0-10-preview.xml"))
-
-    config = Config()
-    config.add_param("home", "s", home)
-    config.add_param("data", "s", "postgresql://cumin@localhost/cumin")
-    config.add_param("spec", "s", spec)
+    config = CuminConfig()
     config.add_param("hits", "i", 1000)
     config.add_param("profile", "b", False)
+    config.init()
 
-    config.load_file(os.path.join(home, "etc", "cumin.conf"))
-    config.load_file(os.path.join(os.path.expanduser("~"), ".cumin.conf"))
-    config.load_args(sys.argv)
+    if config.get("debug"):
+        config.prt()
 
-    config.prt()
-
-    home = config.get("home")
+    home = config.home
     data = config.get("data")
     spec = config.get("spec")
     hits = config.get("hits")

Modified: mgmt/cumin/bin/cumin-test
===================================================================
--- mgmt/cumin/bin/cumin-test	2008-03-19 18:26:52 UTC (rev 1782)
+++ mgmt/cumin/bin/cumin-test	2008-03-20 22:08:42 UTC (rev 1783)
@@ -12,14 +12,13 @@
     print """Usage: cumin-test OPTIONS...
 Options:
     -h, --help            Print this message
-    --home PATH           Use home directory at PATH
     --data URI            Connect to database at URI
                           (default postgesql://cumin@localhost/cumin)
     --spec PATH           Use AMQP spec file at PATH
     --broker ADDRESS      Register new test broker at ADDRESS
                           (default localhost:5672)
-    --profile
-    --debug"""
+    --profile yes         Enable profiling
+    --debug yes           Enable debugging"""
     sys.exit(1)
 
 def do_main(home, data, spec, broker_host, broker_port, debug):
@@ -48,26 +47,15 @@
     if "-h" in sys.argv or "--help" in sys.argv:
         usage()
 
-    home = os.environ.get("CUMIN_HOME", os.path.normpath("/usr/share/cumin"))
-    spec = os.environ.get("AMQP_SPEC",
-                   os.path.normpath("/usr/share/amqp/amqp.0-10-preview.xml"))
-
-    config = Config()
-    
-    config.add_param("home", "s", home)
-    config.add_param("data", "s", "postgresql://cumin@localhost/cumin")
-    config.add_param("spec", "s", spec)
+    config = CuminConfig()
     config.add_param("broker", "s", "localhost:5672")
-    config.add_param("debug", "b", True)
     config.add_param("profile", "b", False)
+    config.init()
 
-    config.load_file(os.path.join(home, "etc", "cumin.conf"))
-    config.load_file(os.path.join(os.path.expanduser("~"), ".cumin.conf"))
-    config.load_args(sys.argv)
+    if config.get("debug"):
+        config.prt()
 
-    config.prt()
-
-    home = config.get("home")
+    home = config.home
     data = config.get("data")
     spec = config.get("spec")
     broker = config.get("broker")

Modified: mgmt/cumin/python/cumin/__init__.py
===================================================================
--- mgmt/cumin/python/cumin/__init__.py	2008-03-19 18:26:52 UTC (rev 1782)
+++ mgmt/cumin/python/cumin/__init__.py	2008-03-20 22:08:42 UTC (rev 1783)
@@ -1,4 +1,4 @@
-import sys, os
+import sys, os, logging
 
 from random import randint
 from wooly import Application, Session, Page
@@ -18,6 +18,7 @@
 from page import CuminPage
 from stat import StatChartPage
 from action import ActionPage
+from util import Config
 
 class Cumin(Application):
     def __init__(self, home, data_uri, spec_path):
@@ -54,6 +55,8 @@
         self.broker_connect_thread.start()
 
 class BrokerConnectThread(Thread):
+    log = logging.getLogger("cumin.mgmt.conn")
+
     def __init__(self, model):
         super(BrokerConnectThread, self).__init__()
 
@@ -124,3 +127,52 @@
             user.syncUpdate()
 
         return False
+
+class CuminConfig(Config):
+    def __init__(self):
+        super(CuminConfig, self).__init__()
+
+        hdef = os.path.normpath("/usr/share/cumin")
+        self.home = os.environ.get("CUMIN_HOME", hdef)
+
+        if not os.path.isdir(self.home):
+            raise Exception("Home path '%s' is not a directory")
+
+        sdef = os.path.normpath("/usr/share/amqp/amqp.0-10-preview.xml")
+        spec = os.environ.get("AMQP_SPEC", sdef)
+
+        self.add_param("debug", "b", False)
+        self.add_param("data", "s", "postgresql://cumin@localhost/cumin")
+        self.add_param("spec", "s", spec)
+        self.add_param("log", "s", os.path.join(self.home, "log", "cumin.log"))
+
+    def init(self):
+        root = logging.getLogger()
+        root.setLevel(logging.NOTSET)
+
+        self.load_args(sys.argv)
+
+        h = self.get_console_handler()
+        root.addHandler(h)
+        self.load_file(os.path.join(self.home, "etc", "cumin.conf"))
+        self.load_file(os.path.join(os.path.expanduser("~"), ".cumin.conf"))
+        self.load_args(sys.argv)
+        root.removeHandler(h)
+
+        h = self.get_console_handler()
+        root.addHandler(h)
+
+        h = logging.FileHandler(self.get("log"))
+        if self.get("debug"):
+            h.setLevel(logging.DEBUG)
+        else:
+            h.setLevel(logging.INFO)
+        root.addHandler(h)
+
+    def get_console_handler(self):
+        h = logging.StreamHandler()
+        if self.get("debug"):
+            h.setLevel(logging.DEBUG)
+        else:
+            h.setLevel(logging.ERROR)
+        return h

Modified: mgmt/cumin/python/cumin/charts.py
===================================================================
--- mgmt/cumin/python/cumin/charts.py	2008-03-19 18:26:52 UTC (rev 1782)
+++ mgmt/cumin/python/cumin/charts.py	2008-03-20 22:08:42 UTC (rev 1783)
@@ -1,3 +1,5 @@
+import logging
+
 from cairo import *
 from random import random
 from time import time
@@ -5,6 +7,8 @@
 from formats import *
 from util import *
 
+log = logging.getLogger("cumin.chart")
+
 class LineChart(object):
     def __init__(self, width, height):
         self.width = width
@@ -25,7 +29,7 @@
 
         for dt, value in samples:
             if value is None:
-                print "Warning: unexpected null value" #XXX
+                log.warn("Unexpected null value") # XXX
                 value = 0
 
             t = secs(dt)

Modified: mgmt/cumin/python/cumin/queue.py
===================================================================
--- mgmt/cumin/python/cumin/queue.py	2008-03-19 18:26:52 UTC (rev 1782)
+++ mgmt/cumin/python/cumin/queue.py	2008-03-20 22:08:42 UTC (rev 1783)
@@ -1,4 +1,4 @@
-import pdb
+import pdb, logging
 
 from mint import *
 from wooly import *
@@ -17,6 +17,7 @@
 from util import *
 
 strings = StringCatalog(__file__)
+log = logging.getLogger("cumin.queue")
 
 class QueueSet(CuminTable, Form):
     def __init__(self, app, name):
@@ -331,7 +332,7 @@
             name = self.namef.get(session)
             durable = self.durable.get(session)
 
-            print "XXX add queue", name, self.durable.get(session)
+            log.info("Adding queue '%s'" % name)
             
             self.process_cancel(session)
 
@@ -446,7 +447,7 @@
         self.page().set_redirect_url(session, branch.marshal())
     
     def process_submit(self, session, binding):
-        print "processing", binding
+        log.info("Removing binding %s" % binding)
         
         self.process_cancel(session, binding)
 

Modified: mgmt/cumin/python/cumin/util.py
===================================================================
--- mgmt/cumin/python/cumin/util.py	2008-03-19 18:26:52 UTC (rev 1782)
+++ mgmt/cumin/python/cumin/util.py	2008-03-20 22:08:42 UTC (rev 1783)
@@ -1,5 +1,6 @@
 from time import mktime
 from ConfigParser import SafeConfigParser
+from logging import getLogger
 
 def sorted_by(seq, attr="name"):
     return sorted(seq, cmp, lambda x: getattr(x, attr))
@@ -38,13 +39,13 @@
         self.id = id
 
 class Config(object):
+    log = getLogger("cumin.config")
+
     def __init__(self):
         self.__params = list()
         self.__param_specs = dict() # param name => (type, default)
         self.__values = dict()
 
-        self.verbose = True
-
     def add_param(self, name, type, default):
         self.__params.append(name)
         self.__param_specs[name] = (type, default)
@@ -59,7 +60,8 @@
         if type == "i":
             value = int(string)
         elif type == "b":
-            value = bool(string)
+            value = string is None or \
+                string.lower() in ("y", "yes", "t", "true", "1")
         elif type == "s":
             value = string
         else:
@@ -81,15 +83,13 @@
         return value
 
     def load_file(self, file):
-        print "Looking for config file '%s':" % file,
-
         conf = SafeConfigParser()
         found = conf.read(file)
 
         if found:
-            print "found"
+            self.log.info("Found config file '%s' and read it" % file)
         else:
-            print "not found"
+            self.log.info("Config file '%s' not found" % file)
 
         params = dict()
 
@@ -118,7 +118,7 @@
             if name in self.__params:
                 self.set(name, self.unmarshal(name, value))
             else:
-                print "Warning: ignoring unrecognized parameter '%s'" % name
+                self.log.info("Ignoring unrecognized parameter '%s'" % name)
 
     def require(self, params):
         missing = list()

Modified: mgmt/cumin/python/cumin/widgets.py
===================================================================
--- mgmt/cumin/python/cumin/widgets.py	2008-03-19 18:26:52 UTC (rev 1782)
+++ mgmt/cumin/python/cumin/widgets.py	2008-03-20 22:08:42 UTC (rev 1783)
@@ -193,7 +193,7 @@
         self.process_return(session, *args)
 
     def process_item(self, session, item):
-        print "processing item", item
+        pass
 
     def process_return(self, session, *args):
         pass

Modified: mgmt/cumin/python/wooly/widgets.py
===================================================================
--- mgmt/cumin/python/wooly/widgets.py	2008-03-19 18:26:52 UTC (rev 1782)
+++ mgmt/cumin/python/wooly/widgets.py	2008-03-20 22:08:42 UTC (rev 1783)
@@ -103,8 +103,6 @@
 
 class Link(Widget):
     def render_class(self, session, *args):
-        print "args", self.get_args(session)
-
         return self.html_class
 
     def edit_session(self, session, *args):

Modified: mgmt/mint/python/mint/__init__.py
===================================================================
--- mgmt/mint/python/mint/__init__.py	2008-03-19 18:26:52 UTC (rev 1782)
+++ mgmt/mint/python/mint/__init__.py	2008-03-20 22:08:42 UTC (rev 1783)
@@ -1,4 +1,4 @@
-import os, socket, qpid
+import os, socket, qpid, logging
 from qpid.management import managementChannel, managementClient
 from datetime import *
 from sqlobject import *
@@ -7,6 +7,8 @@
 
 from mint import schema
 
+log = logging.getLogger("mint")
+
 this_module = __import__(__name__)
 
 for item in dir(schema):
@@ -36,16 +38,16 @@
   profile = ForeignKey("BrokerProfile", cascade="null", default=None)
 
   def connect(self, model):
-    print "Connecting to broker '%s' at %s:%i" % \
-        (self.name, self.host, self.port or 5672)
+    log.info("Connecting to broker '%s' at %s:%i" % \
+               (self.name, self.host, self.port or 5672))
 
     conn = BrokerConnection(model, self.host, self.port or 5672)
 
     try:
       conn.open()
-      print "Connection succeeded"
+      log.info("Connection succeeded")
     except:
-      print "Connection failed: " + str(conn.exception)
+      log.info("Connection failed: " + str(conn.exception))
       print_exc()
 
   def getDefaultVhost(self):
@@ -143,7 +145,7 @@
 
       for reg in regs:
         if reg not in existing:
-          print "Attaching broker to reg", reg
+          log.info("Attaching broker to reg %s" % reg)
 
           reg.broker = obj
           obj.syncUpdate()




More information about the rhmessaging-commits mailing list