# Path: examples/pyramid_tut/pyramid_tut/models.py
# class User(Base):
# class Address(Base):
#     def __unicode__(self):
#     def __repr__(self):
#     def __unicode__(self):
#     def __repr__(self):


import os
import sys
import transaction
from datetime import date
from pyramid.paster import get_appsettings, setup_logging
from sqlalchemy import engine_from_config
from ..models import Address, Base, DBSession, User
def usage(argv):
    """Help user on how to use the script."""
    cmd = os.path.basename(argv[0])

    print("usage: %s <config_uri> [var=value]\n" % cmd, cmd)

    sys.exit(1)


def main(argv=sys.argv):
    """Populate database with 30 users."""
    if len(argv) < 2:
        usage(argv)

    config_uri = argv[1]

    setup_logging(config_uri)

    settings = get_appsettings(config_uri)

    engine = engine_from_config(settings, "sqlalchemy.")

    DBSession.configure(bind=engine)

    Base.metadata.create_all(engine)

    for i in range(30):
        with transaction.manager:
            address = Address(description="Address#2" + str(i).rjust(2, "0"))


# Path: examples/pyramid_tut/pyramid_tut/models.py
# class User(Base):
# class Address(Base):
#     def __unicode__(self):
#     def __repr__(self):
#     def __unicode__(self):
#     def __repr__(self):


# Path: examples/pyramid_tut/pyramid_tut/scripts/initializedb.py
import os
import sys
import transaction
from datetime import date
from pyramid.paster import get_appsettings, setup_logging
from sqlalchemy import engine_from_config
from ..models import Address, Base, DBSession, User

def usage(argv):
    """Help user on how to use the script."""
    cmd = os.path.basename(argv[0])

    print("usage: %s <config_uri> [var=value]\n" % cmd, cmd)

    sys.exit(1)


def main(argv=sys.argv):
    """Populate database with 30 users."""
    if len(argv) < 2:
        usage(argv)

    config_uri = argv[1]

    setup_logging(config_uri)

    settings = get_appsettings(config_uri)

    engine = engine_from_config(settings, "sqlalchemy.")

    DBSession.configure(bind=engine)

    Base.metadata.create_all(engine)

    for i in range(30):
        with transaction.manager:
            address = Address(description="Address#2" + str(i).rjust(2, "0"))


            DBSession.add(address)