Discussion:
2 commits - modifyrepo.py
z***@osuosl.org
2013-09-30 13:21:51 UTC
Permalink
modifyrepo.py | 35 +++++++++++++++++++++++++++++------
1 file changed, 29 insertions(+), 6 deletions(-)

New commits:
commit c0d4e0937712ad59e4120db345c2d5191b24d7b9
Author: Zdenek Pavlas <***@redhat.com>
Date: Mon Sep 30 15:19:48 2013 +0200

modifyrepo: sanitize opts.sumtype. BZ 1013614

diff --git a/modifyrepo.py b/modifyrepo.py
index 88f1290..804a243 100755
--- a/modifyrepo.py
+++ b/modifyrepo.py
@@ -32,7 +32,7 @@ import sys
from createrepo import __version__
from createrepo.utils import checksum_and_rename, compressOpen, MDError
from createrepo.utils import _available_compression
-from yum.misc import checksum
+from yum.misc import checksum, _available_checksums

from yum.repoMDObject import RepoMD, RepoMDError, RepoData
from xml.dom import minidom
@@ -231,6 +231,9 @@ def main(args):
if opts.compress_type not in _available_compression:
print "Compression %s not available: Please choose from: %s" % (opts.compress_type, ', '.join(_available_compression))
return 1
+ if opts.sumtype not in _available_checksums:
+ print "Checksum %s not available: Please choose from: %s" % (opts.sumtype, ', '.join(_available_checksums))
+ return 1
repomd.compress_type = opts.compress_type

# remove
commit 9b7c504616f137e422cb637bcbfe0f0e07497701
Author: Zdenek Pavlas <***@redhat.com>
Date: Fri Sep 27 10:36:59 2013 +0200

modifyrepo: automatic option defaults

use --compress-type, --checksum, and --unique-md-filenames
defaults from the "primary" repodata.

Suggested by: "Michael Schroeder" <***@suse.de>

Note that createrepo always uses .gz for primary.xml, because
it compiles xml.gz => sqlite directly and libxml2 can only
parse .gz compressed files.

diff --git a/modifyrepo.py b/modifyrepo.py
index bffe99a..88f1290 100755
--- a/modifyrepo.py
+++ b/modifyrepo.py
@@ -27,6 +27,7 @@
# modified by Daniel Mach 2011

import os
+import re
import sys
from createrepo import __version__
from createrepo.utils import checksum_and_rename, compressOpen, MDError
@@ -180,13 +181,13 @@ def main(args):
help="compress the new repodata before adding it to the repo (default)")
parser.add_option("--no-compress", action="store_false", dest="compress",
help="do not compress the new repodata before adding it to the repo")
- parser.add_option("--compress-type", dest='compress_type', default='gz',
+ parser.add_option("--compress-type", dest='compress_type',
help="compression format to use")
- parser.add_option("-s", "--checksum", default='sha256', dest='sumtype',
- help="specify the checksum type to use (default: sha256)")
+ parser.add_option("-s", "--checksum", dest='sumtype',
+ help="specify the checksum type to use")
parser.add_option("--unique-md-filenames", dest="unique_md_filenames",
- help="include the file's checksum in the filename, helps with proxies (default)",
- default=True, action="store_true")
+ help="include the file's checksum in the filename, helps with proxies",
+ action="store_true")
parser.add_option("--simple-md-filenames", dest="unique_md_filenames",
help="do not include the file's checksum in the filename",
action="store_false")
@@ -204,6 +205,25 @@ def main(args):
print "Could not access repository: %s" % str(e)
return 1

