<s> from __future__ import unicode_literals <EOL> import os <EOL> import sys <EOL> import logging <EOL> import transaction as db_transaction <EOL> from pyramid . paster import ( <EOL> get_appsettings , <EOL> setup_logging , <EOL> ) <EOL> from billy . models import setup_database <EOL> from billy . models . model_factory import ModelFactory <EOL> from billy . api . utils import get_processor_factory <EOL> def usage ( argv ) : <EOL> cmd = os . path . basename ( argv [ <NUM_LIT:0> ] ) <EOL> print ( '<STR_LIT>' <EOL> '<STR_LIT>' % ( cmd , cmd ) ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> def main ( argv = sys . argv , processor = None ) : <EOL> logger = logging . getLogger ( __name__ ) <EOL> if len ( argv ) != <NUM_LIT:2> : <EOL> usage ( argv ) <EOL> config_uri = argv [ <NUM_LIT:1> ] <EOL> setup_logging ( config_uri ) <EOL> settings = get_appsettings ( config_uri ) <EOL> settings = setup_database ( { } , ** settings ) <EOL> session = settings [ '<STR_LIT>' ] <EOL> try : <EOL> if processor is None : <EOL> processor_factory = get_processor_factory ( settings ) <EOL> else : <EOL> processor_factory = lambda : processor <EOL> factory = ModelFactory ( <EOL> session = session , <EOL> processor_factory = processor_factory , <EOL> settings = settings , <EOL> ) <EOL> subscription_model = factory . create_subscription_model ( ) <EOL> tx_model = factory . create_transaction_model ( ) <EOL> with db_transaction . manager : <EOL> logger . info ( '<STR_LIT>' ) <EOL> subscription_model . yield_invoices ( ) <EOL> with db_transaction . manager : <EOL> logger . info ( '<STR_LIT>' ) <EOL> tx_model . process_transactions ( ) <EOL> logger . info ( '<STR_LIT>' ) <EOL> finally : <EOL> session . close ( ) </s>
