resetting manifest requested domain to floor
[platform/upstream/createrepo.git] / mergerepo.py
1 #!/usr/bin/python -tt
2 # This program is free software; you can redistribute it and/or modify
3 # it under the terms of the GNU General Public License as published by
4 # the Free Software Foundation; either version 2 of the License, or
5 # (at your option) any later version.
6 #
7 # This program is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10 # GNU Library General Public License for more details.
11 #
12 # You should have received a copy of the GNU General Public License
13 # along with this program; if not, write to the Free Software
14 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15 # Copyright 2008  Red Hat, Inc - written by skvidal at fedoraproject.org
16
17 # merge repos from arbitrary repo urls
18
19 import sys
20 import createrepo.merge
21 from optparse import OptionParser
22
23 #TODO:
24 # excludes?
25 # handle content/distro tags
26 # support revision?
27
28
29 def parse_args(args):
30     """Parse our opts/args"""
31     usage = """
32     mergerepo: take 2 or more repositories and merge their metadata into a new repo
33
34     mergerepo --repo=url --repo=url --outputdir=/some/path"""
35
36     parser = OptionParser(version = "mergerepo 0.1", usage=usage)
37     # query options
38     parser.add_option("-r", "--repo", dest='repos', default=[], action="append",
39                       help="repo url")
40     parser.add_option("-a", "--archlist", default=[], action="append",
41                       help="Defaults to all arches - otherwise specify arches")
42     parser.add_option("-d", "--database", default=True, action="store_true")
43     parser.add_option( "--no-database", default=False, action="store_true", dest="nodatabase")
44     parser.add_option("-o", "--outputdir", default=None,
45                       help="Location to create the repository")
46     parser.add_option("", "--nogroups", default=False, action="store_true",
47                       help="Do not merge group(comps) metadata")
48     parser.add_option("", "--noupdateinfo", default=False, action="store_true",
49                       help="Do not merge updateinfo metadata")
50     (opts, argsleft) = parser.parse_args(args)
51
52     if len(opts.repos) < 2:
53         parser.print_usage()
54         sys.exit(1)
55
56     # sort out the comma-separated crap we somehow inherited.
57     archlist = []
58     for archs in opts.archlist:
59         for arch in archs.split(','):
60             archlist.append(arch)
61
62     opts.archlist = archlist
63
64     return opts
65
66 def main(args):
67     """main"""
68     opts = parse_args(args)
69     rmbase = createrepo.merge.RepoMergeBase(opts.repos)
70     if opts.archlist:
71         rmbase.archlist = opts.archlist
72     if opts.outputdir:
73         rmbase.outputdir = opts.outputdir
74     if opts.nodatabase:
75         rmbase.mdconf.database = False
76     if opts.nogroups:
77         rmbase.groups = False
78     if opts.noupdateinfo:
79         rmbase.updateinfo = False
80
81     rmbase.merge_repos()
82     rmbase.write_metadata()
83
84 if __name__ == "__main__":
85     main(sys.argv[1:])