+ try:
+ # try to extract defaults from primary entry
+ md = repomd.repoobj.getData('primary')
+ sumtype = md.checksum[0]
+ name = os.path.basename(md.location[1])
+ unique_md_filenames = re.match(r'[0-9a-f]{32,}-', name) != None
+ compress_type = name.rsplit('.', 1)[1]
+ except RepoMDError:
+ sumtype = 'sha256'
+ unique_md_filenames = True
+ compress_type = 'gz'
+
+ # apply defaults
+ if opts.sumtype is None:
+ opts.sumtype = sumtype
+ if opts.unique_md_filenames is None:
+ opts.unique_md_filenames = unique_md_filenames
+ if opts.compress_type is None:
+ opts.compress_type = compress_type

repomd.checksum_type = opts.sumtype
repomd.unique_md_filenames = opts.unique_md_filenames
z***@osuosl.org
2013-09-30 14:27:38 UTC
Permalink
modifyrepo.py | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)

New commits:
commit de6c0b5e53ab1628355443b2c1d60574654a89be
Author: Zdenek Pavlas <***@redhat.com>
Date: Mon Sep 30 15:57:47 2013 +0200

modifyrepo --remove: fix multiple bugs. BZ 1013626

- Fix mdtype autodetection from filename.

Now we should correctly derive mdtype even if the file argument
used full path, and/or --unique-md-filenames was on.

- Remove metadata file using path relative to repodir.

See the BZ, unlink should work from any $cwd.

- Honor --mdtype option

When --mdtype is specified, it overrides mdtype autodetection.
This should work for --remove, too.

diff --git a/modifyrepo.py b/modifyrepo.py
index 13b14a5..f9d346c 100755
--- a/modifyrepo.py
+++ b/modifyrepo.py
@@ -60,6 +60,9 @@ class RepoMetadata:
""" Get mdtype from existing mdtype or from a mdname. """
if mdtype:
return mdtype
+ mdname = os.path.basename(mdname)
+ if re.match(r'[0-9a-f]{32,}-', mdname):
+ mdname = mdname.split('-', 1)[1]
return mdname.split('.')[0]

def _print_repodata(self, repodata):
@@ -82,7 +85,8 @@ class RepoMetadata:
def _remove_repodata_file(self, repodata):
""" Remove a file specified in repodata location """
try:
- os.remove(repodata.location[1])
+ fname = os.path.basename(repodata.location[1])
+ os.remove(os.path.join(self.repodir, fname))
except OSError, ex:
if ex.errno != 2:
# continue on a missing file
@@ -243,7 +247,7 @@ def main(args):
# remove
if opts.remove:
try:
- repomd.remove(metadata)
+ repomd.remove(metadata, mdtype=opts.mdtype)
except MDError, ex:
print "Could not remove metadata: %s" % (metadata, str(ex))
return 1
commit 66b4c0557b33e797a1a8c47d8575e70b179b1785
Author: Tomas Mlcoch <***@redhat.com>
Date: Mon Sep 30 14:20:34 2013 +0200

Add support for <open-size> element + show size and open-size on output

diff --git a/modifyrepo.py b/modifyrepo.py
index 804a243..13b14a5 100755
--- a/modifyrepo.py
+++ b/modifyrepo.py
@@ -69,6 +69,8 @@ class RepoMetadata:
print " checksum =", repodata.checksum[1]
print " timestamp =", repodata.timestamp
print " open-checksum =", repodata.openchecksum[1]
+ print " size =", repodata.size
+ print " open-size =", repodata.opensize

def _write_repomd(self):
""" Write the updated repomd.xml. """
@@ -142,8 +144,10 @@ class RepoMetadata:
new_rd.type = mdtype
new_rd.location = (None, 'repodata/' + base_destmd)
new_rd.checksum = (self.checksum_type, csum)
- new_rd.openchecksum = (self.checksum_type, open_csum)
new_rd.size = str(os.stat(destmd).st_size)
+ if do_compress:
+ new_rd.openchecksum = (self.checksum_type, open_csum)
+ new_rd.opensize = str(os.stat(metadata).st_size)
new_rd.timestamp = str(int(os.stat(destmd).st_mtime))
self.repoobj.repoData[new_rd.type] = new_rd
self._print_repodata(new_rd)

Loading...