def make_celery(): app, conf = create_app() if app.config['REDIS_PASSWORD']: redis_broker='redis://:{}@{}:{}/0'.format( app.config['REDIS_PASSWORD'], app.config['REDIS_HOST'], app.config['REDIS_PORT'], ) else: redis_broker='redis://{}:{}/0'.format( app.config['REDIS_HOST'], app.config['REDIS_PORT'], ) app.logger.info('MIGRATE_MODE: {}, MIGRATE_ES: {}, Broker at {}' .format(MIGRATE_MODE, MIGRATE_ES,app.config['REDIS_HOST'])) celery = Celery(app.import_name, broker=redis_broker) celery.conf.update(app.config) celery.data_db = app.data_db # boiler plate to get our tasks running in the app context TaskBase = celery.Task class ContextTask(TaskBase): abstract = True def __call__(self, *args, **kwargs): with app.app_context(): return TaskBase.__call__(self, *args, **kwargs) celery.Task = ContextTask return celery
def main(self): args = self._parse_args() host_name, index_name = args.host, args.index if not host_name or not index_name: # we only create the app if needed for the host name or index name app, conf = create_app() else: app, conf = None, None es = elasticsearch.Elasticsearch(host_name) if host_name else app.es if not index_name: index_name = app.es_data_db_index_name self.create_es_index(es, index_name, delete_existing=args.force)
def flaskrun(db=None): ''' run's flask or does flask run? based on http://flask.pocoo.org/snippets/133/ ''' parser = argparse.ArgumentParser(description='Process some integers.') parser.add_argument('db', nargs='?', help='db name to use - FAIL edit /etc/bhs/config.yml for now') parser.add_argument('-d', '--debug', help='turn debug on', default=False) args = parser.parse_args() if (args.db): #TODO: change the db pass app, conf = create_app() app.run(debug=args.debug)
import pymongo from bson.code import Code from bhs_api import create_app def parse_args(): parser = argparse.ArgumentParser(description='compare the trees') parser.add_argument('--fromdb', help='the db from which to copy the slugs') return parser.parse_args() if __name__ == '__main__': args = parse_args() app, conf = create_app() fromdb = app.client_data_db[args.fromdb] trees = app.data_db.trees # TODO: remove references to the genTreeIndividuals collection - it is irrelevant and not in use # ''' # old_trees = fromdb.genTreeIndividuals.map_reduce( # Code("function() {emit (this.GTN, this.tree.meta.num_nodes)}"), # Code("function(k, vs) {return vs[0]}"), # "treeSizes", # query = {'tree': {'$exists': True}}) # # ''' old_trees = list(fromdb.treeSizes.find()) to_mig = []
import pymongo from bhs_api import create_app if __name__ == "__main__": app, conf = create_app(testing=True) app.testing = True for i in app.data_db.personalities.find( {'Slug.En': { '$regex': r'^personality_' }}): try: s = i['Slug']['En'] except KeyError: continue l = s.split('_')[1] i['Slug']['En'] = 'luminary_' + l app.data_db.personalities.save(i) client_user_db = pymongo.MongoClient(conf.user_db_host, conf.user_db_port)[conf.user_db_name] user_db = client_user_db['user'] for i in user_db.find(): if 'story_items' not in i: continue changed = False for j in i['story_items']: slug = j['id'] if slug.startswith('personality'): l = slug.split('_')[1] j['id'] = 'luminary_' + l app.logger.debug('changed {} to {}'.format(slug, j['id']))
from bhs_api import create_app app, conf = create_app(live=True)
def __init__(self, app=None): self.args = self._parse_args() self.app, self.conf = create_app() if not app else (app, app.conf)
import pymongo from bson.code import Code from bhs_api import create_app def parse_args(): parser = argparse.ArgumentParser(description= 'compare the trees') parser.add_argument('--fromdb', help='the db from which to copy the slugs') return parser.parse_args() if __name__ == '__main__': args = parse_args() app, conf = create_app() fromdb = app.client_data_db[args.fromdb] trees = app.data_db.trees # TODO: remove references to the genTreeIndividuals collection - it is irrelevant and not in use # ''' # old_trees = fromdb.genTreeIndividuals.map_reduce( # Code("function() {emit (this.GTN, this.tree.meta.num_nodes)}"), # Code("function(k, vs) {return vs[0]}"), # "treeSizes", # query = {'tree': {'$exists': True}}) # # ''' old_trees = list(fromdb.treeSizes.find()) to_mig = []
import pymongo from bhs_api import create_app if __name__ == "__main__": app, conf = create_app(testing=True) app.testing = True for i in app.data_db.personalities.find({'Slug.En': {'$regex': r'^personality_'}}): try: s = i['Slug']['En'] except KeyError: continue l = s.split('_')[1] i['Slug']['En'] = 'luminary_'+l app.data_db.personalities.save(i) client_user_db = pymongo.MongoClient(conf.user_db_host, conf.user_db_port)[conf.user_db_name] user_db = client_user_db['user'] for i in user_db.find(): if 'story_items' not in i: continue changed = False for j in i['story_items']: slug = j['id'] if slug.startswith('personality'): l = slug.split('_')[1] j['id'] = 'luminary_'+l app.logger.debug('changed {} to {}'.format(slug, j['id'])) changed = True if changed: user_db.update_one({'_id': i['_id']}, {'$set' : {'story_items': i['story_items']}})
def app(mock_db): mock.patch('elasticsearch.Elasticsearch') app, conf = create_app(testing=True) # there should one and only one data db app.data_db = mock_db return app
def app(): app, conf = create_app(testing=True) return app