Created
November 18, 2010 03:27
pip command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pkg_resources | |
import xmlrpclib | |
import pip | |
import pip.download | |
from pip.log import logger | |
from pip.basecommand import Command | |
from pip.util import get_installed_distributions | |
from pip.commands.search import transform_hits, compare_versions, highest_version | |
class OutdatedCommand(Command): | |
name = 'outdated' | |
usage = '%prog' | |
summary = 'check updated packages' | |
def __init__(self): | |
super(OutdatedCommand, self).__init__() | |
def run(self, options, args): | |
index_url = 'http://pypi.python.org/pypi' | |
for dist in get_installed_distributions(local_only=True): | |
pypi_hits = self.search(dist.key, index_url) | |
hits = transform_hits(pypi_hits) | |
print_results(hits) | |
def search(self, query, index_url): | |
pypi = xmlrpclib.ServerProxy(index_url, pip.download.xmlrpclib_transport) | |
hits = pypi.search({'name': query}) | |
return hits | |
def print_results(hits): | |
installed_packages = [p.project_name for p in pkg_resources.working_set] | |
for hit in hits: | |
name = hit['name'] | |
try: | |
if name in installed_packages: | |
dist = pkg_resources.get_distribution(name) | |
try: | |
latest = highest_version(hit['versions']) | |
if dist.version < latest: | |
logger.notify('%s: %s => %s' % (name, dist.version, latest)) | |
finally: | |
pass | |
except UnicodeEncodeError: | |
pass | |
OutdatedCommand() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment