Skip to content

Instantly share code, notes, and snippets.

@wenLiangcan wenLiangcan/pyv.py
Created Jul 18, 2014

Embed
What would you like to do?
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
You can’t perform that action at this time.