gump-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From leosim...@apache.org
Subject svn commit: r156966 - in gump/branches/Gump3/pygump/python/gump: config.py engine/__init__.py engine/modeller.py test/testDynagumper.py test/testEngine.py test/testUtilIO.py util/io.py util/mysql.py util/sysinfo.py
Date Thu, 10 Mar 2005 17:26:36 GMT
Author: leosimons
Date: Thu Mar 10 09:26:30 2005
New Revision: 156966

URL: http://svn.apache.org/viewcvs?view=rev&rev=156966
Log:

* clean up some bits of code

* add documentation to some functions and classes

* start testing the engine

* fix a few bugs in the engine

* change behaviour of io code to make more sense

* several other small changes

Added:
    gump/branches/Gump3/pygump/python/gump/test/testEngine.py
      - copied, changed from r156957, gump/branches/Gump3/pygump/python/gump/test/testMain.py
Modified:
    gump/branches/Gump3/pygump/python/gump/config.py
    gump/branches/Gump3/pygump/python/gump/engine/__init__.py
    gump/branches/Gump3/pygump/python/gump/engine/modeller.py
    gump/branches/Gump3/pygump/python/gump/test/testDynagumper.py
    gump/branches/Gump3/pygump/python/gump/test/testUtilIO.py
    gump/branches/Gump3/pygump/python/gump/util/io.py
    gump/branches/Gump3/pygump/python/gump/util/mysql.py
    gump/branches/Gump3/pygump/python/gump/util/sysinfo.py

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=156965&r2=156966
==============================================================================
--- gump/branches/Gump3/pygump/python/gump/config.py (original)
+++ gump/branches/Gump3/pygump/python/gump/config.py Thu Mar 10 09:26:30 2005
@@ -176,11 +176,11 @@
         raise AttributeError, name
 
 
-def get_logger(level, name):
+def get_logger(config, name):
     """Provide a logging implementation for the given level and name."""
     logging.basicConfig()
     log = logging.getLogger(name)
-    log.setLevel(level)
+    log.setLevel(config.log_level)
     return log
 
 
@@ -196,10 +196,16 @@
     return db
 
 
-def get_vfs(filesystem_root, cache_dir):
+_VFS_CACHE_DIR_NAME="vfs-cache"
+
+def get_vfs(config):
     """Provide a VFS implementation."""
     from gump.util.io import VFS
-    return VFS(filesystem_root, cache_dir)
+
+    cache_dir = os.path.join(config.paths_work, _VFS_CACHE_DIR_NAME)
+    if not os.path.isdir(cache_dir):
+        os.mkdir(cache_dir);
+    return VFS(config.paths_metadata, cache_dir)
 
 
 def get_modeller_loader(log, vfs=None, mergefile=None, dropfile=None):
@@ -232,6 +238,13 @@
     
     log = get_logger(config.log_level, "walker")
     return Walker(log)
+
+
+def get_dom_implementation():
+    """Provide a DOM implementation."""
+    from xml import dom
+    impl = dom.getDOMImplementation()
+    return impl
 
 
 def get_plugin(config):

Modified: gump/branches/Gump3/pygump/python/gump/engine/__init__.py
URL: http://svn.apache.org/viewcvs/gump/branches/Gump3/pygump/python/gump/engine/__init__.py?view=diff&r1=156965&r2=156966
==============================================================================
--- gump/branches/Gump3/pygump/python/gump/engine/__init__.py (original)
+++ gump/branches/Gump3/pygump/python/gump/engine/__init__.py Thu Mar 10 09:26:30 2005
@@ -46,6 +46,11 @@
 from gump.config import *
 from gump.util.io import open_file_or_stream
 
+_ENGINE_LOGGER_NAME = "engine"
+_MODELLER_LOGGER_NAME = "modeller"
+_MERGE_FILE_NAME = "merge.xml"
+_DROPPED_FILE_NAME = "dropped.xml"
+
 def main(settings):
     """Controls the big pygump beast.
 
@@ -59,8 +64,18 @@
     Arguments:
       - settings -- everything the engine needs to know about the environment.
     """
