Esempio n. 1
0
def test_version_compare():
    """
    Test version comparison.

    """
    assert highest_version(["1.0", "2.0", "0.1"]) == "2.0"
    assert highest_version(["1.0a1", "1.0"]) == "1.0"
Esempio n. 2
0
def test_version_compare():
    """
    Test version comparison.

    """
    assert highest_version(['1.0', '2.0', '0.1']) == '2.0'
    assert highest_version(['1.0a1', '1.0']) == '1.0'
Esempio n. 3
0
def test_version_compare():
    """
    Test version comparison.

    """
    assert highest_version(['1.0', '2.0', '0.1']) == '2.0'
    assert highest_version(['1.0a1', '1.0']) == '1.0'
Esempio n. 4
0
def test_version_compare():
    """
    Test version comparison.

    """
    assert compare_versions('1.0', '1.1') == -1
    assert compare_versions('1.1', '1.0') == 1
    assert compare_versions('1.1a1', '1.1') == -1
    assert compare_versions('1.1.1', '1.1a') == -1
    assert highest_version(['1.0', '2.0', '0.1']) == '2.0'
    assert highest_version(['1.0a1', '1.0']) == '1.0'
Esempio n. 5
0
def test_version_compare():
    """
    Test version comparison.

    """
    assert compare_versions('1.0', '1.1') == -1
    assert compare_versions('1.1', '1.0') == 1
    assert compare_versions('1.1a1', '1.1') == -1
    assert compare_versions('1.1.1', '1.1a') == -1
    assert highest_version(['1.0', '2.0', '0.1']) == '2.0'
    assert highest_version(['1.0a1', '1.0']) == '1.0'
Esempio n. 6
0
def print_results(hits, name_column_width=None, terminal_width=None):
	if not hits:
		return
	if name_column_width is None:
		name_column_width = max((len(hit['name']) for hit in hits)) + 4
	installed_packages = [p.project_name for p in pkg_resources.working_set]
	for hit in hits:
		name = hit['name']
		summary = hit['summary'] or ''
		if terminal_width is not None:
			# wrap and indent summary to fit terminal
			summary = textwrap.wrap(summary,terminal_width - name_column_width - 5,)
			summary = ('\n' + ' ' * (name_column_width + 3)).join(summary)
		line = '%s - %s' % (name.ljust(name_column_width), summary)
		try:
			logger.info(line)
			if name in installed_packages:
				dist = pkg_resources.get_distribution(name)
				with indent_log():
					latest = highest_version(hit['versions'])
					if dist.version == latest:
						logger.info('INSTALLED: %s (latest)', dist.version)
					else:
						logger.info('INSTALLED: %s', dist.version)
						logger.info('LATEST:    %s', latest)
		except UnicodeEncodeError:
			pass
Esempio n. 7
0
    def get_search_results(self):
        """
        This code is taken from pip.commands.search.print_results(). It is modified
        to return results in dictionary format instead of printing results
        For all the search results obtained, we can check if a package is already
        installed or not. If installed then the version of installed package is
        found and stored.
        """
        if not hasattr(self, "hits"):
            return None

        # Here pkg_resources is a module of pip._vendor. It has been included
        # in pip gui because as mentioned by pip, this module is considered to
        # be 'immutable'. There are very less chances that it will changed in future
        from pip_tkinter._vendor import pkg_resources
        self.installed_packages = [
            p.project_name for p in pkg_resources.working_set
        ]
        for hit in self.hits:
            hit['latest'] = highest_version(hit['versions'])
            name = hit['name']
            if name in self.installed_packages:
                dist = pkg_resources.get_distribution(name)
                hit['installed'] = dist.version

        return self.hits
Esempio n. 8
0
 def run(self, options, args):
     self.installed_packages = [p.project_name for p in pkg_resources.working_set]
     self.pypi = xmlrpclib.ServerProxy(index_url, pip.download.xmlrpclib_transport)
     packages = set([])
     for dist in get_installed_distributions(local_only=True):
         pypi_hits = self.search(dist.key)
         hits = transform_hits(pypi_hits)
         data = [(i['name'], highest_version(i['versions'])) for i in hits]
         packages = packages.union(set(data))
     self.print_results(packages)
Esempio n. 9
0
def do_version_info(options):
    """
    List all installed packages with his versions and version info from PyPi
    """
    local_only = True # exclude globally-installed packages in a virtualenv
    dependency_links = []
    for dist in pkg_resources.working_set:
        if dist.has_metadata('dependency_links.txt'):
            dependency_links.extend(
                dist.get_metadata_lines('dependency_links.txt'),
            )
    
    installed_info = []
    for dist in get_installed_distributions(local_only=local_only):
        req = dist.as_requirement() # pkg_resources.Requirement() instance
        project_name = req.project_name
        specs = req.specs
        version = specs[0][1]
        installed_info.append((project_name, version))
        
    max_name_len = max([len(i[0]) for i in installed_info])
    max_ver_len = max([len(i[1]) for i in installed_info])
    if max_name_len<20:
        max_name_len = 20
    if max_ver_len<20:
        max_ver_len = 20
    max_len_others = get_terminal_size()[0] - max_name_len - max_ver_len - 7    
    
    table_header = " package name".ljust(max_name_len)
    table_header += " installed version".ljust(max_ver_len)
    table_header += "  versions on PyPi".ljust(max_len_others)
    print c.colorize(table_header, opts=("underscore",))
    
    for project_name, version in installed_info:
        print project_name.ljust(max_name_len),
        print version.ljust(max_ver_len),
               
        # http://wiki.python.org/moin/PyPiXmlRpc
        client = xmlrpclib.ServerProxy(INDEX_URL)
        versions = client.package_releases(project_name)
        
        if not versions:
            print c.colorize("No version found at PyPi!", foreground="yellow")
        else:
            latest = highest_version(versions)
            older_versions = [v for v in versions if latest!=v]
            pypi_info = "%s" % latest
            if older_versions:
                pypi_info += " - %s" % ", ".join(older_versions)

            if len(pypi_info)>max_len_others:
                pypi_info = pypi_info[:max_len_others] + " ..."
            
            print pypi_info
Esempio n. 10
0
def _transform_hits(hits):
	"""
	The list from pypi is really a list of versions. We want a list of
	packages with the list of versions stored inline. This converts the
	list from pypi into one we can use.
	"""
	packages = {}
	for hit in hits:
		name = hit['name']
		summary = hit['summary']
		version = hit['version']
		score = hit['_pypi_ordering']
		if score is None:
			score = 0

		if name not in packages.keys():
			packages[name] = {
				'name'    : name,
				'summary' : summary,
				'versions': [version],
				'score'   : score,
			}
		else:
			packages[name]['versions'].append(version)

			# if this is the highest version, replace summary and score
			if version == highest_version(packages[name]['versions']):
				packages[name]['summary'] = summary
				packages[name]['score'] = score


		packages[name]['version'] = highest_version(packages[name]['versions'])
	# each record has a unique name now, so we will convert the dict into a
	# list sorted by score
	package_list = sorted(
		packages.items(),
		key=lambda x: x['score'],
		reverse=True,
	)
	return package_list
Esempio n. 11
0
def browse(request):
    import pkg_resources
    from pip.commands.search import highest_version, transform_hits
    from pip.util import get_installed_distributions

    import xmlrpclib

    pypi = xmlrpclib.ServerProxy('http://pypi.python.org/pypi')
    installed_packages = [p.project_name for p in pkg_resources.working_set]

    results = []
    for p in get_installed_distributions():
        result = {}
        hits = pypi.search({
            'name': p.project_name,
            'summary': p.project_name
        }, 'or')
        hits = transform_hits(hits)
        for hit in hits:
            try:
                if hit['name'] in installed_packages:
                    dist = pkg_resources.get_distribution(hit['name'])
                    result['name'] = hit['name']
                    result['version'] = dist.version
                    result['summary'] = hit['summary'] or ''
                    try:
                        result['latest'] = highest_version(hit['versions'])
                    finally:
                        results.append(result)
            except UnicodeEncodeError:
                pass

    query = request.GET.copy()

    return render_to_response(
        'djip/index.html',
        {
            'results': results,
            #'dir': path,
            #'p': p,
            #'q': q,
            #'page': page,
            #'results_var': results_var,
            #'counter': counter,
            'query': query,
            'title': _(u'PIP browser'),
            #'settings_var': get_settings_var(),
            #'breadcrumbs': get_breadcrumbs(query, path),
            'breadcrumbs_title': ""
        },
        context_instance=RequestContext(request))
