mirror of
https://github.com/openSUSE/osc.git
synced 2025-01-13 17:16:23 +01:00
- get rid of rpm-python:
* so far it was only used for querying rpms which can be done with the rpmquery module - core.py: * removed data_from_rpm() and tag_to_rpmpy() methods - util/rpmquery.py: * added staticmethod "query()" - commandline.py, fetch.py: * use rpmquery module instead of rpm-python/data_from_rpm()
This commit is contained in:
parent
221fe84d1a
commit
cb16432cd9
@ -3171,6 +3171,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
||||
${cmd_option_list}
|
||||
"""
|
||||
import glob
|
||||
from util import rpmquery
|
||||
|
||||
if opts.delete_old_files and conf.config['do_package_tracking']:
|
||||
# IMHO the --delete-old-files option doesn't really fit into our
|
||||
@ -3200,11 +3201,10 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
||||
else:
|
||||
project = store_read_project(project_dir)
|
||||
|
||||
rpm_data = data_from_rpm(srpm, 'Name:', 'Summary:', '%description', 'Url:')
|
||||
if rpm_data:
|
||||
title, pac, descr, url = ( v for k, v in rpm_data.iteritems() )
|
||||
else:
|
||||
title = pac = descr = url = ''
|
||||
rpmq = rpmquery.RpmQuery.query(srpm)
|
||||
title, pac, descr, url = rpmq.summary(), rpmq.name(), rpmq.description(), rpmq.url()
|
||||
if url is None:
|
||||
url = ''
|
||||
|
||||
if opts.title:
|
||||
title = opts.title
|
||||
|
52
osc/core.py
52
osc/core.py
@ -3902,58 +3902,6 @@ def unpack_srcrpm(srpm, dir, *files):
|
||||
sys.exit(1)
|
||||
os.chdir(curdir)
|
||||
|
||||
def tag_to_rpmpy(tag):
|
||||
"""
|
||||
maps a spec file tag/section to a valid
|
||||
rpm-python RPMTAG
|
||||
"""
|
||||
|
||||
try:
|
||||
import rpm
|
||||
tags = { 'Name:' : rpm.RPMTAG_NAME,
|
||||
'Version:' : rpm.RPMTAG_VERSION,
|
||||
'Release:' : rpm.RPMTAG_RELEASE,
|
||||
'Arch:' : rpm.RPMTAG_ARCH,
|
||||
'SourceRPM:' : rpm.RPMTAG_SOURCERPM,
|
||||
'NoSource:' : 1051,
|
||||
'NoPatch:' : 1052,
|
||||
'Summary:' : rpm.RPMTAG_SUMMARY,
|
||||
'%description' : rpm.RPMTAG_DESCRIPTION,
|
||||
'Url:' : rpm.RPMTAG_URL
|
||||
}
|
||||
if tag in tags.keys():
|
||||
return tags[tag]
|
||||
else:
|
||||
return None
|
||||
except ImportError:
|
||||
return None
|
||||
|
||||
def data_from_rpm(rpm_file, *rpmdata):
|
||||
"""
|
||||
This method reads the given rpmdata
|
||||
from a rpm.
|
||||
"""
|
||||
|
||||
try:
|
||||
import rpm
|
||||
ts = rpm.TransactionSet()
|
||||
ts.setVSFlags(rpm._RPMVSF_NOSIGNATURES)
|
||||
file = open(rpm_file, 'rb')
|
||||
header = ts.hdrFromFdno(file.fileno())
|
||||
file.close()
|
||||
data = {}
|
||||
for itm in rpmdata:
|
||||
rpmpy = tag_to_rpmpy(itm)
|
||||
if rpmpy:
|
||||
data[itm] = header[rpmpy]
|
||||
else:
|
||||
print >>sys.stderr, 'invalid data \'%s\'' % itm
|
||||
sys.exit(1)
|
||||
return data
|
||||
except ImportError:
|
||||
print >>sys.stderr, 'warning: rpm-python not found'
|
||||
return None
|
||||
|
||||
def is_rpm(f):
|
||||
"""check if the named file is an RPM package"""
|
||||
try:
|
||||
|
27
osc/fetch.py
27
osc/fetch.py
@ -7,7 +7,7 @@ import sys, os
|
||||
import urllib2
|
||||
from urlgrabber.grabber import URLGrabber, URLGrabError
|
||||
from urlgrabber.mirror import MirrorGroup
|
||||
from core import data_from_rpm
|
||||
from util import rpmquery
|
||||
try:
|
||||
from meter import TextMeter
|
||||
except:
|
||||
@ -90,18 +90,19 @@ class Fetcher:
|
||||
sys.exit(1)
|
||||
|
||||
if pac.partname.endswith('.rpm.part'):
|
||||
rpm_data = data_from_rpm(pac.fullpartname, 'Name:', 'Version:', 'Release:', 'Arch:', 'SourceRPM:', 'NoSource:', 'NoPatch:')
|
||||
if rpm_data:
|
||||
arch = rpm_data['Arch:']
|
||||
if not rpm_data['SourceRPM:']:
|
||||
if rpm_data['NoSource:'] or rpm_data['NoPatch:']:
|
||||
arch = "nosrc"
|
||||
else:
|
||||
arch = "src"
|
||||
canonname = "%s-%s-%s.%s.rpm" % (rpm_data['Name:'], rpm_data['Version:'], rpm_data['Release:'], arch)
|
||||
head, tail = os.path.split(pac.fullfilename)
|
||||
pac.filename = canonname
|
||||
pac.fullfilename = os.path.join(head, canonname)
|
||||
rpmq = rpmquery.RpmQuery.query(pac.fullpartname)
|
||||
arch = rpmq.arch()
|
||||
# SOURCERPM = 1044
|
||||
if not rpmq.getTag(1044):
|
||||
# NOSOURCE = 1051, NOPATCH = 1052
|
||||
if rpmq.getTag(1051) or rpmq.getTag(1052):
|
||||
arch = "nosrc"
|
||||
else:
|
||||
arch = "src"
|
||||
canonname = "%s-%s-%s.%s.rpm" % (rpmq.name(), rpmq.version(), rpmq.release(), arch)
|
||||
head, tail = os.path.split(pac.fullfilename)
|
||||
pac.filename = canonname
|
||||
pac.fullfilename = os.path.join(head, canonname)
|
||||
|
||||
os.rename(pac.fullpartname, pac.fullfilename);
|
||||
|
||||
|
@ -188,9 +188,17 @@ class RpmQuery():
|
||||
def requires(self):
|
||||
return self.__reqprov(1049, 1048, 1050)
|
||||
|
||||
def getTag(num):
|
||||
def getTag(self, num):
|
||||
return self.header.getTag(num)
|
||||
|
||||
@staticmethod
|
||||
def query(filename):
|
||||
f = open(filename, 'rb')
|
||||
rpmq = RpmQuery(f)
|
||||
rpmq.read()
|
||||
f.close()
|
||||
return rpmq
|
||||
|
||||
def unpack_string(data):
|
||||
"""unpack a '\\0' terminated string from data"""
|
||||
val = ''
|
||||
@ -203,13 +211,10 @@ def unpack_string(data):
|
||||
return val
|
||||
|
||||
if __name__ == '__main__':
|
||||
f = open(sys.argv[1], 'rb')
|
||||
rpmq = RpmQuery(f)
|
||||
try:
|
||||
rpmq.read()
|
||||
rpmq = RpmQuery.query(sys.argv[1])
|
||||
except RpmError, e:
|
||||
print e.msg
|
||||
f.close()
|
||||
print rpmq.name(), rpmq.version(), rpmq.release(), rpmq.arch(), rpmq.url()
|
||||
print rpmq.summary()
|
||||
print rpmq.description()
|
||||
|
Loading…
Reference in New Issue
Block a user