# 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/User.py
# class User(object):
# 
#     """Model class for the Userhpc table."""
# 
#     def __init__(self, login, firstname, lastname, department, user_id=None):
# 
#         self.user_id = user_id
#         self.login = login
#         self.lastname = lastname
#         self.firstname = firstname
#         self.department = department
# 
#     def __str__(self):
# 
#         return str(self.firstname) + " " + str(self.lastname) \
#                + " [" + str(self.department) + "] " + str(self.login)
# 
#     def __eq__(self, other):
# 
#         return self.login == other.login
# 
#     def find(self, db):
#         """Search the User in the database based on its login. If exactly
#            one user matches in database, set user_id attribute properly
#            and returns its value. If more than one user matches, raises
#            HPCStatsDBIntegrityError. If no user is found, returns None.
#         """
# 
#         req = """
#                 SELECT userhpc_id
#                   FROM Userhpc
#                  WHERE userhpc_login = %s
#               """
#         params = ( self.login, )
#         db.execute(req, params)
#         nb_rows = db.cur.rowcount
#         if nb_rows == 0:
#             logger.debug("user %s not found in DB", str(self))
#             return None
#         elif nb_rows > 1:
#             raise HPCStatsDBIntegrityError(
#                     "several user_id found in DB for user %s" \
#                       % (str(self)))
#         else:
#             self.user_id = db.cur.fetchone()[0]
#             logger.debug("user %s found in DB with id %d",
#                           str(self),
#                           self.user_id )
#             return self.user_id
# 
#     def save(self, db):
#         """Insert User in database. You must make sure that the User does
#            not already exist in database yet (typically using User.find()
#            method else there is a risk of future integrity errors because of
#            duplicated users. If user_id attribute is set, it raises
#            HPCStatsRuntimeError.
#         """
# 
#         if self.user_id is not None:
#             raise HPCStatsRuntimeError(
#                     "could not insert user %s since already existing in "\
#                     "database" \
#                       % (str(self)))
# 
#         req = """
#                 INSERT INTO Userhpc ( userhpc_login,
#                                       userhpc_firstname,
#                                       userhpc_name,
#                                       userhpc_department)
#                 VALUES ( %s, %s, %s, %s)
#                 RETURNING userhpc_id
#               """
#         params = ( self.login,
#                    self.firstname,
#                    self.lastname,
#                    self.department )
# 
#         #print db.cur.mogrify(req, params)
#         db.execute(req, params)
#         self.user_id = db.cur.fetchone()[0]
# 
#     def update(self, db):
#         """Update User firstname, lastname and department fields in database.
#            Raises HPCStatsRuntimeError is user_id is None.
#         """
# 
#         if self.user_id is None:
#             raise HPCStatsRuntimeError(
#                     "could not update user %s since not found in database" \
#                       % (str(self)))
# 
#         req = """
#                 UPDATE Userhpc
#                    SET userhpc_firstname = %s,
#                        userhpc_name = %s,
#                        userhpc_department = %s
#                 WHERE userhpc_id = %s
#               """
#         params = ( self.firstname,
#                    self.lastname,
#                    self.department,
#                    self.user_id )
# 
#         #print db.cur.mogrify(req, params)
#         db.execute(req, params)


import logging
from HPCStats.Exceptions import HPCStatsDBIntegrityError, HPCStatsRuntimeError
from HPCStats.Model.User import User

    tuples = []
    req = """
            SELECT Userhpc.userhpc_id,
                   userhpc_login,
                   userhpc_name,
                   userhpc_firstname,
                   userhpc_department,
                   account_uid,
                   account_gid,
                   account_creation
             FROM Userhpc,
                  Account
            WHERE Account.cluster_id = %s
              AND Account.userhpc_id = Userhpc.userhpc_id
              AND Account.account_deletion = NULL
          """
    params = ( cluster.cluster_id, )
    db.execute(req, params)
    results = db.cur.fetchall()

    for result in results:
        user_id = result[0]
        login = result[1]
        lastname = result[2]
        firstname = result[3]
        department = result[4]
        uid = result[5]
        gid = result[6]
        creation = result[7]

