# 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 datetime import datetime
from HPCStats.Exceptions import HPCStatsDBIntegrityError, HPCStatsRuntimeError
                   AND fsquota_time = %s
              """
        params = ( self.filesystem.cluster.cluster_id,
                   self.filesystem.fs_id,
                   self.name,
                   self.timestamp )
        db.execute(req, params)
        nb_rows = db.cur.rowcount
        if nb_rows == 0:
            logger.debug("fsusage %s not found in DB", str(self))
            self.exists = False
        elif nb_rows > 1:
            raise HPCStatsDBIntegrityError(
                    "several fsusage found in DB for fsusage %s" \
                      % (str(self)))
        else:
            logger.debug("fsusage %s found in DB", str(self))
            self.exists = True
        return self.exists

    def save(self, db):
        """Insert FSQuota in database. It first makes sure that the FSQuota
           does not already exist in database yet by calling FSQuota.existing()
           method if needed. If the fsquota already exists in database, it
           raises HPCStatsRuntimeError.
        """

        if self.exists is None: # not checked yet
            self.existing(db)
        if self.exists is True:

# 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/FSQuota.py
import logging
from datetime import datetime
from HPCStats.Exceptions import HPCStatsDBIntegrityError, HPCStatsRuntimeError

                   AND fsquota_time = %s
              """
        params = ( self.filesystem.cluster.cluster_id,
                   self.filesystem.fs_id,
                   self.name,
                   self.timestamp )
        db.execute(req, params)
        nb_rows = db.cur.rowcount
        if nb_rows == 0:
            logger.debug("fsusage %s not found in DB", str(self))
            self.exists = False
        elif nb_rows > 1:
            raise HPCStatsDBIntegrityError(
                    "several fsusage found in DB for fsusage %s" \
                      % (str(self)))
        else:
            logger.debug("fsusage %s found in DB", str(self))
            self.exists = True
        return self.exists

    def save(self, db):
        """Insert FSQuota in database. It first makes sure that the FSQuota
           does not already exist in database yet by calling FSQuota.existing()
           method if needed. If the fsquota already exists in database, it
           raises HPCStatsRuntimeError.
        """

        if self.exists is None: # not checked yet
            self.existing(db)
        if self.exists is True:

            raise HPCStatsRuntimeError(