# Path: zoe_lib/state/base.py
# class BaseRecord:
#     """
#     :type sql_manager: SQLManager
#     """
#     def __init__(self, d, sql_manager):
#         """
#         :type sql_manager: SQLManager
#         """
#         self.sql_manager = sql_manager
#         self.id = d['id']
# 
#     def serialize(self):
#         """Generates a dictionary that can be serialized in JSON."""
#         raise NotImplementedError
# 
# class BaseTable:
#     """Common abstraction for all tables."""
#     def __init__(self, sql_manager, table_name):
#         self.table_name = table_name
#         self.sql_manager = sql_manager
#         self.cursor = self.sql_manager.cursor()
# 
#     def create(self):
#         """Create this table."""
#         raise NotImplementedError
# 
#     def insert(self, **kwargs):
#         """Create a new record."""
#         raise NotImplementedError
# 
#     def delete(self, record_id):
#         """Delete a record from this table."""
#         query = 'DELETE FROM "{}" WHERE id = %s'.format(self.table_name)
#         self.cursor.execute(query, (record_id,))
#         self.sql_manager.commit()
# 
#     def update(self, record_id, **kwargs):
#         """Update the state of an execution."""
#         arg_list = []
#         value_list = []
#         for key, value in kwargs.items():
#             arg_list.append('{} = %s'.format(key))
#             value_list.append(value)
#         set_q = ", ".join(arg_list)
#         value_list.append(record_id)
#         q_base = 'UPDATE "{}" SET '.format(self.table_name) + set_q + ' WHERE id=%s'
#         query = self.cursor.mogrify(q_base, value_list)
#         self.cursor.execute(query)
#         self.sql_manager.commit()
# 
#     def select(self, only_one=False, limit=-1, **kwargs):
#         """Select records."""
#         raise NotImplementedError


import logging
import pwd
from passlib.hash import pbkdf2_sha256 as hash_algo
from zoe_lib.state.base import BaseRecord, BaseTable
    def set_quota_id(self, quota_id):
        """Set a different quota for this user."""
        self.quota_id = quota_id
        self.sql_manager.user.update(self.id, quota_id=quota_id)

    def set_role_id(self, role_id):
        """Set a new role for this user."""
        self.role_id = role_id
        self.sql_manager.user.update(self.id, role_id=role_id)

    @property
    def role(self):
        """Get the role from the DB."""
        return self.sql_manager.role.select(only_one=True, id=self.role_id)

    @property
    def quota(self):
        """Get the quota for this user."""
        return self.sql_manager.quota.select(only_one=True, id=self.quota_id)

    def __repr__(self):
        return self.username

    def __eq__(self, other):
        if isinstance(other, User):
            return self.id == other.id
        else:
            return False



# Path: zoe_lib/state/base.py
# class BaseRecord:
#     """
#     :type sql_manager: SQLManager
#     """
#     def __init__(self, d, sql_manager):
#         """
#         :type sql_manager: SQLManager
#         """
#         self.sql_manager = sql_manager
#         self.id = d['id']
# 
#     def serialize(self):
#         """Generates a dictionary that can be serialized in JSON."""
#         raise NotImplementedError
# 
# class BaseTable:
#     """Common abstraction for all tables."""
#     def __init__(self, sql_manager, table_name):
#         self.table_name = table_name
#         self.sql_manager = sql_manager
#         self.cursor = self.sql_manager.cursor()
# 
#     def create(self):
#         """Create this table."""
#         raise NotImplementedError
# 
#     def insert(self, **kwargs):
#         """Create a new record."""
#         raise NotImplementedError
# 
#     def delete(self, record_id):
#         """Delete a record from this table."""
#         query = 'DELETE FROM "{}" WHERE id = %s'.format(self.table_name)
#         self.cursor.execute(query, (record_id,))
#         self.sql_manager.commit()
# 
#     def update(self, record_id, **kwargs):
#         """Update the state of an execution."""
#         arg_list = []
#         value_list = []
#         for key, value in kwargs.items():
#             arg_list.append('{} = %s'.format(key))
#             value_list.append(value)
#         set_q = ", ".join(arg_list)
#         value_list.append(record_id)
#         q_base = 'UPDATE "{}" SET '.format(self.table_name) + set_q + ' WHERE id=%s'
#         query = self.cursor.mogrify(q_base, value_list)
#         self.cursor.execute(query)
#         self.sql_manager.commit()
# 
#     def select(self, only_one=False, limit=-1, **kwargs):
#         """Select records."""
#         raise NotImplementedError


# Path: zoe_lib/state/user.py
import logging
import pwd
from passlib.hash import pbkdf2_sha256 as hash_algo
from zoe_lib.state.base import BaseRecord, BaseTable

    def set_quota_id(self, quota_id):
        """Set a different quota for this user."""
        self.quota_id = quota_id
        self.sql_manager.user.update(self.id, quota_id=quota_id)

    def set_role_id(self, role_id):
        """Set a new role for this user."""
        self.role_id = role_id
        self.sql_manager.user.update(self.id, role_id=role_id)

    @property
    def role(self):
        """Get the role from the DB."""
        return self.sql_manager.role.select(only_one=True, id=self.role_id)

    @property
    def quota(self):
        """Get the quota for this user."""
        return self.sql_manager.quota.select(only_one=True, id=self.quota_id)

    def __repr__(self):
        return self.username

    def __eq__(self, other):
        if isinstance(other, User):
            return self.id == other.id
        else:
            return False



class UserTable(BaseTable):