# 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/User.py
# class User(object):
# 
#     """Model class for the Userhpc table."""
# 
#     def __init__(self, login, firstname, lastname, department, user_id=None):
# 
#         self.user_id = user_id
#         self.login = login
#         self.lastname = lastname
#         self.firstname = firstname
#         self.department = department
# 
#     def __str__(self):
# 
#         return str(self.firstname) + " " + str(self.lastname) \
#                + " [" + str(self.department) + "] " + str(self.login)
# 
#     def __eq__(self, other):
# 
#         return self.login == other.login
# 
#     def find(self, db):
#         """Search the User in the database based on its login. If exactly
#            one user matches in database, set user_id attribute properly
#            and returns its value. If more than one user matches, raises
#            HPCStatsDBIntegrityError. If no user is found, returns None.
#         """
# 
#         req = """
#                 SELECT userhpc_id
#                   FROM Userhpc
#                  WHERE userhpc_login = %s
#               """
#         params = ( self.login, )
#         db.execute(req, params)
#         nb_rows = db.cur.rowcount
#         if nb_rows == 0:
#             logger.debug("user %s not found in DB", str(self))
#             return None
#         elif nb_rows > 1:
#             raise HPCStatsDBIntegrityError(
#                     "several user_id found in DB for user %s" \
#                       % (str(self)))
#         else:
#             self.user_id = db.cur.fetchone()[0]
#             logger.debug("user %s found in DB with id %d",
#                           str(self),
#                           self.user_id )
#             return self.user_id
# 
#     def save(self, db):
#         """Insert User in database. You must make sure that the User does
#            not already exist in database yet (typically using User.find()
#            method else there is a risk of future integrity errors because of
#            duplicated users. If user_id attribute is set, it raises
#            HPCStatsRuntimeError.
#         """
# 
#         if self.user_id is not None:
#             raise HPCStatsRuntimeError(
#                     "could not insert user %s since already existing in "\
#                     "database" \
#                       % (str(self)))
# 
#         req = """
#                 INSERT INTO Userhpc ( userhpc_login,
#                                       userhpc_firstname,
#                                       userhpc_name,
#                                       userhpc_department)
#                 VALUES ( %s, %s, %s, %s)
#                 RETURNING userhpc_id
#               """
#         params = ( self.login,
#                    self.firstname,
#                    self.lastname,
#                    self.department )
# 
#         #print db.cur.mogrify(req, params)
#         db.execute(req, params)
#         self.user_id = db.cur.fetchone()[0]
# 
#     def update(self, db):
#         """Update User firstname, lastname and department fields in database.
#            Raises HPCStatsRuntimeError is user_id is None.
#         """
# 
#         if self.user_id is None:
#             raise HPCStatsRuntimeError(
#                     "could not update user %s since not found in database" \
#                       % (str(self)))
# 
#         req = """
#                 UPDATE Userhpc
#                    SET userhpc_firstname = %s,
#                        userhpc_name = %s,
#                        userhpc_department = %s
#                 WHERE userhpc_id = %s
#               """
#         params = ( self.firstname,
#                    self.lastname,
#                    self.department,
#                    self.user_id )
# 
#         #print db.cur.mogrify(req, params)
#         db.execute(req, params)


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


    tuples = []
    req = """
            SELECT Userhpc.userhpc_id,
                   userhpc_login,
                   userhpc_name,
                   userhpc_firstname,
                   userhpc_department,
                   account_uid,
                   account_gid,
                   account_creation
             FROM Userhpc,
                  Account
            WHERE Account.cluster_id = %s
              AND Account.userhpc_id = Userhpc.userhpc_id
              AND Account.account_deletion = NULL
          """
    params = ( cluster.cluster_id, )
    db.execute(req, params)
    results = db.cur.fetchall()

    for result in results:
        user_id = result[0]
        login = result[1]
        lastname = result[2]
        firstname = result[3]
        department = result[4]
        uid = result[5]
        gid = result[6]
        creation = result[7]

        user = User(login, firstname, lastname, department, user_id=user_id)