def _fall_back_setStatus(self, job_path, status):
        parser = etree.XMLParser(no_network=False)
        index_path = os.path.join(job_path, "index.xml")
        doc = parse_xml_file(index_path, parser)
        root = doc.getroot()
        status_node = root.find("./status")
        try:
            old_message = status_node.find("value")
            if old_message is None:
                oldStatus = Status(string=str(status_node.find("value").text))
            else:
                oldStatus = Status(string=str(status_node.find("value").text), message=str(old_message.text))
        except AttributeError:
            oldStatus = Status(code=-1)  # unknown

        if oldStatus.isKnown() and oldStatus.isEnded():
            # the job is ended we can refactor status in a separate file
            root.remove(status_node)
            try:
                tmp_file = open(os.path.join(job_path, "tmp_index.xml"), "w")
                tmp_file.write(etree.tostring(doc, pretty_print=True, encoding="UTF-8"))
                tmp_file.close()
                os.rename(tmp_file.name, index_path)
            except Exception, err:
                _log.error("cannot make index.xml : %s" % err)

            self.create(job_path, oldStatus)
            return None
 def _fall_back_getStatus(self, job_path):
     parser = etree.XMLParser(no_network=False)
     doc = parse_xml_file(os.path.join(job_path, "index.xml"), parser)
     root = doc.getroot()
     try:
         status = root.find("./status/value").text
     except AttributeError:
         return Status(code=-1)  # unknown
     try:
         message = root.find("./status/message").text
     except AttributeError:
         message = None
     if message:
         return Status(string=str(status), message=str(message))
     else:
         return Status(string=str(status))
     File = open(fileName, "r+")
 except IOError, err:
     if err.errno == errno.ENOENT:
         try:
             return self._fall_back_setStatus(job_path, status)
         except Exception, err:
             _log.error("%s : cannot open either index.xml nor mobyle_status.xml: %s" % (job_path, err))
             return Status(code=-1)
     else:
         _log.error("cannot open %s : %s" % (fileName, err))
         return Status(code=-1)
 self._lock(File, self.WRITE)  # try to acquire a lock
 # If I do not got a lock a IOError is raised
 try:
     parser = etree.XMLParser(no_network=False)
     doc = parse_xml_file(File, parser)
     root = doc.getroot()
 except Exception, err:
     msg = "error in parsing status %s : %s" % (File.name, err)
     _log.error(msg)
     _log.debug("%f : %s : setStatus UNLOCK " % (time(), fileName))
     fcntl.lockf(File, fcntl.LOCK_UN)
     File.close()
     raise MobyleError(msg)
 #################
 old_status = self.getStatus(job_path)
 _log.debug("old_status= %s" % old_status)
 if old_status.isEnded():
     _log.warning(
         "%f : %s : try to update job status from %s to %s ( call by %s )"
         % (time(), fileName, old_status, status, os.path.basename(sys.argv[0]))