Пример #1
0
    def do_info(self, subcmd, opts):
        """${cmd_name}: Show version and other diagnostic details

        ${cmd_usage}
        ${cmd_option_list}
        """
        with self.bootstrapped():
            pyenv = python.GlobalPythonEnvironment()

            if not opts.full:
                LOG.info('PyPM {0} ({1[product_type]} {2})'.format(
                    pypm.__version__,
                    activestate.version_info,
                    activestate.version))
                LOG.info('Installation target: {0}'.format(
                    self.pypmenv.pyenv.printable_location))
                LOG.info('(type "pypm info --full" for detailed information)')
            else:  # --full
                LOG.info('PyPM: %s', pypm.__version__)
                LOG.info('ActivePython %s built on %s <%s>',
                         activestate.version,
                         activestate.version_info['build_time'],
                         sys.prefix)
                LOG.info('Installation target: Python %s <%s>',
                         self.pypmenv.pyenv.pyver,
                         self.pypmenv.pyenv.site_packages_dir)
                LOG.info('Platform: %s', PLATNAME)
                LOG.info('Repositories:\n %s', '\n '.join([
                        r.url for r in self.pypmenv.repo_store.repository_list]))
                license_file = licensing.get_license_location()
                LOG.info('Business Edition: %s (%s)',
                         licensing.user_has_be_license(),
                         (P.exists(license_file) and \
                              license_file or \
                              'no license is installed'))
                LOG.info('Config file:\n (current) %s\n (global) %s',
                         self.options.configfile,
                         CONF_FILE_GLOBAL)
                LOG.info('Log file: %s',
                         application.locations.log_file_path)
                LOG.info('Repository cache: %s', IDX_PATH)
                LOG.info('Download cache: %s', DOWNLOAD_CACHE)
                LOG.info('Install database: %s', self.pypmenv.installed_store.storepath)
                import applib, appdirs, sqlalchemy, zclockfile
                LOG.info('Imports:\n %s', '\n '.join([
                            pypm.__file__ + ' (%s)' % pypm.__version__,
                            applib.__file__ + ' (%s)' % applib.__version__,
                            appdirs.__file__ + ' (%s)' % appdirs.__version__,
                            six.__file__ + ' (%s)' % six.__version__,
                            zclockfile.__file__,
                            sqlalchemy.__file__ + ' (%s)' % sqlalchemy.__version__,
                            ]))
        return self.pypmenv
Пример #2
0
    def do_show(self, subcmd, opts, name, version=None):
        """${cmd_name}: Display detailed information about a package

        If the package is already installed, show the location of the
        site-packages directory under which it is installed.
        
        ${cmd_usage}
        ${cmd_option_list}
        """
        with self.bootstrapped():
            self._autosync()
            
            pkg = self.pypmenv.repo_store.find_package(name, version)
            dependencies = pkg.install_requires['']
            extra_dependencies = []
            for extra in pkg.install_requires:
                if extra == '': continue
                extra_dependencies.append('`pypm install {0}[{1}]` ->\n    {2}'.format(
                    pkg.name,
                    extra,
                    ',\n    '.join(pkg.install_requires[extra])))
            
            # Show package metadata
            LOG.info('Name: %s', pkg.name)
            LOG.info('Latest version: %s', pkg.printable_version)
            if pkg.author or pkg.author_email:
                LOG.info('Author: %s %s',
                         pkg.author,
                         pkg.author_email and '<%s>' % pkg.author_email or '')
            LOG.info('Summary: %s', pkg.summary)
            if pkg.home_page:
                LOG.info('Home Page: %s', pkg.home_page)
            if pkg.license:
                LOG.info('License: %s', pkg.license)
            
            # Show package dependencies
            if dependencies:
                LOG.info('Dependencies:')
                for dep in dependencies:
                    LOG.info(' %s', dep)
                if extra_dependencies:
                    LOG.info('Optional dependencies:')
                    for ed in extra_dependencies:
                        LOG.info(' %s', ed)
                        
            # Optionally, show packages depending on it
            if opts.rdepends:
                LOG.info('Depended by:')
                rdependencies = {}
                for rpkg in self.pypmenv.repo_store._query():
                    for req in rpkg.install_requires['']:
                        req = Requirement.parse(req)
                        if pkg.name == req_name(req):
                            if pkg.version in req:
                                prev_rpkg = rdependencies.get(rpkg.name, None)
                                if (not prev_rpkg) or (
                                    rpkg.version_key > prev_rpkg.version_key):
                                        rdependencies[rpkg.name] = rpkg
                if rdependencies:
                    LOG.info(wrapped(
                        ', '.join(sorted(
                            [p.full_name for p in rdependencies.values()])),
                        prefix=' ',
                        break_on_hyphens=False))
            
            # Show list of (older) versions available in the repository
            if not version:
                pkglist = self.pypmenv.repo_store.find_package_releases(name)
                LOG.info('Available versions: %s', ', '.join(
                    [p.printable_version for p in pkglist]))
            
            # Status: is this package installed or not? Does it require BE?
            try:
                ipkg = self.pypmenv.installed_store.find_only_package(name)
            except error.NoPackageInstalled:
                LOG.info('Status: Not installed')
                if pkg.requires_be_license and not licensing.user_has_be_license():
                    LOG.info(
                        'NOTE: This package requires a valid Business Edition '
                        'license. Please visit %s for more details.',
                        licensing.BE_HOME_PAGE)
            else:
                # Is this package installed because another package?
                depgraph = installer.PyPMDepGraph(self.pypmenv)
                required_by = depgraph.edges[ipkg.name].items()
                if required_by:
                    LOG.info('Required by:')
                    for rpkg, rl in required_by:
                        LOG.info(' %s [%s]', rpkg, req2str(*rl))
                    
                LOG.info('Status: Already installed (%s) at %s',
                         ipkg.printable_version,
                         self.pypmenv.pyenv.printable_location)
                # Is a newer version available for upgrade?
                if ipkg.version_key < pkg.version_key:
                    # TODO: Need --force
                    LOG.info('Status: '
                             'A newer version (%s) is available. '
                             'Type "pypm install %s" to upgrade',
                             pkg.printable_version,
                             pkg.name)

            # Show postinstall notes for this package
            for note in pkg.get_notes(postinstall=True):
                LOG.info('***NOTE***: %s', note['content'].strip())
                    
            if opts.open_home_page:
                import webbrowser
                u = 'http://code.activestate.com/pypm/{0}/'.format(pkg.name)
                webbrowser.open(pkg.home_page or u)
                
            return pkg
