Ejemplo n.º 1
0
def execute(args, parser):
    if not args.package:
        parser.print_help()
        return

    import conda.install
    import conda.resolve
    from conda.api import get_package_versions, app_is_installed
    from conda.misc import launch

    prefix = common.get_prefix(args)

    if args.quiet:
        logging.disable(logging.CRITICAL)

    if args.package.endswith('.tar.bz2'):
        if app_is_installed(args.package, prefixes=[prefix]):
            fn = args.package
        else:
            error_message = "Package {} not installed.".format(args.package)
            common.error_and_exit(error_message, json=args.json,
                                  error_type="PackageNotInstalled")
    else:
        installed = []
        for pkg in get_package_versions(args.package):
            if app_is_installed(pkg.fn, prefixes=[prefix]):
                installed.append(pkg)

        for pkg in conda.install.linked(prefix):
            name, version, build = pkg.rsplit('-', 2)
            if name == args.package:
                installed = [conda.resolve.Package(pkg + '.tar.bz2',
                                                   conda.install.is_linked(prefix, pkg))]
                break

        if installed:
            package = max(installed)
            fn = package.fn

            try:
                subprocess = launch(fn, prefix=prefix,
                                    additional_args=args.arguments,
                                    background=args.json)
                if args.json:
                    common.stdout_json(dict(fn=fn, pid=subprocess.pid))
                elif not args.quiet:
                    print("Started app. Some apps may take a while to finish loading.")
            except TypeError:
                execute_command(args.package, prefix, args.arguments, args.json)
            except Exception as e:
                common.exception_and_exit(e, json=args.json)
        else:
            # Try interpreting it as a command
            execute_command(args.package, prefix, args.arguments, args.json)
Ejemplo n.º 2
0
def execute(args, parser):
    if not args.package:
        parser.print_help()
        return

    import conda.install
    import conda.resolve
    from conda.api import get_package_versions, app_is_installed
    from conda.misc import launch

    prefix = common.get_prefix(args)

    if args.quiet:
        logging.disable(logging.CRITICAL)

    if args.package.endswith('.tar.bz2'):
        if app_is_installed(args.package, prefixes=[prefix]):
            fn = args.package
        else:
            error_message = "Package {} not installed.".format(args.package)
            common.error_and_exit(error_message, json=args.json,
                                  error_type="PackageNotInstalled")
    else:
        installed = []
        for pkg in get_package_versions(args.package):
            if app_is_installed(pkg.fn, prefixes=[prefix]):
                installed.append(pkg)

        for pkg in conda.install.linked(prefix):
            name, version, build = pkg.rsplit('-', 2)
            if name == args.package:
                installed = [conda.resolve.Package(pkg + '.tar.bz2',
                                                   conda.install.is_linked(prefix, pkg))]
                break

        if installed:
            package = max(installed)
            fn = package.fn

            try:
                subprocess = launch(fn, prefix=prefix,
                                    additional_args=args.arguments,
                                    background=args.json)
                if args.json:
                    common.stdout_json(dict(fn=fn, pid=subprocess.pid))
                elif not args.quiet:
                    print("Started app. Some apps may take a while to finish loading.")
            except TypeError:
                execute_command(args.package, prefix, args.arguments, args.json)
            except Exception as e:
                common.exception_and_exit(e, json=args.json)
        else:
            # Try interpreting it as a command
            execute_command(args.package, prefix, args.arguments, args.json)
Ejemplo n.º 3
0
def pretty_package(pkg):
    import conda.config as config
    from conda.utils import human_bytes
    from conda.api import app_is_installed

    d = OrderedDict([
        ('file name', pkg.fn),
        ('name', pkg.name),
        ('version', pkg.version),
        ('build number', pkg.build_number),
        ('build string', pkg.build),
        ('channel', config.canonical_channel_name(pkg.channel)),
        ('size', human_bytes(pkg.info['size'])),
        ])
    rest = pkg.info.copy()
    for key in sorted(rest):
        if key in ['build', 'depends', 'requires', 'channel', 'name',
            'version', 'build_number', 'size']:
            continue
        d[key] = rest[key]


    print()
    header = "%s %s %s" % (d['name'], d['version'], d['build string'])
    print(header)
    print('-'*len(header))
    for key in d:
        print("%-12s: %s" % (key, d[key]))
    print("installed environments:")
    for env in app_is_installed(pkg.fn):
        print('    %s' % env)
    print('dependencies:')
    for dep in pkg.info['depends']:
        print('    %s' % dep)
