def db_setup(datadir): # Workaround for https://github.com/mitsuhiko/flask-sqlalchemy/pull/250 tables.metadata.create_all(db.engine) if db.session.query(tables.Event).count(): print('Skipping DB reload') return get_db(datadir, engine=db.engine)
def test_at_least_one_event_present(): # This loads the DB, making sure it *can* be loaded from pyvodb.load import get_db from pyvodb.tables import Event db = get_db(str(data_dir)) cnt = db.query(Event).count() print(cnt) if not cnt: exit("no events found")
def cli(ctx, data, verbose, color, format, editor): """Query a meetup database. """ ctx.obj['verbose'] = verbose if verbose: logging.basicConfig(level=logging.INFO) logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO) ctx.obj['datadir'] = os.path.abspath(data) if 'db' not in ctx.obj: ctx.obj['db'] = get_db(data) if color is None: ctx.obj['term'] = blessings.Terminal() elif color is True: ctx.obj['term'] = blessings.Terminal(force_styling=True) elif color is False: ctx.obj['term'] = blessings.Terminal(force_styling=None) if 'PYVO_TEST_NOW' in os.environ: # Fake the current date for testing ctx.obj['now'] = datetime.datetime.strptime( os.environ['PYVO_TEST_NOW'], '%Y-%m-%d %H:%M:%S') else: ctx.obj['now'] = datetime.datetime.now() ctx.obj['format'] = format ctx.obj['editor'] = shlex.split(editor)
def db(): directory = os.path.join(os.path.dirname(__file__), 'data') return get_db(directory)
def empty_db(data_directory): return get_db(None)
def db(data_directory): return get_db(data_directory)