Skip to content

Instantly share code, notes, and snippets.

@thehadeeryounis
Created August 3, 2012 04:26
Show Gist options
  • Save thehadeeryounis/3244354 to your computer and use it in GitHub Desktop.
Save thehadeeryounis/3244354 to your computer and use it in GitHub Desktop.
pip auto upgrade
#!/usr/bin/env python
import xmlrpclib
import pip
#import pip.commands.install
from subprocess import call
#def install_distributions(distributions):
# command = pip.commands.install.InstallCommand()
# opts, args = command.parser.parse_args()
# requirement_set = command.run(opts, distributions)
# requirement_set = command.run(opts, distributions)
# requirement_set.install(opts)
pypi = xmlrpclib.ServerProxy('http://pypi.python.org/pypi')
#dists = []
for dist in pip.get_installed_distributions():
available = pypi.package_releases(dist.project_name)
if not available:
# Try to capitalize pkg name
available = pypi.package_releases(dist.project_name.capitalize())
if not available:
msg = 'no releases at pypi'
elif available[0] != dist.version:
msg = '{} available'.format(available[0])
# dists.append(dist.project_name)
call(["sudo","pip", "install", "-U", dist.project_name])
else:
msg = 'up to date'
pkg_info = '{dist.project_name} {dist.version}'.format(dist=dist)
print '{pkg_info:40} {msg}'.format(pkg_info=pkg_info, msg=msg)
#print '---------------------------------------------------------------'
#print 'Will now install:'
#install_distributions(dists)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment