import logging
import sys

from dataactcore.models.baseInterface import databaseSession
from dataactbroker.fsrs import (
    configValid, fetchAndReplaceBatch, GRANT, PROCUREMENT)


logger = logging.getLogger(__name__)


if __name__ == '__main__':
    logging.basicConfig(level=logging.INFO)
    with databaseSession() as sess:
        if not configValid():
            logger.error("No config for broker/fsrs/[service]/wsdl")
            sys.exit(1)
        else:
            procs = fetchAndReplaceBatch(sess, PROCUREMENT)
            grants = fetchAndReplaceBatch(sess, GRANT)
            awards = procs + grants
            numSubAwards = sum(len(a.subawards) for a in awards)
            logger.info("Inserted/Updated %s awards, %s subawards",
                        len(awards), numSubAwards)

import logging
import sys

from dataactcore.interfaces.db import databaseSession
from dataactbroker.fsrs import (
    configValid, fetchAndReplaceBatch, GRANT, PROCUREMENT)


logger = logging.getLogger(__name__)


if __name__ == '__main__':
    logging.basicConfig(level=logging.INFO)
    with databaseSession() as sess:
        if not configValid():
            logger.error("No config for broker/fsrs/[service]/wsdl")
            sys.exit(1)
        else:
            procs = fetchAndReplaceBatch(sess, PROCUREMENT)
            grants = fetchAndReplaceBatch(sess, GRANT)
            awards = procs + grants
            numSubAwards = sum(len(a.subawards) for a in awards)
            logger.info("Inserted/Updated %s awards, %s subawards",
                        len(awards), numSubAwards)

Switch to using dbSession in db.py instead of baseInterface.py
Switch to using dbSession in db.py instead of baseInterface.py

This is another file that should have been included in PR #272,
where we transitioned all existing non-Flask db access to a
db connection using the new contextmanager. Originally missed
this one because it *is* using a contextmanager, but it's using
one in the deprecated baseInterface.py instead of the newer db.py.
