Skip to content

Commit

Permalink
More config fixes and db plumbing. Minor reorg.
Browse files Browse the repository at this point in the history
  • Loading branch information
aaront committed Jun 3, 2016
1 parent 8e9bafa commit 04533e3
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 19 deletions.
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM python:3.5
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
ADD requirements.txt /code/
RUN pip install -r requirements.txt
ADD . /code/
4 changes: 2 additions & 2 deletions puckdb/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ def _write(dsn=''):
conf.write(f)


def init():
def init(connect_path):
config_file = _get_config_file_path()
if not os.path.exists(os.path.dirname(config_file)):
os.makedirs(os.path.dirname(config_file))
_write()
_write(dsn=connect_path)


def get_db() -> str:
Expand Down
15 changes: 11 additions & 4 deletions puckdb/console.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import click

from . import conf, db

@click.command()
def init():
pass

@click.command(help='Initialize the database')
@click.argument('connect', nargs=1, required=False)
def init(connect=None):
if not conf.get_db():
if not connect:
raise Exception('Must provide a connection string')
conf.init(connect)
db.create()


@click.group
@click.group()
@click.version_option()
def main():
pass
Expand Down
12 changes: 8 additions & 4 deletions puckdb/db.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import sqlalchemy as sa
from sqlalchemy.schema import CreateTable

from .constants import GameState, GameEvent
from .async.db import *
from .conf import get_db

metadata = sa.MetaData()

Expand Down Expand Up @@ -34,6 +33,11 @@

event_tbl = sa.Table('event', metadata,
sa.Column('game_id', sa.BigInteger, sa.ForeignKey('game.id'), nullable=False),
sa.Column('type', sa.Enum(GameEvent), nullable=False),
sa.Column('')
sa.Column('type', sa.Enum(GameEvent), nullable=False)
)


def create():
engine = sa.create_engine(get_db())
metadata.drop_all(engine)
metadata.create_all(engine)
7 changes: 7 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
click
cchardet
aiohttp
aiopg
sqlalchemy
python-dateutil
ujson
9 changes: 0 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,6 @@
url='https://github.com/aaront/puckdb',
description='An async-first hockey data extractor and API',
long_description=open('README.rst').read(),
install_requires=[
'click',
'cchardet',
'aiohttp',
'aiopg',
'sqlalchemy',
'python-dateutil',
'ujson'
],
test_suite="tests",
include_package_data=True,
packages=find_packages(),
Expand Down

0 comments on commit 04533e3

Please sign in to comment.