# Path: HPCStats/Exceptions.py
# class HPCStatsDBIntegrityError(HPCStatsException):
# 
#     """Class for DB intregrity errors exceptions in HPCStats"""
# 
#     def __init__(self, msg):
# 
#         super(HPCStatsDBIntegrityError, self).__init__(msg)
# 
# class HPCStatsRuntimeError(HPCStatsException):
# 
#     """Class for runtime errors exceptions in HPCStats"""
# 
#     def __init__(self, msg):
# 
#         super(HPCStatsRuntimeError, self).__init__(msg)


import logging
from HPCStats.Exceptions import HPCStatsDBIntegrityError, HPCStatsRuntimeError
                 self.state,
                 self.queue,
                 self.job_department,
                 self.job_acct,
                 submission,
                 start,
                 end,
                 self.walltime )

    def find(self, db):
        """Search the Job in the database based on its sched_id and cluster. If
           exactly one job matches in database, set job_id attribute properly
           and returns its value. If more than one job matches, raises
           HPCStatsDBIntegrityError. If no job is found, returns None.
        """

        req = """
                SELECT job_id
                  FROM Job
                 WHERE cluster_id = %s
                   AND job_batch_id = %s
              """
        params = ( self.account.cluster.cluster_id,
                   self.batch_id )
        db.execute(req, params)
        nb_rows = db.cur.rowcount
        if nb_rows == 0:
            logger.debug("job %s not found in DB", str(self))
            return None
        elif nb_rows > 1:

# Path: HPCStats/Exceptions.py
# class HPCStatsDBIntegrityError(HPCStatsException):
# 
#     """Class for DB intregrity errors exceptions in HPCStats"""
# 
#     def __init__(self, msg):
# 
#         super(HPCStatsDBIntegrityError, self).__init__(msg)
# 
# class HPCStatsRuntimeError(HPCStatsException):
# 
#     """Class for runtime errors exceptions in HPCStats"""
# 
#     def __init__(self, msg):
# 
#         super(HPCStatsRuntimeError, self).__init__(msg)


# Path: HPCStats/Model/Job.py
import logging
from HPCStats.Exceptions import HPCStatsDBIntegrityError, HPCStatsRuntimeError

                 self.state,
                 self.queue,
                 self.job_department,
                 self.job_acct,
                 submission,
                 start,
                 end,
                 self.walltime )

    def find(self, db):
        """Search the Job in the database based on its sched_id and cluster. If
           exactly one job matches in database, set job_id attribute properly
           and returns its value. If more than one job matches, raises
           HPCStatsDBIntegrityError. If no job is found, returns None.
        """

        req = """
                SELECT job_id
                  FROM Job
                 WHERE cluster_id = %s
                   AND job_batch_id = %s
              """
        params = ( self.account.cluster.cluster_id,
                   self.batch_id )
        db.execute(req, params)
        nb_rows = db.cur.rowcount
        if nb_rows == 0:
            logger.debug("job %s not found in DB", str(self))
            return None
        elif nb_rows > 1:

            raise HPCStatsDBIntegrityError(