예제 #1
0
def main(options, out, err):
    if options.debug:
        if options.funcs is None:
            logger.debug('=== Funcs: None')
        else:
            logger.debug('=== Funcs:')
            for thing in options.funcs:
                logger.debug(repr(thing))
        if options.vars is None:
            logger.debug('=== Vars: None')
        else:
            logger.debug('=== Vars:')
            for thing in options.vars:
                logger.debug(repr(thing))
        logger.debug('var_match: %r, func_match: %r', options.var_match,
                     options.func_match)

    stream = out.stream
    var_callback = func_callback = None
    if options.print_vars:
        stream = None
        var_matches = []
        var_callback = var_matches.append
    if options.print_funcs:
        stream = None
        func_matches = []

        def func_callback(level, name, body):
            func_matches.append((level, name, body))

    # Hack: write to the stream directly.
    filter_env.main_run(stream,
                        options.input.read(),
                        options.vars,
                        options.funcs,
                        options.var_match,
                        options.func_match,
                        global_envvar_callback=var_callback,
                        func_callback=func_callback)

    if options.print_vars:
        for var in sorted(var_matches):
            out.write(var.strip())

    if options.print_funcs:
        for level, name, block in func_matches:
            if level == 0:
                out.write(block)
예제 #2
0
def main(options, out, err):
    if options.debug:
        if options.funcs is None:
            logger.debug('=== Funcs: None')
        else:
            logger.debug('=== Funcs:')
            for thing in options.funcs:
                logger.debug(repr(thing))
        if options.vars is None:
            logger.debug('=== Vars: None')
        else:
            logger.debug('=== Vars:')
            for thing in options.vars:
                logger.debug(repr(thing))
        logger.debug('var_match: %r, func_match: %r',
                     options.var_match, options.func_match)

    stream = out.stream
    var_callback = func_callback = None
    if options.print_vars:
        stream = None
        var_matches = []
        var_callback = var_matches.append
    if options.print_funcs:
        stream = None
        func_matches = []

        def func_callback(level, name, body):
            func_matches.append((level, name, body))

    # Hack: write to the stream directly.
    filter_env.main_run(
        stream, options.input.read(), options.vars, options.funcs,
        options.var_match, options.func_match,
        global_envvar_callback=var_callback,
        func_callback=func_callback)

    if options.print_vars:
        for var in sorted(var_matches):
            out.write(var.strip())

    if options.print_funcs:
        for level, name, block in func_matches:
            if level == 0:
                out.write(block)
예제 #3
0
 def run(self, args):
     src_path, dest_path = args.files
     with open(src_path) as src, open(dest_path, 'wb') as dest:
         filter_env.main_run(dest, src.read(), args.vars, args.funcs,
                             args.var_match, args.func_match)