Ejemplo n.º 4
0
def pretty_package(pkg):
    import conda.config as config
    from conda.utils import human_bytes
    from conda.api import app_is_installed

    d = OrderedDict([
        ('file name', pkg.fn),
        ('name', pkg.name),
        ('version', pkg.version),
        ('build number', pkg.build_number),
        ('build string', pkg.build),
        ('channel', config.canonical_channel_name(pkg.channel)),
        ('size', human_bytes(pkg.info['size'])),
    ])
    rest = pkg.info.copy()
    for key in sorted(rest):
        if key in [
                'build', 'depends', 'requires', 'channel', 'name', 'version',
                'build_number', 'size'
        ]:
            continue
        d[key] = rest[key]

    print()
    header = "%s %s %s" % (d['name'], d['version'], d['build string'])
    print(header)
    print('-' * len(header))
    for key in d:
        print("%-12s: %s" % (key, d[key]))
    print("installed environments:")
    for env in app_is_installed(pkg.fn):
        print('    %s' % env)
    print('dependencies:')
    for dep in pkg.info['depends']:
        print('    %s' % dep)
Ejemplo n.º 5
0
def execute(args, parser):
    from conda import config
    from conda.api import get_package_versions, app_is_installed
    from conda.install import is_linked

    if args.args:
        results = defaultdict(list)

        for arg in args.args:
            if isfile(arg):
                from conda.misc import which_package
                path = arg
                for dist in which_package(path):
                    if args.json:
                        results[arg].append(dist)
                    else:
                        print('%-50s  %s' % (path, dist))
            elif arg.endswith('.tar.bz2'):
                info = is_linked(config.root_dir, arg[:-8])
                if not info:
                    if args.json:
                        results[arg] = {
                            'installed': []
                        }
                    else:
                        print("Package %s is not installed" % arg)

                    continue

                info['installed'] = app_is_installed(arg)
                if args.json:
                    results[arg] = info
                else:
                    print(arg)
                    print('    %-15s %30s' %
                               ('installed', bool(info.get('installed'))))

                    for key in ('name', 'version', 'build', 'license',
                                'platform', 'arch', 'size', 'summary'):
                        print('    %-15s %30s' % (key, info.get(key)))
            else:
                if args.json:
                    for pkg in get_package_versions(arg):
                        results[arg].append(pkg._asdict())
                else:
                    show_pkg_info(arg)

        if args.json:
            common.stdout_json(results)
        return

    import os
    from os.path import basename, dirname, isdir, join

    import conda
    import conda.config as config
    from conda.cli.main_init import is_initialized

    options = 'envs', 'system', 'license'

    info_dict = dict(platform=config.subdir,
                     conda_version=conda.__version__,
                     root_prefix=config.root_dir,
                     root_writable=config.root_writable,
                     pkgs_dirs=config.pkgs_dirs,
                     envs_dirs=config.envs_dirs,
                     default_prefix=config.default_prefix,
                     channels=config.get_channel_urls(),
                     rc_path=config.rc_path,
                     is_foreign=bool(config.foreign),
                     envs=[],
                     python_version='.'.join(map(str, sys.version_info)),
    )

    if args.all or args.json:
        for option in options:
            setattr(args, option, True)

    t_pat = re.compile(r'binstar\.org/(t/[0-9a-f\-]{4,})')
    info_dict['channels_disp'] = [t_pat.sub('binstar.org/t/<TOKEN>', c)
                                  for c in info_dict['channels']]

    if args.all or all(not getattr(args, opt) for opt in options):
        for key in 'pkgs_dirs', 'envs_dirs', 'channels_disp':
            info_dict['_' + key] = ('\n' + 24 * ' ').join(info_dict[key])
        info_dict['_rtwro'] = ('writable' if info_dict['root_writable'] else
                               'read only')
        print("""\
Current conda install:

             platform : %(platform)s
        conda version : %(conda_version)s
       python version : %(python_version)s
     root environment : %(root_prefix)s  (%(_rtwro)s)
  default environment : %(default_prefix)s
     envs directories : %(_envs_dirs)s
        package cache : %(_pkgs_dirs)s
         channel URLs : %(_channels_disp)s
          config file : %(rc_path)s
    is foreign system : %(is_foreign)s
""" % info_dict)
        if not is_initialized():
            print("""\
# NOTE:
#     root directory '%s' uninitalized,
#     use 'conda init' to initialize.""" % config.root_dir)

    del info_dict['channels_disp']

    if args.envs:
        if not args.json:
            print("# conda environments:")
            print("#")
        def disp_env(prefix):
            fmt = '%-20s  %s  %s'
            default = '*' if prefix == config.default_prefix else ' '
            name = (config.root_env_name if prefix == config.root_dir else
                    basename(prefix))
            if not args.json:
                print(fmt % (name, default, prefix))

        for envs_dir in config.envs_dirs:
            if not isdir(envs_dir):
                continue
            for dn in sorted(os.listdir(envs_dir)):
                if dn.startswith('.'):
                    continue
                prefix = join(envs_dir, dn)
                if isdir(prefix):
                    prefix = join(envs_dir, dn)
                    disp_env(prefix)
                    info_dict['envs'].append(prefix)
        disp_env(config.root_dir)
        print()

    if args.system and not args.json:
        from conda.cli.find_commands import find_commands, find_executable

        print("sys.version: %s..." % (sys.version[:40]))
        print("sys.prefix: %s" % sys.prefix)
        print("sys.executable: %s" % sys.executable)
        print("conda location: %s" % dirname(conda.__file__))
        for cmd in sorted(set(find_commands() + ['build'])):
            print("conda-%s: %s" % (cmd, find_executable(cmd)))
        print()

        evars = ['PATH', 'PYTHONPATH', 'PYTHONHOME', 'CONDA_DEFAULT_ENV',
                 'CIO_TEST', 'CONDA_ENVS_PATH']
        if config.platform == 'linux':
            evars.append('LD_LIBRARY_PATH')
        elif config.platform == 'osx':
            evars.append('DYLD_LIBRARY_PATH')
        for ev in sorted(evars):
            print("%s: %s" % (ev, os.getenv(ev, '<not set>')))
        print()

    if args.license and not args.json:
        try:
            from _license import show_info
            show_info()
        except ImportError:
            print("""\
WARNING: could import _license.show_info
# try:
# $ conda install -n root _license""")

    if args.json:
        common.stdout_json(info_dict)
Ejemplo n.º 6
0
def execute(args, parser):
    import os
    from os.path import basename, dirname

    import conda
    import conda.config as config
    import conda.misc as misc
    from conda.cli.main_init import is_initialized
    from conda.api import get_package_versions, app_is_installed
    from conda.install import is_linked

    if args.args:
        results = defaultdict(list)

        for arg in args.args:
            if isfile(arg):
                from conda.misc import which_package
                path = arg
                for dist in which_package(path):
                    if args.json:
                        results[arg].append(dist)
                    else:
                        print('%-50s  %s' % (path, dist))
            elif arg.endswith('.tar.bz2'):
                info = None
                for prefix in misc.list_prefixes():
                    info = is_linked(prefix, arg[:-8])
                    if info:
                        break

                if not info:
                    if args.json:
                        results[arg] = {'installed': []}
                    else:
                        print("Package %s is not installed" % arg)

                    continue

                info['installed'] = app_is_installed(arg)
                if args.json:
                    results[arg] = info
                else:
                    print(arg)
                    print('    %-15s %30s' %
                          ('installed', bool(info.get('installed'))))

                    for key in ('name', 'version', 'build', 'license',
                                'platform', 'arch', 'size', 'summary'):
                        print('    %-15s %30s' % (key, info.get(key)))
            else:
                if args.json:
                    for pkg in get_package_versions(arg):
                        results[arg].append(pkg._asdict())
                else:
                    show_pkg_info(arg)

        if args.json:
            common.stdout_json(results)
        return

    options = 'envs', 'system', 'license'

    try:
        import requests
        requests_version = requests.__version__
    except ImportError:
        requests_version = "could not import"
    except Exception as e:
        requests_version = "Error %s" % e

    try:
        import conda_build
    except ImportError:
        conda_build_version = "not installed"
    except Exception as e:
        conda_build_version = "Error %s" % e
    else:
        conda_build_version = conda_build.__version__

    info_dict = dict(
        platform=config.subdir,
        conda_version=conda.__version__,
        conda_build_version=conda_build_version,
        root_prefix=config.root_dir,
        root_writable=config.root_writable,
        pkgs_dirs=config.pkgs_dirs,
        envs_dirs=config.envs_dirs,
        default_prefix=config.default_prefix,
        channels=config.get_channel_urls(),
        rc_path=config.rc_path,
        is_foreign=bool(config.foreign),
        envs=[],
        python_version='.'.join(map(str, sys.version_info)),
        requests_version=requests_version,
    )

    if args.all or args.json:
        for option in options:
            setattr(args, option, True)

    info_dict['channels_disp'] = [
        config.hide_binstar_tokens(c) for c in info_dict['channels']
    ]

    if args.all or all(not getattr(args, opt) for opt in options):
        for key in 'pkgs_dirs', 'envs_dirs', 'channels_disp':
            info_dict['_' + key] = ('\n' + 24 * ' ').join(info_dict[key])
        info_dict['_rtwro'] = ('writable'
                               if info_dict['root_writable'] else 'read only')
        print("""\
Current conda install:

             platform : %(platform)s
        conda version : %(conda_version)s
  conda-build version : %(conda_build_version)s
       python version : %(python_version)s
     requests version : %(requests_version)s
     root environment : %(root_prefix)s  (%(_rtwro)s)
  default environment : %(default_prefix)s
     envs directories : %(_envs_dirs)s
        package cache : %(_pkgs_dirs)s
         channel URLs : %(_channels_disp)s
          config file : %(rc_path)s
    is foreign system : %(is_foreign)s
""" % info_dict)
        if not is_initialized():
            print("""\
# NOTE:
#     root directory '%s' uninitalized,
#     use 'conda init' to initialize.""" % config.root_dir)

    del info_dict['channels_disp']

    if args.envs:
        if not args.json:
            print("# conda environments:")
            print("#")

        def disp_env(prefix):
            fmt = '%-20s  %s  %s'
            default = '*' if prefix == config.default_prefix else ' '
            name = (config.root_env_name
                    if prefix == config.root_dir else basename(prefix))
            if not args.json:
                print(fmt % (name, default, prefix))

        for prefix in misc.list_prefixes():
            disp_env(prefix)
            if prefix != config.root_dir:
                info_dict['envs'].append(prefix)

        print()

    if args.system and not args.json:
        from conda.cli.find_commands import find_commands, find_executable

        print("sys.version: %s..." % (sys.version[:40]))
        print("sys.prefix: %s" % sys.prefix)
        print("sys.executable: %s" % sys.executable)
        print("conda location: %s" % dirname(conda.__file__))
        for cmd in sorted(set(find_commands() + ['build'])):
            print("conda-%s: %s" % (cmd, find_executable(cmd)))
        print("user site dirs: ", end='')
        site_dirs = get_user_site()
        if site_dirs:
            print(site_dirs[0])
        else:
            print()
        for site_dir in site_dirs[1:]:
            print('                %s' % site_dir)
        print()

        evars = [
            'PATH', 'PYTHONPATH', 'PYTHONHOME', 'CONDA_DEFAULT_ENV',
            'CIO_TEST', 'CONDA_ENVS_PATH'
        ]
        if config.platform == 'linux':
            evars.append('LD_LIBRARY_PATH')
        elif config.platform == 'osx':
            evars.append('DYLD_LIBRARY_PATH')
        for ev in sorted(evars):
            print("%s: %s" % (ev, os.getenv(ev, '<not set>')))
        print()

    if args.license and not args.json:
        try:
            from _license import show_info
            show_info()
        except ImportError:
            print("""\
WARNING: could import _license.show_info
# try:
# $ conda install -n root _license""")

    if args.json:
        common.stdout_json(info_dict)