# Path: config.py
# def sitename_from_readme():
# def splitcamel(s):
#     def __init__(self):
# class Config(object):
# class TestConfig(Config):
#     NAME = "DEBUG"
#     SECRET_KEY = os.environ.get("SECRET_KEY")
#     DEBUG = True
#     MAIL_SERVER = "smtp.gmail.com"
#     MAIL_USERNAME = "KentonCountyLibrary@gmail.com"
#     MAIL_PASSWORD = os.environ.get("MAIL_PASSWORD",None)
#     MAIL_PORT = 587
#     MAIL_USE_TLS = True
#     MAIL_DEFAULT_SENDER = "KentonCountyLibrary@gmail.com"
#     SQLALCHEMY_DATABASE_URI = "sqlite:///library.db"
#     SITENAME = sitename_from_readme()
#     SITENAMEPARTS = splitcamel(SITENAME)
#     NAME = "TEST"
#     SQLALCHEMY_DATABASE_URI = "sqlite://"
# 
# Path: library.py
# def csrf_protect():
# def generate_csrf_token():
# def logout_user():
# def login_required(test):
#     def wrap(*args, **kwargs):
# def inject_sitename():
# def login():
# def logout():
# def main():
# def admin():
# def librarian(rlid=None):
# def adduser():
# def deleteuser(username):
# def addrecread():
# def remrecread(rlid):
# def changeSticky(rlid):
# def profile(uname):
# def edit_profile(uname):
# def valid_image_file(image_file):
# def upload_picture(uname):
# def contact(uname):
# def contact_status(PCID):
# def is_valid_password(s):
# def changepassword():
# def reset_request():
# def reset_password():
# def publish():
#     ISBN = request.form['ISBN']
# 
# Path: database.py
# class Database(object):
#     """
#     An extremely simplified version of Flask-SQLAlchemy
#     """
# 
#     def __init__(self, app=None):
#         self._session = None
#         self.engine = None
#         self.app = None
# 
#         if app is not None:
#             self.init_app(app)
# 
#     @property
#     def session(self):
#         # either instantiate class with app or init_app before accessing the session property
#         if self._session is not None:
#             return self._session
#         return self.create_session()
# 
#     def create_session(self):
#         uri = self.app.config['SQLALCHEMY_DATABASE_URI']
#         self.engine = engine = create_engine(uri, convert_unicode=True)
#         maker = sessionmaker(autocommit=False, autoflush=False, bind=engine)
#         self._session = scoped_session(maker)
#         return self._session
# 
#     def init_app(self, app):
#         self.app = app
#         app.config.setdefault('SQLALCHEMY_DATABASE_URI', 'sqlite://')
# 
#         Base.query = self.session.query_property()
# 
#         @app.teardown_appcontext
#         def shutdown_session(response_or_exc):
#             if app.config.get('SQLALCHEMY_COMMIT_ON_TEARDOWN'):
#                 if response_or_exc is None:
#                     self.session.commit()
#             self.session.remove()
#             return response_or_exc
# 
# Path: models.py
# class Meta(Base):
#     """
#     The meta table is to store information about the database or application.
#     It is set up as a simple key/value store.
#     """
#     __tablename__ = 'meta'
#     key = Column(String, primary_key=True)
#     value = Column(String)


from config import config
from library import app
from database import Database
from models import Meta
from migration import *
import migration



class DatabaseMigration(object):
    def __init__(self):
        self.db = Database(app)

    def get_database_version(self):
        """
        DatabaseMigration.get_database_version(): returns the int value of db version
        Params:
        - None
        Returns:
        - (int) : the version of the database
        """
        version = Meta.query.filter_by(key="DB_VERSION").first()
        return int(version.value)

    def update_database_version(self, version=None):
        """
        DatabaseMigration.update_database_version() - updates a db version
        Params:
        - version (int) [optional] : the version to set.  if ommitted, increments version
        Returns:
        - None
        """