-    #TODO: normalize this so that main() isn't responsible for feeding specific
-    # arguments into the _get_xxx() methods. Its annoying.
+    # For those familiar with "inversion of control" containers; this is
+    # method is basically the "container". Since we're not doing any kind
+    # of "autowiring", this method and the config file must work together
+    # to get all the components wired up properly. However, that wiring
+    # responsibility really is isolated right there. If neccessary we can
+    # introduce some magic if we need to, but I do like that it is so very
+    # visible what is going on here.
+    #
+    # The downside is that config.py and this method are very hard to unit
+    # tests, since it all interacts in an ugly fashion. Oh well, this code
+    # gets exercised more than enough on any integration test since there
+    # is no if/else branching of any kind, no looping, etc.
     
     # ooh...ah...fancy :-D
     _banner(settings.version)
@@ -69,28 +84,26 @@
     config = get_config(settings)
     
     # get engine dependencies
-    log = get_logger(config.log_level, "engine")
-    
-    vfsdir = os.path.join(config.paths_work, "vfs-cache")
-    if not os.path.isdir(vfsdir):
-        os.mkdir(vfsdir);
-    vfs = get_vfs(config.paths_metadata, vfsdir)
+    log = get_logger(config, _ENGINE_LOGGER_NAME)
     
-    modeller_log = get_logger(config.log_level, "modeller")
+    vfsdir = os.path.join(config)
+    modeller_log = get_logger(config, _MODELLER_LOGGER_NAME)
     modeller_loader = get_modeller_loader(modeller_log, vfs)
     modeller_normalizer = get_modeller_normalizer(modeller_log)
     modeller_objectifier = get_modeller_objectifier(modeller_log)
     modeller_verifier = get_modeller_verifier()
     
-    mergefile = os.path.join(config.paths_work, "merge.xml")
-    dropfile = os.path.join(config.paths_work, "dropped.xml")
+    mergefile = os.path.join(config.paths_work, _MERGE_FILE_NAME)
+    dropfile = os.path.join(config.paths_work, _DROPPED_FILE_NAME)
     
     walker = get_walker(config)
+    dom_implementation = get_dom_implementation()
     (pre_process_visitor, visitor, post_process_visitor) = get_plugin(config)
     
     # create engine
     engine = _Engine(log, modeller_loader, modeller_normalizer,
                      modeller_objectifier, modeller_verifier, walker,
+                     dom_implementation,
                      pre_process_visitor, visitor, post_process_visitor,
                      config.paths_workspace, mergefile, dropfile)
     
@@ -110,15 +123,15 @@
     print
     print
 
-###
-### FACTORY METHODS
-###
 
 class _Engine:
-    """This is the core of the core of the pygump application."""
+    """This is the core of the core of the pygump application. It interacts
+    with the other parts of the gump.engine package to transform the model
+    xml into an object model and let loose plugins on that model."""
     
     def __init__(self, log, workspace_loader, workspace_normalizer,
                  workspace_objectifier, workspace_verifier, walker,
+                 dom_implementation,
                  pre_process_visitor, visitor, post_process_visitor,
                  workspace, merge_to=None, drop_to=None):
         """Store all config and dependencies as properties.
@@ -143,17 +156,36 @@
             - post_process_visitor -- the component that gets called by the
                 walker while visiting parts of the model during the
                 pre-processing stage
+            - dom_implementation -- a python dom implementation (for example
+                the one returned by xml.dom.getDOMImplementation())
 
             - workspace -- the resource containing the workspace xml.
             - merge_to -- the resource to write the merged workspace xml to.
             - drop_to -- the resource to write the dropped projects xml to.
         """
+        assert hasattr(log, "exception")
+        assert callable(log.exception)
+        assert hasattr(workspace_loader, "get_workspace_tree")
+        assert callable(workspace_loader.get_workspace_tree)
+        assert hasattr(workspace_normalizer, "normalize")
+        assert callable(workspace_normalizer.normalize)
+        assert hasattr(workspace_objectifier, "get_workspace")
+        assert callable(workspace_objectifier.get_workspace)
+        assert hasattr(workspace_verifier, "verify")
+        assert callable(workspace_verifier.verify)
+        assert hasattr(walker, "walk")
+        assert callable(walker.walk)
+        assert hasattr(dom_implementation, "createDocument")
+        assert callable(dom_implementation.createDocument)
+        assert workspace != None
+        
         self.log = log
         self.workspace_loader = workspace_loader
         self.workspace_normalizer = workspace_normalizer
         self.workspace_objectifier = workspace_objectifier
         self.workspace_verifier = workspace_verifier
         self.walker = walker
+        self.dom_implementation = dom_implementation
 
         self.pre_process_visitor = pre_process_visitor
         self.visitor = visitor
@@ -164,7 +196,8 @@
         self.drop_to = open_file_or_stream(drop_to,'w')
 
     def run(self):
