Exemplo n.º 1
0
    def _static_representation(self, bento_info):
        r_pkg = PackageDescription.from_string(bento_info)
        # We recompute pkg to avoid dealing with stylistic difference between
        # original and static_representation
        pkg = PackageDescription.from_string(static_representation(r_pkg))

        self.assertEqual(static_representation(pkg), static_representation(r_pkg))
Exemplo n.º 2
0
    def _static_representation(self, bento_info):
        r_pkg = PackageDescription.from_string(bento_info)
        # We recompute pkg to avoid dealing with stylistic difference between
        # original and static_representation
        pkg = PackageDescription.from_string(static_representation(r_pkg))

        self.assertEqual(static_representation(pkg),
                         static_representation(r_pkg))
Exemplo n.º 3
0
def convert(ctx, filename, setup_args, monkey_patch_mode, verbose, output, log, show_output=True):
    if monkey_patch_mode == "automatic":
        try:
            if verbose:
                pprint("PINK",
                       "Catching monkey (this may take a while) ...")
            monkey_patch_mode = detect_monkeys(filename, show_output, log)
            if verbose:
                pprint("PINK", "Detected mode: %s" % monkey_patch_mode)
        except ValueError:
            e = extract_exception()
            raise UsageException("Error while detecting setup.py type " \
                                 "(original error: %s)" % str(e))

    monkey_patch(ctx.top_node, monkey_patch_mode, filename)
    dist, package_objects = analyse_setup_py(filename, setup_args)
    pkg, options = build_pkg(dist, package_objects, ctx.top_node)

    out = static_representation(pkg, options)
    if output == '-':
        for line in out.splitlines():
            pprint("YELLOW", line)
    else:
        fid = open(output, "w")
        try:
            fid.write(out)
        finally:
            fid.close()
Exemplo n.º 4
0
def convert(ctx,
            filename,
            setup_args,
            monkey_patch_mode,
            verbose,
            output,
            log,
            show_output=True):
    if monkey_patch_mode == "automatic":
        try:
            if verbose:
                pprint("PINK", "Catching monkey (this may take a while) ...")
            monkey_patch_mode = detect_monkeys(filename, show_output, log)
            if verbose:
                pprint("PINK", "Detected mode: %s" % monkey_patch_mode)
        except ValueError:
            e = extract_exception()
            raise UsageException("Error while detecting setup.py type " \
                                 "(original error: %s)" % str(e))

    monkey_patch(ctx.top_node, monkey_patch_mode, filename)
    dist, package_objects = analyse_setup_py(filename, setup_args)
    pkg, options = build_pkg(dist, package_objects, ctx.top_node)

    out = static_representation(pkg, options)
    if output == '-':
        for line in out.splitlines():
            pprint("YELLOW", line)
    else:
        fid = open(output, "w")
        try:
            fid.write(out)
        finally:
            fid.close()
Exemplo n.º 5
0
    def run(self, ctx):
        argv = ctx.get_command_arguments()
        p = ctx.options_context.parser
        o, a = p.parse_args(argv)
        if o.help:
            p.print_help()
            return
        if len(a) < 1:
            filename = "setup.py"
        else:
            filename = a[0]
        if not os.path.exists(filename):
            raise ValueError("file %s not found" % filename)

        output = o.output_filename
        if os.path.exists(output):
            raise UsageException("file %s exists, not overwritten" % output)

        if o.verbose:
            show_output = True
        else:
            show_output = False

        if o.setup_args:
            setup_args = comma_list_split(o.setup_args)
        else:
            setup_args = ["-q", "-n"]

        tp = o.type

        convert_log = "convert.log"
        log = open(convert_log, "w")
        try:
            try:
                if tp == "automatic":
                    try:
                        pprint("PINK",
                               "Catching monkey (this may take a while) ...")
                        tp = detect_monkeys(filename, show_output, log)
                        pprint("PINK", "Detected mode: %s" % tp)
                    except ValueError:
                        e = extract_exception()
                        raise UsageException("Error while detecting setup.py type " \
                                             "(original error: %s)" % str(e))

                monkey_patch(tp, filename)
                # analyse_setup_py put results in LIVE_OBJECTS
                dist = analyse_setup_py(filename, setup_args)
                pkg, options = build_pkg(dist, LIVE_OBJECTS, ctx.top_node)

                out = static_representation(pkg, options)
                if output == '-':
                    for line in out.splitlines():
                        pprint("YELLOW", line)
                else:
                    fid = open(output, "w")
                    try:
                        fid.write(out)
                    finally:
                        fid.close()
            except ConvertionError:
                raise
            except Exception:
                e = extract_exception()
                log.write("Error while converting - traceback:\n")
                tb = sys.exc_info()[2]
                traceback.print_tb(tb, file=log)
                msg = "Error while converting %s - you may look at %s for " \
                      "details (Original exception: %s %s)" 
                raise ConvertionError(msg % (filename, convert_log, type(e), str(e)))
        finally:
            log.flush()
            log.close()