Beispiel #1
0
def main(argv):
    parser = OptionParser(
        conflict_handler='resolve')  # Intelligently resolve switch collisions
    parser.set_defaults(verbose=False,
                        filters_to_run=[],
                        packages=BuiltInPackages)

    # If any library loading switches (-l) are given, collect their names and remove them from argv
    argv, user_defined_libraries = filter_library_switches(argv)
    argv, autoloaded_libraries = filter_autoload_paths(argv)

    # Load built-in filters (those under BuiltInPackages)
    # Load user-requested filters (passed by -l on the command line)
    all_libraries = BuiltInPackages + user_defined_libraries + autoloaded_libraries
    tracer = TraceCore(libraries=all_libraries)

    # For each available filter, allow it to be invoked with switches on the command line
    for filter in tracer.available_filters_dict.values():
        add_filter_to_optparser(parser, filter)
    # Load built-in optparse switches
    register_builtin_switches(parser)

    if len(argv) <= 1:
        parser.print_help()
        sys.exit(1)

    # Perform option parse, check for user-requested filter classes
    opts, remaining_args = parser.parse_args(argv)
    # Done with parser
    parser.destroy()

    if opts.debug:
        config.set(debug=True)

    # Set verbose switch if given on command line
    tracer.verbose = opts.verbose
    tracer.break_on_exception = opts.break_on_exception

    # Set override Reader if given on command line
    tracer.reader_class_name = opts.reader_class_name

    # Take remaining arguments as input file names
    files = remaining_args[1:]  # remaining_args[0] seems to be sys.argv[0]

    # If switch -L was passed, dump out all available filter names and quit
    if opts.do_list_filters:
        tracer.list_filters()
        sys.exit(0)

    # Run requested filters
    try:
        tracer.run(opts.filters_to_run, files)
    except RuntimeError, e:
        err('RuntimeError: %s', e)
        sys.exit(1)
Beispiel #2
0
    def __init__(self, pager_path=None, files=None, verbose=True, clear_history=False):
        HistorySavingDefaultShell.__init__(self, clear_history=clear_history)

        self.tracer = TraceCore(libraries=BuiltInPackages, verbose=verbose, reader_class_name=config.cmd_reader_class)
        self.prompt = "trace> "

        self.files = files or []

        self.last_exception = None

        self._verbose = verbose

        if pager_path:
            self.pager_path = pager_path
            self.output_file = PagerFilename
        else:
            self.pager_path = self.output_file = None
Beispiel #3
0
    i = 0
    while i < len(L):
        yield L[i:i + K]
        i += K


def segmented_corpora(topdir, N):
    '''Divides the files under _topdir_ into N groups of approximately equal size.'''
    def all_files():
        file_list = (f for f in glob.glob(os.path.join(topdir, '**'))
                     if os.path.isfile(f))

        for file in file_list:
            reader = GuessReader(file)
            L = list(reader)
            for i in xrange(1, len(L) + 1):
                yield file + ':%d' % i

    files = list(all_files())
    return as_slices(files, int(math.ceil(len(files) / N)))


if __name__ == '__main__':
    trace = TraceCore(['apps.sanity'], verbose=False)

    topdir = 'cn'
    N = 10

    for files in segmented_corpora(topdir, 10):
        print '%s...%s' % (files[0], files[-1])
        trace.run([('SanityChecks', None)], files)