# Path: recruit_app/app.py
# def create_app(config_object=ProdConfig):
#     '''An application factory, as explained here:
#         http://flask.pocoo.org/docs/patterns/appfactories/
# 
#     :param config_object: The configuration object to use.
#     '''
#     app = Flask(__name__)
#     app.config.from_object(config_object)
#     register_extensions(app)
#     register_blueprints(app)
#     register_errorhandlers(app)
#     admin = Admin()
#     register_admin(admin, db)
#     # register_search(app)
#     admin.init_app(app)
#     # admin needs to be initialized oddly for tests to work.
#     register_tasks()
# 
#     return app
# 
# Path: recruit_app/settings.py
# class DevConfig(Config):
#     """Development configuration."""
#     ENV = 'dev'
#     DEBUG = True
#     #DB_NAME = 'dev.db'
#     # Put the db file in project root
#     #DB_PATH = os.path.join(Config.PROJECT_ROOT, DB_NAME)
#     SQLALCHEMY_DATABASE_URI = os_env.get('DATABASE_URL', 'postgresql://recruit@localhost:5432/recruit')
#     #SQLALCHEMY_DATABASE_URI = 'sqlite:///{0}'.format(DB_PATH)
#     WHOOSH_BASE = os.path.join(basedir, 'search.db')
#     #DEBUG_TB_ENABLED = True
#     ASSETS_DEBUG = True  # Don't bundle/minify static assets
#     CACHE_TYPE = 'simple'  # Can be "memcached", "redis", etc.
# 
# class ProdConfig(Config):
#     """Production configuration."""
#     ENV = 'prod'
#     DEBUG = False
#     SQLALCHEMY_DATABASE_URI = os_env.get('DATABASE_URL', 'postgresql://recruit@localhost:5432/recruit')
#     DEBUG_TB_ENABLED = False  # Disable Debug toolbar
#     WHOOSH_BASE = os.path.join(basedir, 'search.db')
# 
# Path: recruit_app/blacklist/models.py
# class BlacklistCharacter(SurrogatePK, TimeMixin, Model):
#     __tablename__ = 'blacklist_character'
#     # __searchable__ = ['name', 'main_name', 'corporation', 'alliance', 'notes', 'ip_address']
# 
#     name = Column(db.Unicode, nullable=True)
#     main_name = Column(db.Unicode, nullable=True)
#     corporation = Column(db.Unicode)
#     alliance = Column(db.Unicode)
#     notes = Column(db.Unicode)
# 
#     ip_address = Column(db.Unicode)
# 
#     creator_id = ReferenceCol('users', nullable=True)
#     creator = relationship('User', foreign_keys=[creator_id], backref='blacklist_character_entries')
# 
#     def __repr__(self):
#         return '<' + self.name + ': ' + self.notes + '>'


import os
import sys
from recruit_app.app import create_app
from recruit_app.settings import DevConfig, ProdConfig
from recruit_app.blacklist.models import BlacklistCharacter as Model
from flask.ext.whooshalchemy import whoosh_index
#!/usr/bin/env python


sys.stdout  = os.fdopen(sys.stdout.fileno(), 'w', 0)
atatime     = 512

if __name__ == '__main__':
    if os.environ.get("RECRUIT_APP_ENV") == 'prod':
        app = create_app(ProdConfig)
    else:
        app = create_app(DevConfig)

    with app.app_context():
        index       = whoosh_index(app, Model)
        searchable  = Model.__searchable__
        print 'counting rows...'

# Path: recruit_app/app.py
# def create_app(config_object=ProdConfig):
#     '''An application factory, as explained here:
#         http://flask.pocoo.org/docs/patterns/appfactories/
# 
#     :param config_object: The configuration object to use.
#     '''
#     app = Flask(__name__)
#     app.config.from_object(config_object)
#     register_extensions(app)
#     register_blueprints(app)
#     register_errorhandlers(app)
#     admin = Admin()
#     register_admin(admin, db)
#     # register_search(app)
#     admin.init_app(app)
#     # admin needs to be initialized oddly for tests to work.
#     register_tasks()
# 
#     return app
# 
# Path: recruit_app/settings.py
# class DevConfig(Config):
#     """Development configuration."""
#     ENV = 'dev'
#     DEBUG = True
#     #DB_NAME = 'dev.db'
#     # Put the db file in project root
#     #DB_PATH = os.path.join(Config.PROJECT_ROOT, DB_NAME)
#     SQLALCHEMY_DATABASE_URI = os_env.get('DATABASE_URL', 'postgresql://recruit@localhost:5432/recruit')
#     #SQLALCHEMY_DATABASE_URI = 'sqlite:///{0}'.format(DB_PATH)
#     WHOOSH_BASE = os.path.join(basedir, 'search.db')
#     #DEBUG_TB_ENABLED = True
#     ASSETS_DEBUG = True  # Don't bundle/minify static assets
#     CACHE_TYPE = 'simple'  # Can be "memcached", "redis", etc.
# 
# class ProdConfig(Config):
#     """Production configuration."""
#     ENV = 'prod'
#     DEBUG = False
#     SQLALCHEMY_DATABASE_URI = os_env.get('DATABASE_URL', 'postgresql://recruit@localhost:5432/recruit')
#     DEBUG_TB_ENABLED = False  # Disable Debug toolbar
#     WHOOSH_BASE = os.path.join(basedir, 'search.db')
# 
# Path: recruit_app/blacklist/models.py
# class BlacklistCharacter(SurrogatePK, TimeMixin, Model):
#     __tablename__ = 'blacklist_character'
#     # __searchable__ = ['name', 'main_name', 'corporation', 'alliance', 'notes', 'ip_address']
# 
#     name = Column(db.Unicode, nullable=True)
#     main_name = Column(db.Unicode, nullable=True)
#     corporation = Column(db.Unicode)
#     alliance = Column(db.Unicode)
#     notes = Column(db.Unicode)
# 
#     ip_address = Column(db.Unicode)
# 
#     creator_id = ReferenceCol('users', nullable=True)
#     creator = relationship('User', foreign_keys=[creator_id], backref='blacklist_character_entries')
# 
#     def __repr__(self):
#         return '<' + self.name + ': ' + self.notes + '>'


# Path: index_apps.py
import os
import sys
from recruit_app.app import create_app
from recruit_app.settings import DevConfig, ProdConfig
from recruit_app.blacklist.models import BlacklistCharacter as Model
from flask.ext.whooshalchemy import whoosh_index

#!/usr/bin/env python


sys.stdout  = os.fdopen(sys.stdout.fileno(), 'w', 0)
atatime     = 512

if __name__ == '__main__':
    if os.environ.get("RECRUIT_APP_ENV") == 'prod':
        app = create_app(ProdConfig)
    else:
        app = create_app(DevConfig)

    with app.app_context():
        index       = whoosh_index(app, Model)
        searchable  = Model.__searchable__
        print 'counting rows...'

        total       = int(Model.query.order_by(None).count())