-        """Perform a run."""
+        """Perform a gump run. What actually goes on during a gump run is
+        largely determined by the components we're using."""
         try:
             # * merge workspace into big DOM tree
             (domtree, dropped_nodes) = self.workspace_loader.get_workspace_tree(self.workspace)
@@ -185,7 +218,7 @@
                 
             # * verify that our model is correct (for example, that it has
             #   no circular dependencies)
-            self.workspace_verifier.verify(domtree)
+            self.workspace_verifier.verify(workspace)
             
             # * Pfew! All done. Now actually start *doing* stuff.
             self.walker.walk(workspace, self.pre_process_visitor)
@@ -208,9 +241,7 @@
             self.merge_to.close()
         
         if self.drop_to and len(dropped_nodes) > 0:
-            from xml import dom
-            impl = dom.getDOMImplementation()
-            dropdoc = impl.createDocument(None, "dropped-projects-and-modules", None)
+            dropdoc = self.dom_implementation.createDocument(None, "dropped-projects-and-modules",
None)
             dropdocroot = dropdoc.documentElement
             for node in dropped_nodes:
                 dropdocroot.appendChild(node)

Modified: gump/branches/Gump3/pygump/python/gump/engine/modeller.py
URL: http://svn.apache.org/viewcvs/gump/branches/Gump3/pygump/python/gump/engine/modeller.py?view=diff&r1=156965&r2=156966
==============================================================================
--- gump/branches/Gump3/pygump/python/gump/engine/modeller.py (original)
+++ gump/branches/Gump3/pygump/python/gump/engine/modeller.py Thu Mar 10 09:26:30 2005
@@ -978,5 +978,5 @@
 
 
 class Verifier:
-    def verify(self, domtree):
+    def verify(self, workspace):
         pass # TODO!

Modified: gump/branches/Gump3/pygump/python/gump/test/testDynagumper.py
URL: http://svn.apache.org/viewcvs/gump/branches/Gump3/pygump/python/gump/test/testDynagumper.py?view=diff&r1=156965&r2=156966
==============================================================================
--- gump/branches/Gump3/pygump/python/gump/test/testDynagumper.py (original)
+++ gump/branches/Gump3/pygump/python/gump/test/testDynagumper.py Thu Mar 10 09:26:30 2005
@@ -18,14 +18,13 @@
 __license__   = "http://www.apache.org/licenses/LICENSE-2.0"
 
 import unittest
-import pmock
 from pmock import *
 
 from gump.plugins.dynagumper import Dynagumper
 
 from main import _Logger
 
-class DynagumperTestCase(pmock.MockTestCase):
+class DynagumperTestCase(MockTestCase):
     def setUp(self):
         self.log = self.mock()
         self.log.stubs().method("debug")

Copied: gump/branches/Gump3/pygump/python/gump/test/testEngine.py (from r156957, gump/branches/Gump3/pygump/python/gump/test/testMain.py)
URL: http://svn.apache.org/viewcvs/gump/branches/Gump3/pygump/python/gump/test/testEngine.py?view=diff&rev=156966&p1=gump/branches/Gump3/pygump/python/gump/test/testMain.py&r1=156957&p2=gump/branches/Gump3/pygump/python/gump/test/testEngine.py&r2=156966
==============================================================================
--- gump/branches/Gump3/pygump/python/gump/test/testMain.py (original)
+++ gump/branches/Gump3/pygump/python/gump/test/testEngine.py Thu Mar 10 09:26:30 2005
@@ -18,7 +18,7 @@
 __license__   = "http://www.apache.org/licenses/LICENSE-2.0"
 
 """
-    This package tests some aspects of the main module. Note this is
+    This package tests some aspects of the gump.engine module. Note this is
     not an integration test, but a real unit test. Please keep it that
     way :-D
 """
@@ -26,76 +26,245 @@
 import unittest
 from unittest import TestCase
 
-import os
+from pmock import *
+
 import StringIO
 
