# Path: Database/db_controller.py
# class db_settings():
# class SettingsHelper(db_settings):
# class db_access(SettingsHelper, object):
# class db_helper(db_access):
#     USERNAME = 'postgres'
#     DB_HOST = '127.0.0.1'
#     PORT = 5432
#     DATABASE = 'network_monitor'
#     SETTINGS_FILE_PATH = "database_settings.json"
#     KEYRING_APP_ID = 'NetworkMonitor_db'
#         DB_HOST = raw_input('({0})>'.format(self.DB_HOST))
#     def loadSettings(cls):
#     def saveSettings(cls):
#     def __init__(self):
#     def open_connection(self):
#     def close_connection(connection, cursor):
#     def __init__(self):
#     def __create_database(self):
#     def __create_tables(self):
#     def test_db_setup(self):
#     def configure(self):
#     def clear_password_store(self):


import logging
from datetime import datetime
from Database import db_controller
            db_controller.db_access.close_connection(conn, cur)
            now = datetime.now()
            diff = (now - then)
            day_seconds = diff.days * 24 * 60 * 60  # Converts diff.days into seconds
            return float(day_seconds + diff.seconds) / 60  # Returns total diff in minutes
        except TypeError:
            return 9999


class monitor_list(object):
    # TODO maybe move into own module?
    """ CRUD access for monitor_list table """

    @staticmethod
    def get_server_list():
        """ Gets the entire monitor_list from db """
        conn, cur = db_controller.db_access().open_connection()
        get_all_query = '''SELECT * FROM monitor_list'''
        cur.execute(get_all_query)
        db_fetch = cur.fetchall()
        db_controller.db_access.close_connection(conn, cur)
        return db_fetch

    @staticmethod
    def get_time_from_last_failure():
        """ Returns how many minutes ago there was a failure logged """
        conn, cur = db_controller.db_access().open_connection()
        cur.execute(
            'SELECT time_stamp FROM server_stats ORDER BY time_stamp DESC LIMIT 1')
        then = cur.fetchone()[0]

# Path: Database/db_controller.py
# class db_settings():
# class SettingsHelper(db_settings):
# class db_access(SettingsHelper, object):
# class db_helper(db_access):
#     USERNAME = 'postgres'
#     DB_HOST = '127.0.0.1'
#     PORT = 5432
#     DATABASE = 'network_monitor'
#     SETTINGS_FILE_PATH = "database_settings.json"
#     KEYRING_APP_ID = 'NetworkMonitor_db'
#         DB_HOST = raw_input('({0})>'.format(self.DB_HOST))
#     def loadSettings(cls):
#     def saveSettings(cls):
#     def __init__(self):
#     def open_connection(self):
#     def close_connection(connection, cursor):
#     def __init__(self):
#     def __create_database(self):
#     def __create_tables(self):
#     def test_db_setup(self):
#     def configure(self):
#     def clear_password_store(self):


# Path: Database/db_helpers.py
import logging
from datetime import datetime
from Database import db_controller

            db_controller.db_access.close_connection(conn, cur)
            now = datetime.now()
            diff = (now - then)
            day_seconds = diff.days * 24 * 60 * 60  # Converts diff.days into seconds
            return float(day_seconds + diff.seconds) / 60  # Returns total diff in minutes
        except TypeError:
            return 9999


class monitor_list(object):
    # TODO maybe move into own module?
    """ CRUD access for monitor_list table """

    @staticmethod
    def get_server_list():
        """ Gets the entire monitor_list from db """
        conn, cur = db_controller.db_access().open_connection()
        get_all_query = '''SELECT * FROM monitor_list'''
        cur.execute(get_all_query)
        db_fetch = cur.fetchall()
        db_controller.db_access.close_connection(conn, cur)
        return db_fetch

    @staticmethod
    def get_time_from_last_failure():
        """ Returns how many minutes ago there was a failure logged """
        conn, cur = db_controller.db_access().open_connection()
        cur.execute(
            'SELECT time_stamp FROM server_stats ORDER BY time_stamp DESC LIMIT 1')
        then = cur.fetchone()[0]

        db_controller.db_access.close_connection(conn, cur)