Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@wenLiangcan
Created July 18, 2014 07:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wenLiangcan/10892d3585a4e3508fa2 to your computer and use it in GitHub Desktop.
Save wenLiangcan/10892d3585a4e3508fa2 to your computer and use it in GitHub Desktop.
Find out-of-date modules
import json
from distutils.version import LooseVersion
import pip
try:
from urllib.request import urlopen
except ImportError:
from urllib2 import urlopen
POOLSIZE = 10
def get_sys_list():
return [
(dis.project_name, dis.version)
for dis in pip.get_installed_distributions()
]
def latest_version(package):
url = 'http://pypi.python.org/pypi/{0}/json'.format(package)
try:
return json.loads(
urlopen(url).read().decode('utf-8')
)['info']['version']
except:
return '0'
def isoutdated(cv, lv):
return LooseVersion(cv) < LooseVersion(lv)
def find_outofdate(package):
latest = latest_version(package[0])
if isoutdated(package[1], latest):
print("{0}: {1} ~> {2}".format(package[0], package[1], latest))
def main():
try:
from concurrent.futures import ThreadPoolExecutor
with ThreadPoolExecutor(POOLSIZE) as executor:
for p in get_sys_list():
executor.submit(find_outofdate, p)
except ImportError:
from multiprocessing import Pool
pool = Pool(processes=POOLSIZE)
pool.map(find_outofdate, get_sys_list())
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment