Parcourir la source

[2225_statistics] move init() into the Counter class

Naoki Kambe il y a 12 ans
Parent
commit
117645fa11

+ 16 - 15
src/lib/python/isc/statistics/counter.py

@@ -77,21 +77,6 @@ from datetime import datetime
 # container of a counter object
 _COUNTER = None
 
-def init(spec_file_name):
-    """A creator method for a counter class. It creates a counter
-    object by the module name of the given spec file. An argument is a
-    specification file name."""
-    global _COUNTER
-    if isinstance(_COUNTER, _Counter):
-        # already loaded
-        return _COUNTER
-    # create an instance once
-    _COUNTER = _Counter(spec_file_name)
-    # set methods in Counter
-    for (k, v) in _COUNTER._to_global.items():
-        setattr(Counter, k, v)
-    return _COUNTER
-
 # static internal functions
 def _add_counter(element, spec, identifier):
     """Returns value of the identifier if the identifier is in the
@@ -159,6 +144,22 @@ def _stop_timer(start_time, element, spec, identifier):
     _set_counter(element, spec, identifier, sec)
 
 class Counter():
+    """A counter class"""
+    def init(spec_file_name):
+        """A creator method for a counter class. It creates a counter
+        object by the module name of the given spec file. An argument is a
+        specification file name."""
+        global _COUNTER
+        if isinstance(_COUNTER, _Counter):
+            # already loaded
+            return _COUNTER
+        # create an instance once
+        _COUNTER = _Counter(spec_file_name)
+        # set methods in Counter
+        for (k, v) in _COUNTER._to_global.items():
+            setattr(Counter, k, v)
+        return _COUNTER
+
     # These method are dummies for notify_out in case XfroutCounter is not
     # loaded.
     def inc_notifyoutv4(arg):

+ 2 - 2
src/lib/python/isc/statistics/tests/counter_test.py

@@ -50,7 +50,7 @@ class TestBasicMethods(unittest.TestCase):
     TEST_SPECFILE_LOCATION = TESTDATA_SRCDIR + os.sep + 'test_spec1.spec'
 
     def setUp(self):
-        self.counter = counter.init(self.TEST_SPECFILE_LOCATION)
+        self.counter = counter.Counter.init(self.TEST_SPECFILE_LOCATION)
 
     def tearDown(self):
         self.counter.clear_counters()
@@ -150,7 +150,7 @@ class BaseTestCounter():
     def setUp(self):
         self._module_spec = isc.config.module_spec_from_file(
             self.TEST_SPECFILE_LOCATION)
-        self.counter = counter.init(self.TEST_SPECFILE_LOCATION)
+        self.counter = counter.Counter.init(self.TEST_SPECFILE_LOCATION)
         self._statistics_data = {}
         self._entire_server    = self.counter._entire_server
         self._perzone_prefix   = self.counter._perzone_prefix