-from main import print_help
-from main import _Logger
-from main import DEBUG
-from main import CRITICAL
-from main import _check_version
-
-class MainTestCase(TestCase):
-    def test_print_help(self):
-        file = StringIO.StringIO("")
-        print_help(file)
-        result = file.getvalue()
-        file.close()
-        self.assert_(len(result) > 100) # for want of a better idea...
-
-    def test_logger(self):
-        try:
-            l = _Logger("gump-maintestcase-logdir-tmp", CRITICAL-1, CRITICAL-1)
-            l.debug("blah")
-            l.log(DEBUG,"blahblah")
-            l.info("blahblahblah")
-            l.warning("blahblahblahblah")
-            l.error("ehm")
-            try:
-                raise Exception
-            except:
-                l.exception("ehmehm")
-            l.critical("whoops!")
-            l.close()
-        finally:
-            try:
-                os.remove(l.filename)
-            except:
-                pass
-            try:
-                os.rmdir(l.logdir)
-            except:
-                pass
-    
-    def test_check_version(self):
-        try:
-            _check_version()
-        except:
-            pass
-    
-    # TODO: refactor the main module to make it easier testable!
-    
-    # don't test _parse_workspace since that should be removed anyway
-    
-    # don't test _svn_update since that should be removed as well and
-    # handled elsewhere
-    
-    # don't test _send_email because that would entail actually sending
-    # e-mail, which is way more trouble than its worth to test
-    
-    # dont't test send_error_email because that would entail actually
-    # sending e-mail, which is way more trouble than its worth to test
-    
-    # don't test _start_engine because that would basically be running
-    # an integration test
-    
-    # don't test main because that would basically be running
-    # an integration test
+from gump.engine import _Engine
 
