def chk_job_result(self, status_file_path, job):
        """
    Read status file attributes and parse them.

    Args:

    Return:
      True/False
      status_attr: dictionary of status file attrs
    """
        try:
            Logger.info("ErcJobProcessor.chk_job_result", "Check log result")
            is_valid_file, status_attr = ErcFileHandler().init_chmm_file(status_file_path, "STATUS")
            if not is_valid_file:
                Logger.error("ErcJobProcessor.chk_job_result", "Invalid CHMM status file.")
                return False, {}
            if not int(status_attr["ErrorCount"]) == 0:
                error_msg = ""
                trap_list = []
                for key, value in status_attr.items():
                    if key.startswith("Error-"):
                        error_msg = error_msg + str(key) + ":" + str(value) + " "
                        trap_list.append(value)
                Logger.error("ErcJobProcessor.chk_job_result", "Error code: " + error_msg)
                ErcTrapGenerator.generate_crm_trap(trap_list, self.config_attr["trap_drop_dir"])
                return False, {}
            else:
                Logger.info(
                    "ErcJobProcessor.chk_job_result", "Generated Log: " + status_attr["Job1 Created Download File"]
                )
                return True, status_attr
        except Exception as e:
            Logger.error("ErcJobProcessor.chk_job_result", str(e))
            return False, {}
def chk_log_time_length(control_attr, control_path):
    """
  Check the log time length resides in the Max and Mini range

  Args:
    control_attr: dictionary which stores attributes in contorl file
  Return:
    True/False
  """
    try:
        now = datetime.datetime.now().replace(second=0, microsecond=0)
        recent = datetime.datetime.strptime(control_attr["MostRecentTime"], "%m/%d/%Y %H:%M:%S")
        now_ts = time.mktime(now.timetuple())
        recent_ts = time.mktime(recent.timetuple())
        diff_in_min = int(now_ts - recent_ts) / 60
        if diff_in_min > int(control_attr["MaxDuration"]):
            Logger.info(
                "ErcJobProcessor.chk_log_time_length",
                "range: " + str(now) + "-" + str(recent) + " Max: " + control_attr["MaxDuration"],
            )
            fix_recent_time_marker(control_attr, control_path)
            return True
        elif diff_in_min < int(control_attr["MinDuration"]):
            Logger.error(
                "ErcJobProcessor.chk_log_time_length",
                "range: " + str(now) + "," + str(recent) + " Min: " + control_attr["MinDuration"],
            )
            ErcTrapGenerator.generate_erc_trap("Invalid log period: " + str(recent) + "->" + str(now), "")
            return False
    except Exception as e:
        Logger.error("ErcJobProcessor.chk_log_time_length", str(e))
        return False
    return True
 def create_ondemand_control_file(self, job):
     try:
         with open(self.config_attr["ondemand_control_tmp"], "r") as f1:
             with open(self.config_attr["ondemand_control_path"], "w") as f2:
                 for line in f1:
                     if line.startswith("StartTime:"):
                         f2.write("StartTime: " + job.start_time + "\n")
                     elif line.startswith("EndTime"):
                         f2.write("EndTime: " + job.end_time + "\n")
                     else:
                         f2.write(line)
         return True
     except Exception as e:
         Logger.error("ErcJobProcessor.create_ondemand_control_file", str(e))
         ErcTrapGenerator.generate_erc_trap(
             "On demand control file create failed.", self.config_attr["trap_drop_dir"]
         )
         return False
    def execute_chmm_crm(self, control_file_path):
        """
    Run crm app to communicate with CHMM, get the log files and generate state file

    Args:

    Return:
      True/False
    """
        try:
            Logger.info("ErcJobProcessor.execute_chmm_crm", "Start log fetching job.")
            process = Popen([self.config_attr["crm_path"], control_file_path], stdout=PIPE, stderr=PIPE)
            out, err = process.communicate()
            Logger.info("ErcJobProcessor.execute_chmm_crm, ", ",Err: " + str(err))
            return True
        except Exception as e:
            Logger.error("ErcJobProcessor.execute_chmm_crm", str(e))
            ErcTrapGenerator.generate_erc_trap("Execute CRM failed.", self.config_attr["trap_drop_dir"])
            return False
    def get_control_file_attrs(self, job):
        """
    get attrs from control file

    Args:

    Return:
      True/False
    """
        try:
            is_valid_file, control_attr = ErcFileHandler().init_chmm_file(self.config_attr["control_path"], "CONTROL")
            if not is_valid_file:
                Logger.error("ErcJobProcessor.get_control_file_attrs", "Invalid control file.")
                raise
            if job.type == "recent":
                if not chk_log_time_length(control_attr, self.config_attr["control_path"]):
                    return False
            if not os.path.exists(self.config_attr["log_path"]):
                os.mkdir(self.config_attr["log_path"])
            return True
        except Exception as e:
            Logger.error("ErcJobProcessor.get_control_file_attrs", str(e))
            ErcTrapGenerator.generate_erc_trap("Invalid CRM control file.", self.config_attr["trap_drop_dir"])
            return False