Esempio n. 1
0
def error_handler_terminal(args):
    exc = args.ExceptionObject
    if exc.InnerException:
        exc = exc.InnerException
    st = exc.StackTrace
    msg = "Error: %s" % exc.Message
    msg = ansicolor.red(msg)
    s = "%s\n%s" % (st, msg)
    print(s)
Esempio n. 2
0
def error_handler_terminal(args):
    exc = args.ExceptionObject
    if exc.InnerException:
        exc = exc.InnerException
    st = exc.StackTrace
    msg = "Error: %s" % exc.Message
    msg = ansicolor.red(msg)
    s = "%s\n%s" % (st, msg)
    print(s)
Esempio n. 3
0
    def display_transforms_and_prompt(self, items):
        clashes = 0
        arrow = "->"
        prefix = " * "
        linewidth = 78
        spacing = 2

        def get_slot(linewidth, arrow, prefix, spacing):
            return (linewidth - len(arrow) - prefix - spacing) / 2

        slotlong = get_slot(linewidth, arrow, len(prefix), spacing)
        longest_l = max(map(lambda item: len(item.f), items))
        longest = max(longest_l, max(map(lambda item: len(item.g), items)))
        slot = longest
        slot_l = longest_l
        if longest > slotlong:
            slot = get_slot(linewidth, arrow, len(prefix), spacing)
            slot_l = slot

        for item in items:
            arrow_fmt = ansicolor.yellow(arrow)
            prefix_fmt = ansicolor.green(prefix)
            f_fmt, g_fmt = ansicolor.colordiff(item.f, item.g)
            if item.invalid:
                clashes += 1
                g_fmt = ansicolor.red(item.g)
            if len(item.f) <= slot and len(item.g) <= slot:
                f_fmt = ansicolor.justify_formatted(f_fmt, string.ljust,
                                                    slot_l)
                io.writeln("%s%s %s %s" %
                           (prefix_fmt, f_fmt, arrow_fmt, g_fmt))
            else:
                io.writeln("%s%s\n%s %s" %
                           (prefix_fmt, f_fmt, arrow_fmt, g_fmt))

        s_files = "%s files" % len(items)
        prompt = "Rename %s? [y/N] " % s_files
        if clashes:
            prompt = "%s clash(es) exist, rename %s? [y/N] " % (clashes,
                                                                s_files)

        sys.stdout.write(prompt)
        inp = raw_input()

        return inp == "y"
Esempio n. 4
0
    def display_transforms_and_prompt(self, items):
        clashes = 0
        arrow = "->"; prefix = " * "
        linewidth = 78; spacing = 2

        def get_slot(linewidth, arrow, prefix, spacing):
            return (linewidth - len(arrow) - prefix - spacing) / 2
        slotlong = get_slot(linewidth, arrow, len(prefix), spacing)
        longest_l = max(map(lambda item: len(item.f), items))
        longest = max(longest_l, max(map(lambda item: len(item.g), items)))
        slot = longest; slot_l = longest_l
        if longest > slotlong:
            slot = get_slot(linewidth, arrow, len(prefix), spacing)
            slot_l = slot

        for item in items:
            arrow_fmt = ansicolor.yellow(arrow)
            prefix_fmt = ansicolor.green(prefix)
            f_fmt, g_fmt = ansicolor.colordiff(item.f, item.g)
            if item.invalid:
                clashes += 1
                g_fmt = ansicolor.red(item.g)
            if len(item.f) <= slot and len(item.g) <= slot:
                f_fmt = ansicolor.justify_formatted(f_fmt, string.ljust, slot_l)
                io.writeln("%s%s %s %s" % (prefix_fmt, f_fmt, arrow_fmt, g_fmt))
            else:
                io.writeln("%s%s\n%s %s" % (prefix_fmt, f_fmt, arrow_fmt, g_fmt))

        s_files = "%s files" % len(items)
        prompt = "Rename %s? [y/N] " % s_files
        if clashes:
            prompt = "%s clash(es) exist, rename %s? [y/N] " % (clashes, s_files)

        sys.stdout.write(prompt)
        inp = raw_input()

        return inp == "y"
Esempio n. 5
0
def write_abort():
    write_err("\n%s\n" % ansicolor.red("User aborted"))
Esempio n. 6
0
    a("--pause", type="int", metavar="<pause>", dest="pause", help="Pause for x seconds between requests")
    a("--depth", type="int", metavar="<depth>", dest="depth", help="Spider to this depth")
    (opts, args) = io.parse_args(parser)
    try:
        if opts.fetch:
            os.environ["FETCH_ALL"] = "1"
        elif opts.dump:
            os.environ["DUMP_ALL"] = "1"
        if opts.host:
            os.environ["HOST_FILTER"] = "1"
        if opts.pause:
            os.environ["PAUSE"] = str(opts.pause)
        if opts.depth:
            os.environ["DEPTH"] = str(opts.depth)

        url = args[0]
        (q, w) = restore_session(url)
        if opts.recipe:
            rules = recipe.load_recipe(opts.recipe, url)
        else:
            pattern = args[1]
            rules = recipe.get_recipe(pattern, url)
        queue = q or recipe.get_queue(url, mode=fetch.Fetcher.SPIDER)
        wb = w or web.Web(url)
    except recipe.PatternError, e:
        io.write_err(ansicolor.red("%s\n" % e))
        sys.exit(1)
    except IndexError:
        io.opts_help(None, None, None, parser)
    main(queue, rules, wb)