def main():
    parser = create_arg_parser()
    args = parser.parse_args()

    root = logging.getLogger()
    formatter = logging.Formatter('%(asctime)s : %(name)s : %(message)s')
    handler = logging.StreamHandler(sys.stderr)
    handler.setFormatter(formatter)
    root.addHandler(handler)
    root.setLevel(args.log_level)

    ctx = Context(
        api_location=os.environ.get('BALANCED_API_LOC', args.api_location),
        scenarios_dir=os.path.abspath(args.directory),
        client_dir=os.path.abspath(args.client),
        storage_file=args.storage,
        spec_file=args.spec,
        langs=args.langs,
        api_dir=os.path.abspath('./balanced-api'),
    )
    Scenario.bootstrap(ctx)
    write = BlockWriter(sys.stdout)
    for scenario in args.scenarios:
        logger.debug('scenario "%s"', scenario)
        scenario = ctx.lookup_scenario(scenario)
        blocks, response = scenario()
        generate(write, scenario.name, blocks, response, args.sections)
    ctx.storage.save()
Example #2
0
def error_rst(args):
    content = args.content.read() if args.content else None
    if content:
        logger.warning('discarding content:\n%s', content)
    data = dockers.load(open(args.data, 'r'))
    rst.error.generate(BlockWriter(sys.stdout), args.section_char, data,
                       args.sorts)
Example #3
0
def main():
    parser = create_arg_parser()
    args = parser.parse_args()

    root = logging.getLogger()
    formatter = logging.Formatter('%(asctime)s : %(name)s : %(message)s')
    handler = logging.StreamHandler(sys.stderr)
    handler.setFormatter(formatter)
    root.addHandler(handler)
    root.setLevel(args.log_level)

    Context.ROOT_URI = args.api_location

    if args.cache and os.path.isfile(args.cache):
        logger.debug('loading context from cache "%s"', args.cache)
        ctx = Context.load(open(args.cache, 'r'))
    else:
        ctx = Context()
    try:
        thresh_h, thresh_l = 10000000, 100000
        if ctx.marketplace.in_escrow < thresh_l:
            amount = thresh_h - ctx.marketplace.in_escrow
            logger.debug('incrementing escrow balanced %s', amount)
            ctx.card.debit(amount)
        write = BlockWriter(sys.stdout)
        for name in args.scenarios:
            munged = re.sub(r'[\-\.]', '_', name.lower())
            if munged not in SCENARIOS:
                raise ValueError('Invalid scenario "{0}" (munged "{1}")'.format(name, munged))
            req, resp = SCENARIOS[munged](ctx)
            generate(write, req, resp, args.sections)
    finally:
        if args.cache:
            logger.debug('saving context to cache "%s"', args.cache)
            ctx.save(open(args.cache, 'w'))
Example #4
0
def main():
    parser = create_arg_parser()
    args = parser.parse_args()

    root = logging.getLogger()
    formatter = logging.Formatter('%(asctime)s : %(name)s : %(message)s')
    handler = logging.StreamHandler(sys.stderr)
    handler.setFormatter(formatter)
    root.addHandler(handler)
    root.setLevel(args.log_level)

    ctx = Context(
        api_location=os.environ.get('BALANCED_API_LOC', args.api_location),
        scenarios_dir=os.path.abspath(args.directory),
        client_dir=os.path.abspath(args.client),
        storage_file=args.storage,
        spec_file=args.spec,
        langs=args.langs,
        api_dir=os.path.abspath('./balanced-api'),
    )
    Scenario.bootstrap(ctx)
    write = BlockWriter(sys.stdout)
    for scenario in args.scenarios:
        if os.environ.get('BALANCED_REV', 'rev0') != 'rev0':
            if re.match('^account_', scenario):
                #if 'account' in scenario.replace('bank_account', '') and False:
                # TODO: make this work
                with open('./empty-scenario', 'r') as some_file:
                    print some_file.read()
                continue
        logger.debug('scenario "%s"', scenario)
        scenario = ctx.lookup_scenario(scenario)
        blocks, response = scenario()
        generate(write, scenario.name, blocks, response, args.sections)
    ctx.storage.save()
Example #5
0
def endpoint_rst(args):
    content = args.content.read() if args.content else None
    if content:
        logger.warning('discarding content:\n%s', content)
    name = args.endpoint[0]
    data = dockers.load(open(args.data, 'r'))
    rst.endpoint.generate(
        writer=BlockWriter(sys.stdout),
        name=name,
        data=data,
        exclude_methods=args.exclude_methods,
    )
Example #6
0
def view_rst(args):
    content = args.content.read() if args.content else None
    name = args.view[0]
    data = dockers.load(open(args.data, 'r'))
    rst.view.generate(
        writer=BlockWriter(sys.stdout),
        name=name,
        content=content,
        data=data,
        includes=args.includes,
        excludes=args.excludes,
    )
Example #7
0
def enum_rst(args):
    content = args.content.read() if args.content else None
    if content:
        logger.warning('discarding content:\n%s', content)
    name = args.enum[0]
    data = dockers.load(open(args.data, 'r'))
    rst.enum.generate(
        BlockWriter(sys.stdout),
        name,
        data,
        includes=args.includes,
        excludes=args.excludes,
    )
Example #8
0
def form_rst(args):
    content = args.content.read() if args.content else None
    name = args.form[0]
    data = dockers.load(open(args.data, 'r'))
    rst.form.generate(
        writer=BlockWriter(sys.stdout),
        name=name,
        content=content,
        data=data,
        includes=args.includes,
        excludes=args.excludes,
        required=args.required,
    )