2013-01-22 2 views
1

rpm 모듈은 rpm 패키지 정보를 검색 할 때만 사용할 수 있습니다. rpm 모듈을 사용하면 python rpm 모듈을 사용하여 폴더의 * .rpm 파일을 검색하고 해당 정보를 알 수 있습니다. 릴리스 또는 버전. rpm 모듈을 사용하면 가능합니까?파이썬에서 rpm 모듈에 관한 정보

+0

내가 모든 Python으로 작성 yum''꽤 확신을 참조하십시오. 파이썬 RPM 라이브러리가 기본적으로 설치되어 있다고 생각합니다. (지금은 윈도우즈 박스에서 죄송합니다.) –

답변

0

내가 아는 한 방법이 없습니다. 당신의 가장 쉬운 좋은 방법은 데이터

subprocess.check_output(["rpm", "-qip", "CentOS_Image/Packages/python-2.6.6-29.el6_2.2.x86_64.rpm" ]) 

'Name  : python\nVersion  : 2.6.6\nRelease  : 29.el6_2.2\nArchitecture: x86_64\nInstall Date: (not installed)\nGroup  : Development/Languages\nSize  : 21290059\nLicense  : Python\nSignature : RSA/SHA1, Mon 18 Jun 2012 14:47:20 BST, Key ID 0946fca2c105b9de\nSource RPM : python-2.6.6-29.el6_2.2.src.rpm\nBuild Date : Mon 18 Jun 2012 14:21:55 BST\nBuild Host : c6b5.bsys.dev.centos.org\nRelocations : (not relocatable)\nPackager : CentOS BuildSystem <http://bugs.centos.org>\nVendor  : CentOS\nURL   : http://www.python.org/\nSummary  : An interpreted, interactive, object-oriented programming language\nDescription :\nPython is an interpreted, interactive, object-oriented programming\nlanguage often compared to Tcl, Perl, Scheme or Java. Python includes\nmodules, classes, exceptions, very high level dynamic data types and\ndynamic typing. Python supports interfaces to many system calls and\nlibraries, as well as to various windowing systems (X11, Motif, Tk,\nMac and MFC).\n\nProgrammers can write new built-in modules for Python in C or C++.\nPython can be used as an extension language for applications that need\na programmable interface. This package contains most of the standard\nPython modules, as well as modules for interfacing to the Tix widget\nset for Tk and RPM.\n\nNote that documentation for Python is provided in the python-docs\npackage.\n' 
를 검색하는 동안 사람이 아직 여기 끝나는 경우

+1

파싱하기 쉽도록'query-format'을 살펴볼 수 있습니다. –

1

rpm 명령에 직접 전화를하고 구문 분석하는 것입니다 대답은 python-rpm으로 할 수있는 방법입니다 :

import os 
import rpm 

fdno = os.open(PATH_TO_RPM_FILE, os.O_RDONLY) 
ts = rpm.ts() 
hdr = ts.hdrFromFdno(fdno) 
os.close(fdno) 

(os.close에 대한 호출을 주는())

지금 hdr는 RPM 헤더 정보를 보유하고 있습니다. 당신은 예를 들어, 키로 RPMTAG_의 * 값을 사용하여 DICT 스타일에서 개별 속성에 액세스 할 수 있습니다

arch = hdr[rpm.RPMTAG_ARCH] 

당신은 dir()를 사용하여 가능한 모든 RPMTAG_ * 값을 리버스 엔지니어링 시도 할 수 있습니다 :

import rpm 
print '\n'.join(filter(lambda x: x.startswith('RPMTAG'), dir(rpm))) 

또한 keys()를 호출 할 수 있습니다 hdr에 있지만 가능하지 않은 키가 정수로 반환됩니다.

커맨드 라인 도구를 서브 프로세스로 호출하는 대신 python-rpm을 사용하면 많은 RPM 파일을 처리 할 때 성능이 크게 향상된다는 것을 알게되었습니다. 당신이 체크 아웃 할 수 있도록

자세한 내용

, http://rpm5.org/docs/api/classRpmhdr.html

관련 문제