python: Write configuration file without reassigning sys.stdout.
authorMiles Kaufmann <milesck@eecs.umich.edu>
Thu, 30 Aug 2007 19:16:59 +0000 (15:16 -0400)
committerMiles Kaufmann <milesck@eecs.umich.edu>
Thu, 30 Aug 2007 19:16:59 +0000 (15:16 -0400)
Using print >>ini_file syntax instead of reassigning sys.stdout
allows the python debugger to be used.

--HG--
extra : convert_revision : 63fc268f2e80f338ad1a7abe54b9e979e2239609

src/python/m5/SimObject.py
src/python/m5/params.py
src/python/m5/simulate.py

index 14978dd750bf307641fe05f84c346417767d757c..d3e7d7975264d2ebc112f7453cce1109f9dd13ad 100644 (file)
@@ -721,37 +721,38 @@ class SimObject(object):
         for child in child_names:
             self._children[child].unproxy_all()
 
-    def print_ini(self):
-        print '[' + self.path() + ']'  # .ini section header
+    def print_ini(self, ini_file):
+        print >>ini_file, '[' + self.path() + ']'      # .ini section header
 
         instanceDict[self.path()] = self
 
         if hasattr(self, 'type'):
-            print 'type=%s' % self.type
+            print >>ini_file, 'type=%s' % self.type
 
         child_names = self._children.keys()
         child_names.sort()
         if len(child_names):
-            print 'children=%s' % ' '.join(child_names)
+            print >>ini_file, 'children=%s' % ' '.join(child_names)
 
         param_names = self._params.keys()
         param_names.sort()
         for param in param_names:
             value = self._values.get(param)
             if value != None:
-                print '%s=%s' % (param, self._values[param].ini_str())
+                print >>ini_file, '%s=%s' % (param,
+                                             self._values[param].ini_str())
 
         port_names = self._ports.keys()
         port_names.sort()
         for port_name in port_names:
             port = self._port_refs.get(port_name, None)
             if port != None:
-                print '%s=%s' % (port_name, port.ini_str())
+                print >>ini_file, '%s=%s' % (port_name, port.ini_str())
 
-        print  # blank line between objects
+        print >>ini_file       # blank line between objects
 
         for child in child_names:
-            self._children[child].print_ini()
+            self._children[child].print_ini(ini_file)
 
     def getCCParams(self):
         if self._ccParams:
index 52a927ba39f28fff2f735d8112b28b6252f6b025..27bb24bd7b23d84a46a469e6da676b8a1660c63c 100644 (file)
@@ -176,9 +176,9 @@ class VectorParamValue(list):
         return [v.unproxy(base) for v in self]
 
 class SimObjVector(VectorParamValue):
-    def print_ini(self):
+    def print_ini(self, ini_file):
         for v in self:
-            v.print_ini()
+            v.print_ini(ini_file)
 
 class VectorParamDesc(ParamDesc):
     # Convert assigned value to appropriate type.  If the RHS is not a
index 6c70d8fbd0359822e798cfdbe679dff13f157c2e..3d91da3683a4ffeb86792de0f58c006d8574690c 100644 (file)
@@ -45,11 +45,10 @@ def instantiate(root):
     ticks.fixGlobalFrequency()
 
     root.unproxy_all()
-    # ugly temporary hack to get output to config.ini
-    sys.stdout = file(os.path.join(options.outdir, 'config.ini'), 'w')
-    root.print_ini()
-    sys.stdout.close() # close config.ini
-    sys.stdout = sys.__stdout__ # restore to original
+
+    ini_file = file(os.path.join(options.outdir, 'config.ini'), 'w')
+    root.print_ini(ini_file)
+    ini_file.close() # close config.ini
 
     # Initialize the global statistics
     internal.stats.initSimStats()