#!/usr/bin/python -tt # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Library General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # Copyright (c) 2008 Red Hat, Inc - # Written by seth vidal skvidal @ fedoraproject.org import os import sys import yum.comps import optparse import gzip #take N comps file on the cli and merge them to a single one def parse_args(): parser = optparse.OptionParser() usage = "merge_comps [options] comps1.xml [comps2.xml] [comps3.xml]" parser.set_usage(usage) parser.add_option("-o", "--output", default='comps.xml', help= "output destination for the merged comps file") opts,args = parser.parse_args() if not args: parser.print_usage() sys.exit(1) # deal with relative vs absolute paths for files: if opts.output[0] != '/': cwd = os.getcwd() opts.output = '%s/%s' % (cwd, opts.output) return opts, args def main(): opts, args = parse_args() c = yum.comps.Comps() added_files = 0 for cf in args: if os.path.exists(cf): print 'Adding %s' % cf if cf.endswith('.gz'): cf = gzip.open(cf) c.add(srcfile=cf) added_files+=1 if added_files < 1: print >> sys.stderr, "No files found for input, exiting" return 1 print 'Writing out comps file to %s ' % opts.output try: out = open(opts.output, 'w') out.write(c.xml()) except (IOError, OSError), e: print >> sys.stderr, "Error writing comps file to %s: %s" % (opts.output, str(e)) out.close() return 1 else: out.close() if __name__ == "__main__": sys.exit(main())