Boog Slayer /

from __future__ import print_function

import os
import sys
import pdb
import time
import argparse

import sqlalchemy

from datetime import datetime

from sqlalchemy import create_engine, Column, Integer, Boolean
from sqlalchemy import String, ForeignKey, Numeric, DateTime
from sqlalchemy.orm import sessionmaker, relationship, backref
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()
BASE_DIR = os.path.dirname(__file__)
DB_PATH = os.path.join(BASE_DIR, 'boogs.sq3')

def make_parser():
    '''Generates the ArgumentParser to parse Boog Slayer arguments.'''

class Project(Base):
    __tablename__ = 'projects'

    name = Column(String, primary_key=True)
    desc = Column(String)
    archived = Column(Boolean, default=False)

    def __eq__(self, other):
            return ==
        except AttributeError:
            return False

class Task(Base):
    __tablename__ = 'tasks'

    id = Column(Integer, primary_key=True)
    desc = Column(String)
    project = Column(String, ForeignKey(''))

class Interval(Base):
    __tablename__ = "intervals"

    start = Column(DateTime, primary_key=True)
    end = Column(DateTime)
    task_id = Column(Integer, ForeignKey(''))
    user_id = Column(String)

def make_engine():
    engine = create_engine('sqlite:///{0}'.format(DB_PATH))
    return engine

def make_session(engine=None):
    if engine is None:
        engine = make_engine()
    Session = sessionmaker(bind=engine)
    return Session()

def make_db(engine=None):
    if engine is None:
        engine = make_engine()

def reset_db(engine=None):
    if engine is None:
        engine = make_engine()
    Base.metadata.drop_all(engine, checkfirst=True)

def add_project(name=None, desc=None, session=None):
    if session is None:
        session = make_session()
    name = '' if name is None else name
    desc = '' if desc is None else desc
    proj = session.query(Project).filter_by(name=name).first()
    if proj is not None:
        raise ValueError('Project already exists with name {}'.format(name))
    proj = Project(name=name, desc=desc)

def update_project(name, desc=None, archived=None, session=None):
    if session is None:
        session = make_session()
    proj = session.query(Project).filter_by(name=name).first()
    if desc is not None:
        proj.desc = desc
    if archived is not None:
        proj.archived = archived

def main(args):
    return args

if __name__ == "__main__":