Browse Source

[2298] modify the xml_handler() method

The requested URI is divided at the delimiter '/' and the module name
and the top-level item name are extracted if there are. It requests
statistics data and statistics schema of them the the stats daemon. It
builds an xml document by the values returned from the stats daemon.
Naoki Kambe 12 years ago
parent
commit
52794aa6f2
1 changed files with 12 additions and 6 deletions
  1. 12 6
      src/bin/stats/stats_httpd.py.in

+ 12 - 6
src/bin/stats/stats_httpd.py.in

@@ -462,20 +462,26 @@ class StatsHttpd:
                                   (err.__class__.__name__, err))
 
 
-    def xml_handler(self, module_name=None, item_name=None):
+    def xml_handler(self, path=''):
         """Requests the specified statistics data and specification by
         using the functions get_stats_data and get_stats_spec
         respectively and loads the XML template file and returns the
         string of the XML document.The argument is a path in the
         requested URI."""
 
+        dirs = [ d for d in path.split("/") if len(d) > 0 ]
+        module_name = None
+        item_name = None
+        if len(dirs) > 0:
+            module_name = dirs[0]
+        if len(dirs) > 1:
+            item_name = dirs[1]
+            # removed an index string when list-type value is
+            # requested. Because such a item name can be accept by the
+            # stats module currently.
+            item_name = re.sub('\[\d+\]$', '', item_name)
         stats_spec = self.get_stats_spec(module_name, item_name)
         stats_data = self.get_stats_data(module_name, item_name)
-        path = ''
-        if module_name:
-            path = module_name
-        if item_name:
-            path = '%s/%s' % (path, item_name)
         path_list = []
         try:
             path_list = item_name_list(stats_data, path)