# Path: config.py
# def sitename_from_readme():
# def splitcamel(s):
#     def __init__(self):
# class Config(object):
# class TestConfig(Config):
#     NAME = "DEBUG"
#     SECRET_KEY = os.environ.get("SECRET_KEY")
#     DEBUG = True
#     MAIL_SERVER = "smtp.gmail.com"
#     MAIL_USERNAME = "KentonCountyLibrary@gmail.com"
#     MAIL_PASSWORD = os.environ.get("MAIL_PASSWORD",None)
#     MAIL_PORT = 587
#     MAIL_USE_TLS = True
#     MAIL_DEFAULT_SENDER = "KentonCountyLibrary@gmail.com"
#     SQLALCHEMY_DATABASE_URI = "sqlite:///library.db"
#     SITENAME = sitename_from_readme()
#     SITENAMEPARTS = splitcamel(SITENAME)
#     NAME = "TEST"
#     SQLALCHEMY_DATABASE_URI = "sqlite://"
# 
# Path: library.py
# def csrf_protect():
# def generate_csrf_token():
# def logout_user():
# def login_required(test):
#     def wrap(*args, **kwargs):
# def inject_sitename():
# def login():
# def logout():
# def main():
# def admin():
# def librarian(rlid=None):
# def adduser():
# def deleteuser(username):
# def addrecread():
# def remrecread(rlid):
# def changeSticky(rlid):
# def profile(uname):
# def edit_profile(uname):
# def valid_image_file(image_file):
# def upload_picture(uname):
# def contact(uname):
# def contact_status(PCID):
# def is_valid_password(s):
# def changepassword():
# def reset_request():
# def reset_password():
# def publish():
#     ISBN = request.form['ISBN']
# 
# Path: database.py
# class Database(object):
#     """
#     An extremely simplified version of Flask-SQLAlchemy
#     """
# 
#     def __init__(self, app=None):
#         self._session = None
#         self.engine = None
#         self.app = None
# 
#         if app is not None:
#             self.init_app(app)
# 
#     @property
#     def session(self):
#         # either instantiate class with app or init_app before accessing the session property
#         if self._session is not None:
#             return self._session
#         return self.create_session()
# 
#     def create_session(self):
#         uri = self.app.config['SQLALCHEMY_DATABASE_URI']
#         self.engine = engine = create_engine(uri, convert_unicode=True)
#         maker = sessionmaker(autocommit=False, autoflush=False, bind=engine)
#         self._session = scoped_session(maker)
#         return self._session
# 
#     def init_app(self, app):
#         self.app = app
#         app.config.setdefault('SQLALCHEMY_DATABASE_URI', 'sqlite://')
# 
#         Base.query = self.session.query_property()
# 
#         @app.teardown_appcontext
#         def shutdown_session(response_or_exc):
#             if app.config.get('SQLALCHEMY_COMMIT_ON_TEARDOWN'):
#                 if response_or_exc is None:
#                     self.session.commit()
#             self.session.remove()
#             return response_or_exc
# 
# Path: models.py
# class Meta(Base):
#     """
#     The meta table is to store information about the database or application.
#     It is set up as a simple key/value store.
#     """
#     __tablename__ = 'meta'
#     key = Column(String, primary_key=True)
#     value = Column(String)


# Path: migrate.py
from config import config
from library import app
from database import Database
from models import Meta
from migration import *
import migration




class DatabaseMigration(object):
    def __init__(self):
        self.db = Database(app)

    def get_database_version(self):
        """
        DatabaseMigration.get_database_version(): returns the int value of db version
        Params:
        - None
        Returns:
        - (int) : the version of the database
        """
        version = Meta.query.filter_by(key="DB_VERSION").first()
        return int(version.value)

    def update_database_version(self, version=None):
        """
        DatabaseMigration.update_database_version() - updates a db version
        Params:
        - version (int) [optional] : the version to set.  if ommitted, increments version
        Returns:
        - None
        """

        current_version = Meta.query.filter_by(key="DB_VERSION").first()