いつの間にか yolk がお亡くなりになってて微妙に不便だったから、コピペででっちあげた。
パッケージの名前渡したらヴァージョンチェックしてくれるメソッド用意されてると思ったんだけど、無いくさいからいちいち検索してるのがちょっとアレ。
でもまぁ、いいと思います!
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()