cherry picked cb5d027b about context managers
[nepi.git] / src / nepi / resources / omf / omf6_parser.py
index 4ea5717..68786b6 100644 (file)
@@ -3,9 +3,8 @@
 #    Copyright (C) 2013 INRIA
 #
 #    This program is free software: you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation, either version 3 of the License, or
-#    (at your option) any later version.
+#    it under the terms of the GNU General Public License version 2 as
+#    published by the Free Software Foundation;
 #
 #    This program is distributed in the hope that it will be useful,
 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -20,6 +19,7 @@
 
 from nepi.util.logger import Logger
 
+import os
 import traceback
 import xml.etree.ElementTree as ET
 
@@ -51,9 +51,12 @@ class OMF6Parser(Logger):
         """
         super(OMF6Parser, self).__init__("OMF6API")
         self.mailbox={}
+        self.traces={}
+        self.trace='NULL'
 
         self.init_mailbox()
 
+
     def init_mailbox(self):
         self.mailbox['create'] = []
         self.mailbox['started'] = []
@@ -169,18 +172,34 @@ class OMF6Parser(Logger):
         """
         props = self._check_for_props(root, namespaces)
         uid = self._check_for_tag(root, namespaces, "uid")
-        msg = "STATUS -- "
-        for elt in props.keys():
+        event = self._check_for_tag(root, namespaces, "event")
+
+        log = "STATUS -- "
+        for elt in props:
             ns, tag = elt.split('}')
             if tag == "it":
-                msg = msg + "membership : " + props[elt]+" -- "
+                log = log + "membership : " + props[elt]+" -- "
             elif tag == "event":
                 self.mailbox['started'].append(uid)
-                msg = msg + "event : " + props[elt]+" -- "
+                log = log + "event : " + props[elt]+" -- "
+            elif tag == "msg":
+                if event == "STDOUT" : 
+                    filename = os.path.join("/tmp", "%s.out" % uid)
+                    with open(filename,'a+') as f:
+                        # XXX: Adding fake \n for visual formatting 
+                        msg = props[elt] # + "\n"
+                        f.write(msg)
+                elif event == "STDERR" :
+                    filename = os.path.join("/tmp", "%s.err" % uid)
+                    with open(filename,'a+') as f:
+                        # XXX: Adding fake \n for visual formatting 
+                        msg = props[elt] # + "\n"
+                        f.write(msg)
+                log = log + tag +" : " + props[elt]+" -- "
             else:
-                msg = msg + tag +" : " + props[elt]+" -- "
-        msg = msg + " STATUS "
-        self.info(msg)
+                log = log + tag +" : " + props[elt]+" -- "
+        log = log + " STATUS "
+        self.info(log)
 
     def _inform_released(self, root, namespaces):
         """ Parse and Display RELEASED message