[Yum-devel] [PATCH] createrepo: compress .xml files with 'compress_type'
Zdeněk Pavlas
zpavlas at redhat.com
Mon Nov 5 17:04:29 UTC 2012
Dump metadata to uncompressed files first, then compress with 'compress_type'.
This is more flexible and saves one (two with -d) .xml.gz decompressions.
---
createrepo/__init__.py | 45 +++++++++++++++++++--------------------------
1 files changed, 19 insertions(+), 26 deletions(-)
diff --git a/createrepo/__init__.py b/createrepo/__init__.py
index 8d81136..6dbe992 100644
--- a/createrepo/__init__.py
+++ b/createrepo/__init__.py
@@ -435,11 +435,9 @@ class MetaDataGenerator:
def _setupPrimary(self):
# setup the primary metadata file
- # FIXME - make this be conf.compress_type once y-m-p is fixed
- fpz = self.conf.primaryfile + '.' + 'gz'
primaryfilepath = os.path.join(self.conf.outputdir, self.conf.tempdir,
- fpz)
- fo = compressOpen(primaryfilepath, 'w', 'gz')
+ self.conf.primaryfile)
+ fo = open(primaryfilepath, 'w')
fo.write('<?xml version="1.0" encoding="UTF-8"?>\n')
fo.write('<metadata xmlns="http://linux.duke.edu/metadata/common"' \
' xmlns:rpm="http://linux.duke.edu/metadata/rpm" packages="%s">' %
@@ -448,11 +446,9 @@ class MetaDataGenerator:
def _setupFilelists(self):
# setup the filelist file
- # FIXME - make this be conf.compress_type once y-m-p is fixed
- fpz = self.conf.filelistsfile + '.' + 'gz'
filelistpath = os.path.join(self.conf.outputdir, self.conf.tempdir,
- fpz)
- fo = compressOpen(filelistpath, 'w', 'gz')
+ self.conf.filelistsfile)
+ fo = open(filelistpath, 'w')
fo.write('<?xml version="1.0" encoding="UTF-8"?>\n')
fo.write('<filelists xmlns="http://linux.duke.edu/metadata/filelists"' \
' packages="%s">' % self.pkgcount)
@@ -460,11 +456,9 @@ class MetaDataGenerator:
def _setupOther(self):
# setup the other file
- # FIXME - make this be conf.compress_type once y-m-p is fixed
- fpz = self.conf.otherfile + '.' + 'gz'
otherfilepath = os.path.join(self.conf.outputdir, self.conf.tempdir,
- fpz)
- fo = compressOpen(otherfilepath, 'w', 'gz')
+ self.conf.otherfile)
+ fo = open(otherfilepath, 'w')
fo.write('<?xml version="1.0" encoding="UTF-8"?>\n')
fo.write('<otherdata xmlns="http://linux.duke.edu/metadata/other"' \
' packages="%s">' %
@@ -951,14 +945,15 @@ class MetaDataGenerator:
rp = sqlitecachec.RepodataParserSqlite(repopath, repomd.repoid, None)
for (rpm_file, ftype) in workfiles:
- # when we fix y-m-p and non-gzipped xml files - then we can make this just add
- # self.conf.compress_type
+ uncompressed = None
if ftype in ('other', 'filelists', 'primary'):
- rpm_file = rpm_file + '.' + 'gz'
+ uncompressed = os.path.join(repopath, rpm_file)
+ rpm_file = rpm_file + '.' + self.conf.compress_type
+ compressFile(uncompressed, os.path.join(repopath, rpm_file), self.conf.compress_type)
elif rpm_file.find('.') != -1 and rpm_file.split('.')[-1] not in _available_compression:
rpm_file = rpm_file + '.' + self.conf.compress_type
complete_path = os.path.join(repopath, rpm_file)
- zfo = compressOpen(complete_path)
+ zfo = uncompressed and open(uncompressed) or compressOpen(complete_path)
# This is misc.checksum() done locally so we can get the size too.
data = misc.Checksums([sumtype])
while data.read(zfo, 2**16):
@@ -981,18 +976,18 @@ class MetaDataGenerator:
if ftype == 'primary':
#FIXME - in theory some sort of try/except here
# TypeError appears to be raised, sometimes :(
- rp.getPrimary(complete_path, csum)
+ rp.getPrimary(uncompressed, csum)
elif ftype == 'filelists':
#FIXME and here
- rp.getFilelists(complete_path, csum)
+ rp.getFilelists(uncompressed, csum)
elif ftype == 'other':
#FIXME and here
- rp.getOtherdata(complete_path, csum)
+ rp.getOtherdata(uncompressed, csum)
if ftype in ['primary', 'filelists', 'other']:
- tmp_result_name = '%s.xml.gz.sqlite' % ftype
+ tmp_result_name = '%s.xml.sqlite' % ftype
tmp_result_path = os.path.join(repopath, tmp_result_name)
good_name = '%s.sqlite' % ftype
resultpath = os.path.join(repopath, good_name)
@@ -1055,7 +1050,9 @@ class MetaDataGenerator:
self.callback.log("Ending %s db creation: %s" % (ftype,
time.ctime()))
repomd.repoData[data.type] = data
-
+ if ftype in ['primary', 'filelists', 'other']:
+ os.unlink(uncompressed)
+
data = RepoData()
data.type = ftype
data.checksum = (sumtype, csum)
@@ -1065,11 +1062,7 @@ class MetaDataGenerator:
data.openchecksum = (sumtype, uncsum)
if self.conf.unique_md_filenames:
- if ftype in ('primary', 'filelists', 'other'):
- compress = 'gz'
- else:
- compress = self.conf.compress_type
-
+ compress = self.conf.compress_type
main_name = '.'.join(rpm_file.split('.')[:-1])
res_file = '%s-%s.%s' % (csum, main_name, compress)
orig_file = os.path.join(repopath, rpm_file)
--
1.7.4.4
More information about the Yum-devel
mailing list