modifyrepo patch: automatic option defaults
Michael Schroeder <[email protected]> Mon, 16 Sep 2013 17:25:54 +0200
| Newsgroups | gmane.linux.rpm.metadata |
|---|---|
| Message-ID | <[email protected]> |
--SLDf9lqlvOQaIe6s Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi rpmmd folks, attached is a patch that makes modifyrepo take the defaults of the checksum and unique-md-filenames options from the 'primary' entry in the repomd.xml file. Detecting the compression type is left as an exercise to the reader ;) Cheers, Michael. -- Michael Schroeder [email protected] SUSE LINUX Products GmbH, GF Jeff Hawn, HRB 16746 AG Nuernberg main(_){while(_=~getchar())putchar(~_-1/(~(_|32)/13*2-11)*13);} --SLDf9lqlvOQaIe6s Content-Type: text/x-patch; charset=us-ascii Content-Disposition: attachment; filename="0001-add-autodetection-for-checksum-and-unique-md-filenam.patch" From 7f7c1e49e6144bbb7d1bebbd5e7f39a1bf484bd1 Mon Sep 17 00:00:00 2001 From: Michael Schroeder <[email protected]> Date: Mon, 16 Sep 2013 17:20:31 +0200 Subject: [PATCH] add autodetection for checksum and unique-md-filenames options --- modifyrepo.py | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/modifyrepo.py b/modifyrepo.py index bffe99a..c5d40f5 100755 --- a/modifyrepo.py +++ b/modifyrepo.py @@ -182,14 +182,14 @@ def main(args): help="do not compress the new repodata before adding it to the repo") parser.add_option("--compress-type", dest='compress_type', default='gz', 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") - parser.add_option("--simple-md-filenames", dest="unique_md_filenames", + help="include the file's checksum in the filename, helps with proxies", + action="store_true") + parser.add_option("--simple-md-filenames", dest="simple_md_filenames", help="do not include the file's checksum in the filename", - action="store_false") + action="store_true") parser.usage = "modifyrepo [options] [--remove] <input_metadata> <output repodata>" (opts, argsleft) = parser.parse_args(args) @@ -204,6 +204,23 @@ def main(args): print "Could not access repository: %s" % str(e) return 1 + # try to extract defaults from primary entry + try: + primarymd = repomd.repoobj.getData('primary') + if primarymd and primarymd.checksum and not opts.sumtype: + opts.sumtype = primarymd.checksum[0] + if primarymd and primarymd.location and primarymd.location[1] and \ + not opts.simple_md_filenames and not opts.unique_md_filenames: + if not re.match(r'[0-9a-f]{32,}-', os.path.basename(primarymd.location[1])): + opts.simple_md_filenames = True + except Exception, e: + pass + + # set defaults if above code failed + if not opts.sumtype: + opts.sumtype = 'sha256' + if not opts.simple_md_filenames: + opts.unique_md_filenames = True repomd.checksum_type = opts.sumtype repomd.unique_md_filenames = opts.unique_md_filenames -- 1.8.1.4 --SLDf9lqlvOQaIe6s Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Rpm-metadata mailing list [email protected] http://lists.baseurl.org/mailman/listinfo/rpm-metadata --SLDf9lqlvOQaIe6s--