+class EngineTestCase(MockTestCase):
+    def setUp(self):
+        self.log = self.mock()
+        self.log.stubs().method("debug")
+        self.log.stubs().method("info")
+        self.log.stubs().method("warning")
+        self.log.stubs().method("error")
+        self.log.stubs().method("critical")
+        self.log.stubs().method("log")
+        self.log.stubs().method("exception")
+        self.log.stubs().method("close")        
+        
+        self.workspace_loader = self.mock()
+        self.workspace_normalizer = self.mock()
+        self.workspace_objectifier = self.mock()
+        self.workspace_verifier = self.mock()
+        self.walker = self.mock()
+        self.dom_implementation = self.mock()
+        self.pre_process_visitor = self.mock()
+        self.visitor = self.mock()
+        self.post_process_visitor = self.mock()
+        self.workspace = self.mock()
+        self.merge_to = StringIO.StringIO()
+        self.drop_to = StringIO.StringIO()
+    
+    def test_constructor(self):
+        e = _Engine(self.log,
+                    self.workspace_loader,
+                    self.workspace_normalizer,
+                    self.workspace_objectifier,
+                    self.workspace_verifier,
+                    self.walker,
+                    self.dom_implementation,
+                    self.pre_process_visitor,
+                    self.visitor,
+                    self.post_process_visitor,
+                    self.workspace,
+                    self.merge_to,
+                    self.drop_to)
+        self.assertRaises(AssertionError,_Engine,
+                    "blah",
+                    self.workspace_loader,
+                    self.workspace_normalizer,
+                    self.workspace_objectifier,
+                    self.workspace_verifier,
+                    self.walker,
+                    self.dom_implementation,
+                    self.pre_process_visitor,
+                    self.visitor,
+                    self.post_process_visitor,
+                    self.workspace,
+                    self.merge_to,
+                    self.drop_to)
+        self.assertRaises(AssertionError,_Engine,
+                    self.log,
+                    "blah",
+                    self.workspace_normalizer,
+                    self.workspace_objectifier,
+                    self.workspace_verifier,
+                    self.walker,
+                    self.dom_implementation,
+                    self.pre_process_visitor,
+                    self.visitor,
+                    self.post_process_visitor,
+                    self.workspace,
+                    self.merge_to,
+                    self.drop_to)
+        self.assertRaises(AssertionError,_Engine,
+                    self.log,
+                    self.workspace_loader,
+                    "blah",
+                    self.workspace_objectifier,
+                    self.workspace_verifier,
+                    self.walker,
+                    self.dom_implementation,
+                    self.pre_process_visitor,
+                    self.visitor,
+                    self.post_process_visitor,
+                    self.workspace,
+                    self.merge_to,
+                    self.drop_to)
+        self.assertRaises(AssertionError,_Engine,
+                    self.log,
+                    self.workspace_loader,
+                    self.workspace_normalizer,
+                    "blah",
+                    self.workspace_verifier,
+                    self.walker,
+                    self.dom_implementation,
+                    self.pre_process_visitor,
+                    self.visitor,
+                    self.post_process_visitor,
+                    self.workspace,
+                    self.merge_to,
+                    self.drop_to)
+        self.assertRaises(AssertionError,_Engine,
+                    self.log,
+                    self.workspace_loader,
+                    self.workspace_normalizer,
+                    self.workspace_objectifier,
+                    "blah",
+                    self.walker,
+                    self.dom_implementation,
+                    self.pre_process_visitor,
+                    self.visitor,
+                    self.post_process_visitor,
+                    self.workspace,
+                    self.merge_to,
+                    self.drop_to)
+        self.assertRaises(AssertionError,_Engine,
+                    self.log,
+                    self.workspace_loader,
+                    self.workspace_normalizer,
+                    self.workspace_objectifier,
+                    self.workspace_verifier,
+                    "blah",
+                    self.dom_implementation,
+                    self.pre_process_visitor,
+                    self.visitor,
+                    self.post_process_visitor,
+                    self.workspace,
+                    self.merge_to,
+                    self.drop_to)
+        self.assertRaises(AssertionError,_Engine,
+                    self.log,
+                    self.workspace_loader,
+                    self.workspace_normalizer,
+                    self.workspace_objectifier,
+                    self.workspace_verifier,
+                    self.walker,
+                    "blah",
+                    self.pre_process_visitor,
+                    self.visitor,
+                    self.post_process_visitor,
+                    self.workspace,
+                    self.merge_to,
+                    self.drop_to)
+        self.assertRaises(AssertionError,_Engine,
+                    self.log,
+                    self.workspace_loader,
+                    self.workspace_normalizer,
+                    self.workspace_objectifier,
+                    self.workspace_verifier,
+                    self.walker,
+                    self.dom_implementation,
+                    self.pre_process_visitor,
+                    self.visitor,
+                    self.post_process_visitor,
+                    None,
+                    self.merge_to,
+                    self.drop_to)
+        e = _Engine(
+                    self.log,
+                    self.workspace_loader,
+                    self.workspace_normalizer,
+                    self.workspace_objectifier,
+                    self.workspace_verifier,
+                    self.walker,
+                    self.dom_implementation,
+                    self.pre_process_visitor,
+                    self.visitor,
+                    self.post_process_visitor,
+                    self.workspace,
+                    None,
+                    self.drop_to)
+        e = _Engine(
+                    self.log,
+                    self.workspace_loader,
+                    self.workspace_normalizer,
+                    self.workspace_objectifier,
+                    self.workspace_verifier,
+                    self.walker,
+                    self.dom_implementation,
+                    self.pre_process_visitor,
+                    self.visitor,
+                    self.post_process_visitor,
+                    self.workspace,
+                    self.merge_to,
+                    None)
+    
+    def test_run(self):
+        domtree = self.mock()
+        domtree.expects(once()).unlink()
+        dropped = []
+        passaroundobj = (domtree,dropped)
+        ws = StringIO.StringIO("won't get read anyway")
+        objectws = "Blah"
+        self.workspace_loader.expects(once()).get_workspace_tree(same(ws)).will(return_value(passaroundobj))
+        self.workspace_normalizer.expects(once()).normalize(same(domtree)).will(return_value(domtree))
+        self.workspace_objectifier.expects(once()).get_workspace(same(domtree)).will(return_value(objectws))
+        self.workspace_verifier.expects(once()).verify(same(objectws))
+        self.walker.expects(once()).walk(same(objectws),same(self.pre_process_visitor))
+        self.walker.expects(once()).walk(same(objectws),same(self.visitor))
+        self.walker.expects(once()).walk(same(objectws),same(self.post_process_visitor))
+        e = _Engine(
+                    MockLog(),
+                    self.workspace_loader,
+                    self.workspace_normalizer,
+                    self.workspace_objectifier,
+                    MockVerifier(objectws, self),
+                    self.walker,
+                    self.dom_implementation,
+                    self.pre_process_visitor,
+                    self.visitor,
+                    self.post_process_visitor,
+                    ws,
+                    None,
+                    None)
+        e.run()
+        
+        # TODO test exceptions
+        
+        # TODO test writing merge xml files
+
+
+class MockLog:
+    def exception(self,msg):
+        raise
+
+
+class MockVerifier:
+    def __init__(self,expected, testcase):
+        self.expected = expected
+        self.testcase = testcase
+        
+    def verify(self,argument):
+        TestCase.failUnlessEqual(self.testcase, self.expected, argument)
+        
+        
 # this is used by testrunner.py to determine what tests to run
 def test_suite():
     # be sure to change the referenceto the TestCase class you create above!
