# 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
        self.exists = None

    def __str__(self):

        return "FSUsage %s: at %s %s%% usage" % \
                   ( self.filesystem,
                     self.timestamp,
                     self.usage )

    def existing(self, db):
        """Returns True if the FSUsage already exists in database (same cluster,
           filesystem and timestamp), or False if not.
        """

        req = """
                SELECT fsusage_time
                  FROM fsusage
                 WHERE cluster_id = %s
                   AND filesystem_id = %s
                   AND fsusage_time = %s
              """
        params = ( self.filesystem.cluster.cluster_id,
                   self.filesystem.fs_id,
                   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:

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

        self.exists = None

    def __str__(self):

        return "FSUsage %s: at %s %s%% usage" % \
                   ( self.filesystem,
                     self.timestamp,
                     self.usage )

    def existing(self, db):
        """Returns True if the FSUsage already exists in database (same cluster,
           filesystem and timestamp), or False if not.
        """

        req = """
                SELECT fsusage_time
                  FROM fsusage
                 WHERE cluster_id = %s
                   AND filesystem_id = %s
                   AND fsusage_time = %s
              """
        params = ( self.filesystem.cluster.cluster_id,
                   self.filesystem.fs_id,
                   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(