Пример #3
0
    def do_search(self, subcmd, opts, *keywords):
        """${cmd_name}: Search for a package by name or description

        In the search results, the first column (if available) may show the
        package status marker: 'i' means the package is installed; 'u' means a
        newer version of that package is available.

        If no KEYWORDS are given, all available packages are listed.
        
        ${cmd_usage}
        ${cmd_option_list}
        """
        u = 'http://code.activestate.com/pypm/search:{0}/'.format('+'.join(keywords))
        with self.bootstrapped():
            if opts.web:
                import webbrowser
                webbrowser.open(u)
            else:
                self._autosync()
                
                results = list(self.pypmenv.repo_store.search(*keywords))
                
                # Find the list of installed packages; useful to mark the
                # search results later
                installed = {}
                for pkg in self.pypmenv.installed_store.find_all_packages():
                    installed[pkg.name] = pkg

                # prune duplicates
                verlists = collections.defaultdict(list)
                for pkg in results:
                    verlists[pkg.name].append(pkg)
                for k, verlist in verlists.items():
                    verlist.sort(key=attrgetter('version_key'), reverse=True)
                    
                # prepare what needs to be printed
                output_table = []
                is_be_user = licensing.user_has_be_license()
                print_be_warning = False
                for (name, verlist) in sorted(verlists.items()):
                    pkg = verlist[0] # pick the latest version
                    mark = []
                    
                    # BE mark
                    if pkg.requires_be_license and not is_be_user:
                        mark.append('[BE]')
                        print_be_warning = True
                        
                    # Status mark (installed, upgrade)
                    if pkg.name in installed:
                        available_key = pkg.version_key
                        installed_key = installed[pkg.name].version_key
                        if available_key > installed_key:
                            mark.append('u')
                        else:
                            mark.append('i')
                    
                    output_table.append([
                        ' '.join(mark), name, pkg.summary or ''])
                    
                # If the user is not a BE user and there are BE-only packages
                # in the search results, show the standard BE warning message.
                if print_be_warning:
                    sys.stderr.write((
                        '*** Packages marked [BE] below require a valid \n'
                        '*** Business Edition license to install. Please visit\n'
                        '*** {0} for more details.\n\n').format(
                            licensing.BE_HOME_PAGE))

                if output_table:
                    textui.colprint(output_table)
                else:
                    LOG.warn("no matches found for `%s`; try PyPM Index:\n  %s",
                             ' '.join(keywords), u)
                
                return results