<filename>webapp/assessdb/scripts/import_csv_instruments.py
import os
import sys
import transaction
import csv

from pyramid.paster import (
    get_appsettings,
    setup_logging,
    )

from pyramid.scripts.common import parse_vars

from ..models.meta import Base
from ..models import (
    get_engine,
    get_session_factory,
    get_tm_session,
    )
from ..models import Instrument

def usage(argv):
    cmd = os.path.basename(argv[0])
    print('usage: %s <config_uri> [var=value]\n'
          '(example: "%s development.ini")' % (cmd, cmd))
    sys.exit(1)

def main(argv=sys.argv):
    if len(argv) < 3:
        usage(argv)
    config_uri = argv[1]
    fname = argv[2]
    options = parse_vars(argv[3:])

    setup_logging(config_uri)
    settings = get_appsettings(config_uri, options=options)

    engine = get_engine(settings)
    Base.metadata.create_all(engine)

    session_factory = get_session_factory(engine)

    with transaction.manager:
        dbsession = get_tm_session(session_factory, transaction.manager)
        with open(fname) as csvfile:
            reader = csv.DictReader(csvfile)
            for row in reader:
                p=Instrument()
                p.name=row['name']
                p.description=row['description']
                p.importTag=row['importTag']
                dbsession.add(p)

<filename>webapp/assessdb/scripts/import_csv_instruments.py
import os
import sys
import transaction
import csv

from pyramid.paster import (
    get_appsettings,
    setup_logging,
    )

from pyramid.scripts.common import parse_vars

from ..models.meta import Base
from ..models import (
    get_engine,
    get_session_factory,
    get_tm_session,
    )
from ..models import Instrument

def usage(argv):
    cmd = os.path.basename(argv[0])
    print('usage: %s <config_uri> [var=value]\n'
          '(example: "%s development.ini")' % (cmd, cmd))
    sys.exit(1)

def main(argv=sys.argv):
    if len(argv) < 3:
        usage(argv)
    config_uri = argv[1]
    fname = argv[2]
    options = parse_vars(argv[3:])

    setup_logging(config_uri)
    settings = get_appsettings(config_uri, options=options)

    engine = get_engine(settings)
    Base.metadata.create_all(engine)

    session_factory = get_session_factory(engine)

    with transaction.manager:
        dbsession = get_tm_session(session_factory, transaction.manager)
        with open(fname) as csvfile:
            reader = csv.DictReader(csvfile)
            for row in reader:
                p=Instrument()
                p.name=row['name']
                p.description=row['description']
                p.importTag=row['importTag']
                dbsession.add(p)
