2011-03-04 2 views
2

easy_install을 통해 설치된 모든 Python 라이브러리에 대한 최신 버전을 제공하는 보고서를 쉽게 얻을 수 있습니까? 새로운 라이브러리가 역 호환이 아닌 변경을 할 수 있으므로 알려진 설치 라이브러리 목록에서 easy_install을 다시 실행하기를 원하지 않습니다. 목록을 가져와 변경된 사항을 신속하게 확인하고 충돌 가능성이있는 모든 변경 사항을 확인할 수있는 새 릴리스를 검사하고 싶습니다.Python Easy_Install 업데이트 보고서

답변

5

다음은 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의 최대을) 사용할 수있는 최신 버전을 표시 조정할을 사용자 정의 할 수 있습니다
관련 문제