Пример #1
0
def main():
    global logger
    format = "[%(asctime)s %(levelname)s] %(message)s"
    logging.basicConfig(level=logging.WARNING, format=format)
    logger = logging.getLogger()

    args = parse_args()

    # set logging level
    if args.verbose > 1:
        set_log_debug(logger)
    elif args.verbose == 1:
        set_log_info(logger)
    if args.verbose <= 1:
        # if we're not in verbose mode, suppress routine logging for cron
        lgr = logging.getLogger('alembic')
        lgr.setLevel(logging.WARNING)
        lgr = logging.getLogger('biweeklybudget.db')
        lgr.setLevel(logging.WARNING)

    syncer = WishlistToProject()
    success, total = syncer.run()
    if success != total:
        logger.warning('Synced %d of %d project wishlists', success, total)
        raise SystemExit(1)
    raise SystemExit(0)
Пример #2
0
def main():
    """
    Main entry point - instantiate and run :py:class:`~.OfxBackfiller`.
    """
    global logger
    format = "[%(asctime)s %(levelname)s] %(message)s"
    logging.basicConfig(level=logging.WARNING, format=format)
    logger = logging.getLogger()

    args = parse_args()

    # set logging level
    if args.verbose > 1:
        set_log_debug(logger)
    elif args.verbose == 1:
        set_log_info(logger)

    client = apiclient(api_url=args.remote,
                       ca_bundle=args.ca_bundle,
                       client_cert=args.client_cert,
                       client_key=args.client_key)

    if args.remote is None:
        from biweeklybudget import settings
        save_path = settings.STATEMENTS_SAVE_PATH
    else:
        if args.save_path is None:
            logger.error(
                'ERROR: -s|--save-path must be specified when running '
                'in remote mode.')
            raise SystemExit(1)
        save_path = os.path.abspath(args.save_path)

    cls = OfxBackfiller(client, save_path)
    cls.run()
Пример #3
0
def main():
    global logger
    logging.basicConfig(level=logging.WARNING,
                        format="[%(asctime)s %(levelname)s] %(message)s")
    logger = logging.getLogger()

    args = parse_args()

    # set logging level
    if args.verbose > 1:
        set_log_debug(logger)
    elif args.verbose == 1:
        set_log_info(logger)

    atexit.register(cleanup_db)
    Base.metadata.reflect(engine)
    Base.metadata.drop_all(engine)
    db_session.flush()
    db_session.commit()
    init_db()

    logger.info('Loading data from: %s.%s', args.modname, args.clsname)
    klass = getattr(importlib.import_module(args.modname), args.clsname)
    inst = klass(db_session)
    logger.info('Loading data')
    inst.load()
    db_session.commit()
    logger.info('Data loaded.')
Пример #4
0
 def test_set_log_info(self):
     mock_log = Mock(spec_set=logging.Logger)
     with patch('%s.set_log_level_format' % pbm) as mock_set:
         set_log_info(mock_log)
     assert mock_set.mock_calls == [
         call(mock_log, logging.INFO,
              '%(asctime)s %(levelname)s:%(name)s:%(message)s')
     ]
Пример #5
0
def main():
    global logger
    format = "[%(asctime)s %(levelname)s] %(message)s"
    logging.basicConfig(level=logging.WARNING, format=format)
    logger = logging.getLogger()

    args = parse_args()

    # set logging level
    if args.verbose > 1:
        set_log_debug(logger)
    elif args.verbose == 1:
        set_log_info(logger)
    if args.verbose <= 1:
        # if we're not in verbose mode, suppress routine logging for cron
        lgr = logging.getLogger('alembic')
        lgr.setLevel(logging.WARNING)
        lgr = logging.getLogger('biweeklybudget.db')
        lgr.setLevel(logging.WARNING)

    client = apiclient(
        api_url=args.remote, ca_bundle=args.ca_bundle,
        client_cert=args.client_cert, client_key=args.client_key
    )
    if args.list:
        for k in sorted(OfxGetter.accounts(client).keys()):
            print(k)
        raise SystemExit(0)

    getter = OfxGetter(client, settings.STATEMENTS_SAVE_PATH)
    if args.ACCOUNT_NAME is not None:
        getter.get_ofx(args.ACCOUNT_NAME)
        raise SystemExit(0)
    # else all of them
    total = 0
    success = 0
    for acctname in sorted(OfxGetter.accounts(client).keys()):
        try:
            total += 1
            getter.get_ofx(acctname)
            success += 1
        except Exception:
            logger.error(
                'Failed to download account %s', acctname, exc_info=True
            )
    if success != total:
        logger.warning('Downloaded %d of %d accounts', success, total)
        raise SystemExit(1)
    raise SystemExit(0)
Пример #6
0
def main():
    global logger
    logging.basicConfig(level=logging.WARNING,
                        format="[%(asctime)s %(levelname)s] %(message)s")
    logger = logging.getLogger()

    args = parse_args()

    # set logging level
    if args.verbose > 1:
        set_log_debug(logger)
    elif args.verbose == 1:
        set_log_info(logger)

    logger.info('Initializing DB...')
    init_db()
    logger.info('Done initializing database')
Пример #7
0
def main():
    """
    Main entry point - instantiate and run :py:class:`~.OfxBackfiller`.
    """
    global logger
    format = "[%(asctime)s %(levelname)s] %(message)s"
    logging.basicConfig(level=logging.WARNING, format=format)
    logger = logging.getLogger()

    args = parse_args()

    # set logging level
    if args.verbose > 1:
        set_log_debug(logger)
    elif args.verbose == 1:
        set_log_info(logger)

    client = apiclient(api_url=args.remote,
                       ca_bundle=args.ca_bundle,
                       client_cert=args.client_cert,
                       client_key=args.client_key)
    cls = OfxBackfiller(client, settings.STATEMENTS_SAVE_PATH)
    cls.run()
Пример #8
0
def main():
    global logger
    format = "[%(asctime)s %(levelname)s] %(message)s"
    logging.basicConfig(level=logging.WARNING, format=format)
    logger = logging.getLogger()

    args = parse_args()

    # set logging level
    if args.verbose > 1:
        set_log_debug(logger)
    elif args.verbose == 1:
        set_log_info(logger)
    if args.verbose <= 1:
        # if we're not in verbose mode, suppress routine logging for cron
        lgr = logging.getLogger('alembic')
        lgr.setLevel(logging.WARNING)
        lgr = logging.getLogger('biweeklybudget.db')
        lgr.setLevel(logging.WARNING)

    client = apiclient(api_url=args.remote,
                       ca_bundle=args.ca_bundle,
                       client_cert=args.client_cert,
                       client_key=args.client_key)
    if args.list:
        for k in sorted(OfxGetter.accounts(client).keys()):
            print(k)
        raise SystemExit(0)

    if args.remote is None:
        from biweeklybudget import settings
        save_path = settings.STATEMENTS_SAVE_PATH
    else:
        if args.save_path is None:
            logger.error(
                'ERROR: -s|--save-path must be specified when running '
                'in remote mode.')
            raise SystemExit(1)
        save_path = os.path.abspath(args.save_path)

    getter = OfxGetter(client, save_path)

    if args.institution:
        if args.ACCOUNT_NAME is None:
            raise SystemExit('ERROR: Account name must be specified')
        getter = OfxGetter(client, save_path)
        acct = getter._accounts[args.ACCOUNT_NAME]
        logger.info('Authenticating to institution:')
        logger.debug(acct.institution.authenticate())
        logger.info('Getting list of accounts...')
        accts = acct.institution.accounts()
        print('Found %d accounts' % len(accts))
        for a in accts:
            print(a.serialize())
        raise SystemExit(0)

    if args.ACCOUNT_NAME is not None:
        getter.get_ofx(args.ACCOUNT_NAME, days=args.days)
        raise SystemExit(0)
    # else all of them
    total = 0
    success = 0
    for acctname in sorted(OfxGetter.accounts(client).keys()):
        try:
            total += 1
            getter.get_ofx(acctname, days=args.days)
            success += 1
        except Exception:
            logger.error('Failed to download account %s',
                         acctname,
                         exc_info=True)
    if success != total:
        logger.warning('Downloaded %d of %d accounts', success, total)
        raise SystemExit(1)
    raise SystemExit(0)