Esempio n. 12
0
File: views.py Progetto: Axion/DjIP
def browse(request):
    import pkg_resources
    from pip.commands.search import highest_version, transform_hits
    from pip.util import get_installed_distributions

    import xmlrpclib

    pypi = xmlrpclib.ServerProxy('http://pypi.python.org/pypi')
    installed_packages = [p.project_name for p in pkg_resources.working_set]

    results = []
    for p in get_installed_distributions():
        result = {}
        hits = pypi.search({'name': p.project_name, 'summary': p.project_name}, 'or')
        hits = transform_hits(hits)
        for hit in hits:
            try:
                if hit['name'] in installed_packages:
                    dist = pkg_resources.get_distribution(hit['name'])
                    result['name'] = hit['name']
                    result['version'] = dist.version
                    result['summary'] = hit['summary'] or ''
                    try:
                        result['latest'] = highest_version(hit['versions'])
                    finally:
                        results.append(result)
            except UnicodeEncodeError:
                pass


    query = request.GET.copy()

    return render_to_response('djip/index.html', {
        'results': results,
        #'dir': path,
        #'p': p,
        #'q': q,
        #'page': page,
        #'results_var': results_var,
        #'counter': counter,
        'query': query,
        'title': _(u'PIP browser'),
        #'settings_var': get_settings_var(),
        #'breadcrumbs': get_breadcrumbs(query, path),
        'breadcrumbs_title': ""
    }, context_instance=RequestContext(request))
Esempio n. 13
0
    def run(self):
        pkg_name = self.distribution.get_name()
        pkg_version = self.distribution.get_version()
        search = SearchCommand()
        options, _ = search.parse_args([pkg_name])
        pypi_hits = search.search(pkg_name, options)
        hits = transform_hits(pypi_hits)

        remote_version = None
        for hit in hits:
            if hit['name'] == pkg_name:
                remote_version = highest_version(hit['versions'])
                self.announce("Found %s version %s on PyPi" % (pkg_name, remote_version), log.INFO)
        if remote_version is None:
            raise RuntimeError("Could not found %s on PyPi" % pkg_name)
        if StrictVersion(VERSION) <= StrictVersion(remote_version):
            raise VersionError("Local version %s not greater than PyPi version %s" % (pkg_version, remote_version))
        self.announce("Local version %s higher than PyPi version" % pkg_version)
Esempio n. 14
0
	def simple_search(self, spec, operator='or', getter = None, omit = ('django')):
		"""Can search by name, version, author, author_email, maintainer,
		maintainer_email, home_page, license, summary,
		description, keywords, platform,download_url"""
		from pip.commands.search import transform_hits, highest_version
		from
		results = set()
		packages = {}
		from operator import itemgetter
		filter = itemgetter('name', 'version')
		info_getter = itemgetter('name', 'summary')
		name_getter = itemgetter('name')

		hits = self.proxy.search({'name': spec},{'summary':spec}, operator)
		results = transform_hits(hits)
		for result in results:
			result['version'] = highest_version(result['versions'])
			del result['score']
		return results
Esempio n. 15
0
 def print_results(self, hits):
     from pip.commands.search import highest_version
     installed_packages = [p.project_name for p in pkg_resources.working_set]
     for hit in hits:
         name = hit['name']
         summary = hit['summary'] or ''
         try:
             if name in installed_packages:
                 print name,
                 dist = pkg_resources.get_distribution(name)
                 try:
                     latest = highest_version(hit['versions'])
                     if dist.version == latest:
                         print 'version: %s (latest)' % dist.version
                     else:
                         print 'version: %s, LATEST %s' % (dist.version, latest)
                 finally:
                     pass
         except UnicodeEncodeError:
             pass
