2 commits - modifyrepo.py
[email protected] Mon, 30 Sep 2013 13:21:51 +0000 (UTC)
| Newsgroups | gmane.linux.rpm.metadata |
|---|---|
| Message-ID | <[email protected]> |
modifyrepo.py | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) New commits: commit c0d4e0937712ad59e4120db345c2d5191b24d7b9 Author: Zdenek Pavlas <[email protected]> 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 <[email protected]> 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" <[email protected]> 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