Example #1
0
def replace_path(binary, path, prefix):
    if sys.platform.startswith('linux'):
        return abspath(path)
    elif sys.platform.startswith('darwin'):
        if '@rpath' in path:
            rpath = get_rpath(join(prefix, binary))
            if not rpath:
                return "NO LC_RPATH FOUND"
            else:
                path = path.replace("@rpath", rpath)
        path = path.replace('@loader_path', join(prefix, dirname(binary)))
        if path.startswith('/'):
            return abspath(path)
        return 'not found'
Example #2
0
def replace_path(binary, path, prefix):
    if sys.platform.startswith('linux'):
        return abspath(path)
    elif sys.platform.startswith('darwin'):
        if '@rpath' in path:
            rpath = get_rpath(join(prefix, binary))
            if not rpath:
                return "NO LC_RPATH FOUND"
            else:
                path = path.replace("@rpath", rpath)
        path = path.replace('@loader_path', join(prefix, dirname(binary)))
        if path.startswith('/'):
            return abspath(path)
        return 'not found'
Example #3
0
def execute(args, parser):
    if not args.subcommand:
        parser.print_help()

    prefix = get_prefix(args)
    installed = ci.linked(prefix)

    if not args.packages and not args.untracked and not args.all:
        parser.error("At least one package or --untracked or --all must be provided")

    if args.all:
        args.packages = sorted([i.rsplit('-', 2)[0] for i in installed])

    if args.untracked:
        args.packages.append(untracked_package)

    for pkg in args.packages:
        if pkg == untracked_package:
            dist = untracked_package
        else:
            for dist in installed:
                if pkg == dist.rsplit('-', 2)[0]:
                    break
            else:
                sys.exit("Package %s is not installed in %s" % (pkg, prefix))

        print(pkg)
        print('-'*len(str(pkg)))
        print()

        if args.subcommand == 'linkages':
            if not sys.platform.startswith(('linux', 'darwin')):
                sys.exit("Error: conda inspect linkages is only implemented in Linux and OS X")

            if dist == untracked_package:
                obj_files = get_untracked_obj_files(prefix)
            else:
                obj_files = get_package_obj_files(dist, prefix)
            linkages = get_linkages(obj_files, prefix)
            depmap = defaultdict(list)
            for binary in linkages:
                for lib, path in linkages[binary]:
                    path = replace_path(binary, path, prefix) if path not in {'', 'not found'} else path
                    if path.startswith(prefix):
                        deps = list(which_package(path))
                        if len(deps) > 1:
                            print("Warning: %s comes from multiple packages: %s" % (path, ' and '.join(deps)), file=sys.stderr)
                        if not deps:
                            if exists(path):
                                depmap['untracked'].append((lib, path.split(prefix
                                    + '/', 1)[-1], binary))
                            else:
                                depmap['not found'].append((lib, path.split(prefix
                                    + '/', 1)[-1], binary))
                        for d in deps:
                            depmap[d].append((lib, path.split(prefix + '/',
                                1)[-1], binary))
                    elif path == 'not found':
                        depmap['not found'].append((lib, path, binary))
                    else:
                        depmap['system'].append((lib, path, binary))

            print_linkages(depmap, show_files=args.show_files)

        if args.subcommand == 'objects':
            if not sys.platform.startswith('darwin'):
                sys.exit("Error: conda inspect objects is only implemented in OS X")

            if dist == untracked_package:
                obj_files = get_untracked_obj_files(prefix)
            else:
                obj_files = get_package_obj_files(dist, prefix)

            info = []
            for f in obj_files:
                f_info = {}
                path = join(prefix, f)
                f_info['filetype'] = human_filetype(path)
                f_info['rpath'] = get_rpath(path)
                f_info['filename'] = f
                info.append(f_info)

            print_object_info(info, args.groupby)
Example #4
0
def execute(args, parser):
    if not args.subcommand:
        parser.print_help()

    prefix = get_prefix(args)
    installed = ci.linked(prefix)

    if not args.packages and not args.untracked and not args.all:
        parser.error(
            "At least one package or --untracked or --all must be provided")

    if args.all:
        args.packages = sorted([i.rsplit('-', 2)[0] for i in installed])

    if args.untracked:
        args.packages.append(untracked_package)

    for pkg in args.packages:
        if pkg == untracked_package:
            dist = untracked_package
        else:
            for dist in installed:
                if pkg == dist.rsplit('-', 2)[0]:
                    break
            else:
                sys.exit("Package %s is not installed in %s" % (pkg, prefix))

        print(pkg)
        print('-' * len(str(pkg)))
        print()

        if args.subcommand == 'linkages':
            if not sys.platform.startswith(('linux', 'darwin')):
                sys.exit(
                    "Error: conda inspect linkages is only implemented in Linux and OS X"
                )

            if dist == untracked_package:
                obj_files = get_untracked_obj_files(prefix)
            else:
                obj_files = get_package_obj_files(dist, prefix)
            linkages = get_linkages(obj_files, prefix)
            depmap = defaultdict(list)
            for binary in linkages:
                for lib, path in linkages[binary]:
                    path = replace_path(binary, path, prefix) if path not in {
                        '', 'not found'
                    } else path
                    if path.startswith(prefix):
                        deps = list(which_package(path))
                        if len(deps) > 1:
                            print(
                                "Warning: %s comes from multiple packages: %s"
                                % (path, ' and '.join(deps)),
                                file=sys.stderr)
                        if not deps:
                            if exists(path):
                                depmap['untracked'].append(
                                    (lib, path.split(prefix + '/',
                                                     1)[-1], binary))
                            else:
                                depmap['not found'].append(
                                    (lib, path.split(prefix + '/',
                                                     1)[-1], binary))
                        for d in deps:
                            depmap[d].append((lib, path.split(prefix + '/',
                                                              1)[-1], binary))
                    elif path == 'not found':
                        depmap['not found'].append((lib, path, binary))
                    else:
                        depmap['system'].append((lib, path, binary))

            print_linkages(depmap, show_files=args.show_files)

        if args.subcommand == 'objects':
            if not sys.platform.startswith('darwin'):
                sys.exit(
                    "Error: conda inspect objects is only implemented in OS X")

            if dist == untracked_package:
                obj_files = get_untracked_obj_files(prefix)
            else:
                obj_files = get_package_obj_files(dist, prefix)

            info = []
            for f in obj_files:
                f_info = {}
                path = join(prefix, f)
                f_info['filetype'] = human_filetype(path)
                f_info['rpath'] = get_rpath(path)
                f_info['filename'] = f
                info.append(f_info)

            print_object_info(info, args.groupby)