Esempio n. 16
0
    def run(self, options, args):
        local_only = options.local
        index_url = options.index

        installations = {}
        dependency_links = []
        find_tags = False

        f = sys.stdout

        for dist in pkg_resources.working_set:
            if dist.has_metadata('dependency_links.txt'):
                dependency_links.extend(
                    dist.get_metadata_lines('dependency_links.txt'), )

        for dist in get_installed_distributions(local_only=local_only):
            req = pip.FrozenRequirement.from_dist(
                dist,
                dependency_links,
                find_tags=find_tags,
            )
            installations[req.name] = req

        pypi_hits = self.search(
            [i.name for i in installations.values()],
            index_url,
        )
        hits = transform_hits(pypi_hits)

        for hit in hits:
            name = hit['name']
            try:
                if name in installations:
                    req = installations[name].req
                    latest = highest_version(hit['versions'])
                    if req.specs[0][1] != latest:
                        f.write('%s (LATEST: %s)\n' % (str(req), latest))

            except UnicodeEncodeError:
                pass
Esempio n. 17
0
    def run(self, options, args):
        local_only = options.local
        index_url = options.index

        installations = {}
        dependency_links = []
        find_tags = False

        f = sys.stdout

        for dist in pkg_resources.working_set:
            if dist.has_metadata('dependency_links.txt'):
                dependency_links.extend(
                    dist.get_metadata_lines('dependency_links.txt'),
                )

        for dist in get_installed_distributions(local_only=local_only):
            req = pip.FrozenRequirement.from_dist(
                dist, dependency_links, find_tags=find_tags,
            )
            installations[req.name] = req

        pypi_hits = self.search(
            [i.name for i in installations.values()],
            index_url,
        )
        hits = transform_hits(pypi_hits)

        for hit in hits:
            name = hit['name']
            try:
                if name in installations:
                    req = installations[name].req
                    latest = highest_version(hit['versions'])
                    if req.specs[0][1] != latest:
                        f.write('%s (LATEST: %s)\n' % (str(req), latest))

            except UnicodeEncodeError:
                pass
Esempio n. 18
0
    def get_search_results(self):
        """
        This code is taken from pip.commands.search.print_results(). It is modified
        to return results in dictionary format instead of printing results
        For all the search results obtained, we can check if a package is already
        installed or not. If installed then the version of installed package is
        found and stored.
        """
        if not hasattr(self, "hits"):
            return None

        # Here pkg_resources is a module of pip._vendor. It has been included
        # in pip gui because as mentioned by pip, this module is considered to
        # be 'immutable'. There are very less chances that it will changed in future
        from pip_tkinter._vendor import pkg_resources
        self.installed_packages = [p.project_name for p in pkg_resources.working_set]
        for hit in self.hits:
            hit['latest'] = highest_version(hit['versions'])
            name = hit['name']
            if name in self.installed_packages:
                dist = pkg_resources.get_distribution(name)
                hit['installed'] = dist.version

        return self.hits
Esempio n. 19
0
def print_results(hits, name_column_width=25, terminal_width=None):
    installed_packages = [p.project_name for p in pkg_resources.working_set]
    for hit in hits:
        name = hit['name']
        summary = hit['summary'] or ''
        if terminal_width is not None:
            # wrap and indent summary to fit terminal
            summary = textwrap.wrap(summary, terminal_width - name_column_width - 5)
            summary = ('\n' + ' ' * (name_column_width + 3)).join(summary)
        line = '%s - %s' % (name.ljust(name_column_width), summary)
        try:
            print (line)
            dist = pkg_resources.get_distribution(name) if name in installed_packages else None
            try:
                latest = highest_version(hit['versions'])
                if dist and dist.version == latest:
                    print '  INSTALLED: %s (latest)' % dist.version
                else:
                    print '  INSTALLED: %s' % "0.0.0"
                    print '  LATEST:    %s' % latest
            finally:
                pass
        except UnicodeEncodeError:
            pass