다음은 easy-install.pth
파일을 스캔하고 설치된 최신 버전의 목록을 인쇄하는 빠른 스크립트입니다.
#!/usr/bin/env python
import os, sys
from distutils import sysconfig
from pkg_resources import Requirement
from setuptools.package_index import PackageIndex
index = PackageIndex()
root = sysconfig.get_python_lib()
path = os.path.join(root, 'easy-install.pth')
if not os.path.exists(path):
sys.exit(1)
for line in open(path, 'rb'):
if line.startswith('import sys'):
continue
path = os.path.join(root, line.strip(), 'EGG-INFO', 'PKG-INFO')
if not os.path.exists(path):
continue
lines = [r.split(':', 1) for r in open(path, 'rb').readlines() if ':' in r]
info = dict((k.strip(), v.strip()) for k, v in lines)
print '%s %s updates..' % (info['Name'], info['Version'])
spec = Requirement.parse(info['Name'] + '>' + info['Version'])
index.find_packages(spec)
versions = set([
(d.parsed_version, d.version) for d in index[spec.key] if d in spec
])
if versions:
for _, version in sorted(versions):
print '\t', version
else:
print '\tnone'
사용법 :
% easy_install networkx==1.3
% easy_install gdata==2.0.5
% ./pkgreport
networkx 1.3 updates..
1.4rc1
1.4
gdata 2.0.5 updates..
2.0.6
2.0.7
2.0.8
2.0.9
2.0.14
만 출력 형식, 등, (
parsed_version
의 최대을) 사용할 수있는 최신 버전을 표시 조정할을 사용자 정의 할 수 있습니다