# 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: models.py
# class PasswordReset(Base):
#     __tablename__ = 'passwordreset'
# 
#     secret = Column(String, primary_key=True)
#     created = Column(DateTime, default=dt.datetime.now)
# 
#     username = Column(String, ForeignKey('staff.username', ondelete='CASCADE'))
#     staff = relationship('Staff', backref='passwordresets')
# 
#     def __init__(self, **kwargs):
#         super(PasswordReset, self).__init__(**kwargs)
#         if 'secret' not in kwargs:
#             self.secret = self.gensecret(8)
# 
#     @classmethod
#     def gensecret(self, n):
#         chars = string.ascii_uppercase + string.digits
#         return ''.join(random.SystemRandom().choice(chars) for _ in range(n))
# 
#     @property
#     def valid(self):
#         # valid if not over an hour old
#         return (dt.datetime.now() - self.created).total_seconds() / 60 / 60 < 1


import re
import argparse
import os, sys
from sqlalchemy.sql import text
from library import app, db
from models import PasswordReset

sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

def create_passwordreset():
    """
    Create the passwordreset table in the database.
    """
    #commented out because this is done in models.py
    #with app.app_context():
    #    conn = db.session.connection()
    #    table = PasswordReset.metadata.tables['passwordreset']
    #    table.create(bind=db.engine)
    pass

def main():
    argparser = argparse.ArgumentParser(description=create_passwordreset.__doc__)
    argparser.add_argument('--echo', action='store_true', help='Echo SQL commands.')
    args = argparser.parse_args()

    if not any((app, db, PasswordReset)):
        argparser.exit(message='Import error, run as:\n$ python -m migration.01_create_passwordreset\n')

    if args.echo:

# 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: models.py
# class PasswordReset(Base):
#     __tablename__ = 'passwordreset'
# 
#     secret = Column(String, primary_key=True)
#     created = Column(DateTime, default=dt.datetime.now)
# 
#     username = Column(String, ForeignKey('staff.username', ondelete='CASCADE'))
#     staff = relationship('Staff', backref='passwordresets')
# 
#     def __init__(self, **kwargs):
#         super(PasswordReset, self).__init__(**kwargs)
#         if 'secret' not in kwargs:
#             self.secret = self.gensecret(8)
# 
#     @classmethod
#     def gensecret(self, n):
#         chars = string.ascii_uppercase + string.digits
#         return ''.join(random.SystemRandom().choice(chars) for _ in range(n))
# 
#     @property
#     def valid(self):
#         # valid if not over an hour old
#         return (dt.datetime.now() - self.created).total_seconds() / 60 / 60 < 1


# Path: migration/02_create_passwordreset.py
import re
import argparse
import os, sys
from sqlalchemy.sql import text
from library import app, db
from models import PasswordReset


sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

def create_passwordreset():
    """
    Create the passwordreset table in the database.
    """
    #commented out because this is done in models.py
    #with app.app_context():
    #    conn = db.session.connection()
    #    table = PasswordReset.metadata.tables['passwordreset']
    #    table.create(bind=db.engine)
    pass

def main():
    argparser = argparse.ArgumentParser(description=create_passwordreset.__doc__)
    argparser.add_argument('--echo', action='store_true', help='Echo SQL commands.')
    args = argparser.parse_args()

    if not any((app, db, PasswordReset)):
        argparser.exit(message='Import error, run as:\n$ python -m migration.01_create_passwordreset\n')

    if args.echo:

        db.engine.echo = True