-    return unittest.makeSuite(MainTestCase,'test')
+    return unittest.makeSuite(EngineTestCase,'test')
 
 # this allows us to run this test by itself from the commandline
 if __name__ == '__main__':

Modified: gump/branches/Gump3/pygump/python/gump/test/testUtilIO.py
URL: http://svn.apache.org/viewcvs/gump/branches/Gump3/pygump/python/gump/test/testUtilIO.py?view=diff&r1=156965&r2=156966
==============================================================================
--- gump/branches/Gump3/pygump/python/gump/test/testUtilIO.py (original)
+++ gump/branches/Gump3/pygump/python/gump/test/testUtilIO.py Thu Mar 10 09:26:30 2005
@@ -50,6 +50,15 @@
         result = file.read()
         file.close()
         self.assertEqual(contents, result)
+        
+        file = open_file_or_stream(contents)
+        result = file.read()
+        file.close()
+        self.assertEqual(contents, result)
+
+        result = open_file_or_stream(None)
+        self.assertEqual(None, result)
+        
     
     def test_error(self):
         from gump.util.io import Error

Modified: gump/branches/Gump3/pygump/python/gump/util/io.py
URL: http://svn.apache.org/viewcvs/gump/branches/Gump3/pygump/python/gump/util/io.py?view=diff&r1=156965&r2=156966
==============================================================================
--- gump/branches/Gump3/pygump/python/gump/util/io.py (original)
+++ gump/branches/Gump3/pygump/python/gump/util/io.py Thu Mar 10 09:26:30 2005
@@ -32,6 +32,7 @@
 import StringIO
 import types
 
+# we need to know what kind of instances we can pass to open()
 try:
     _StringTypes = [types.StringType, types.UnicodeType]
 except AttributeError:
@@ -40,17 +41,20 @@
 def open_file_or_stream(file_or_stream, mode='r'):
     """Utility for accepting both filenames and streams.
     
-    If the argument is a string, attempt to use it as a filename,
-    open the specified file and return a reference to the open file. If it is
-    not a valid filename, wrap the string as a stream-like object and return it.
-    
-    If the argument is not a string, returns the string.
+    If the argument is None, returns None. If the argument is a string,
+    attempt to use it as a filename, open the specified file and return
+    a reference to the open file. If it is not a valid filename, return
+    the string wrapped in an IO object. If the argument is not a string,
+    return the argument.
     """
+    if file_or_stream == None:
+        return file_or_stream
+    
     if type(file_or_stream) in _StringTypes:
-        #try:
-        return open(file_or_stream, mode)
-        #except:
-        #    StringIO.StringIO(file_or_stream)
+        try:
+            return open(file_or_stream, mode)
+        except:
+            return StringIO.StringIO(file_or_stream)
     else:
         return file_or_stream
 

Modified: gump/branches/Gump3/pygump/python/gump/util/mysql.py
URL: http://svn.apache.org/viewcvs/gump/branches/Gump3/pygump/python/gump/util/mysql.py?view=diff&r1=156965&r2=156966
==============================================================================
--- gump/branches/Gump3/pygump/python/gump/util/mysql.py (original)
+++ gump/branches/Gump3/pygump/python/gump/util/mysql.py Thu Mar 10 09:26:30 2005
@@ -24,7 +24,7 @@
 class Database:
     """
     Very simple database abstraction layer, basically adding some utilities
-    around MySQLdb and ability to parse the gump DatabaseInformation object.
+    and logging around MySQLdb.
     
     See http://www.python.org/peps/pep-0249.html for more on python and databases.
     This class adheres to the PEP 249 Connection interface.

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=156965&r2=156966
==============================================================================
--- gump/branches/Gump3/pygump/python/gump/util/sysinfo.py (original)
+++ gump/branches/Gump3/pygump/python/gump/util/sysinfo.py Thu Mar 10 09:26:30 2005
@@ -14,7 +14,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-"""This module provides system introspection tools based on all sorts of ugly shell-based
stuff."""
+"""This module provides system introspection tools based on all sorts of ugly
+shell-based stuff."""
 
 __copyright__ = "Copyright (c) 2005 The Apache Software Foundation"
 __license__   = "http://www.apache.org/licenses/LICENSE-2.0"
@@ -22,9 +23,13 @@
 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)
@@ -34,12 +39,21 @@
         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)
@@ -73,6 +87,8 @@
         _safe_rm(serrname)
 
 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)
@@ -82,6 +98,8 @@
     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)
@@ -91,6 +109,8 @@
     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)



Mime
View raw message