source: germinate/trunk/fuentes/germinate/scripts/germinate_main.py @ 169

Last change on this file since 169 was 169, checked in by mabarracus, 4 years ago

wip

File size: 8.6 KB
Line 
1# -*- coding: UTF-8 -*-
2"""Expand dependencies in a list of seed packages."""
3
4# Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
5#               Canonical Ltd.
6#
7# Germinate is free software; you can redistribute it and/or modify it
8# under the terms of the GNU General Public License as published by the
9# Free Software Foundation; either version 2, or (at your option) any
10# later version.
11#
12# Germinate is distributed in the hope that it will be useful, but
13# WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15# General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with Germinate; see the file COPYING.  If not, write to the Free
19# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20# 02110-1301, USA.
21
22import copy
23import logging
24import optparse
25import os
26import shutil
27import sys
28
29import germinate.archive
30import germinate.defaults
31from germinate.germinator import Germinator
32from germinate.log import germinate_logging
33from germinate.seeds import Seed, SeedError, SeedStructure, SeedVcs
34import germinate.version
35
36
37def check_seed_vcs(option, opt, value):
38    if value == "none":  # or just omit the option
39        return None
40    elif value == "auto":
41        return SeedVcs.AUTO
42    elif value == "bzr":
43        return SeedVcs.BZR
44    elif value == "git":
45        return SeedVcs.GIT
46    else:
47        raise optparse.OptionValueError(
48            "option %s: unrecognised VCS value: %s" % (opt, value))
49
50
51class GerminateOption(optparse.Option):
52    """A custom option type for use with optparse."""
53
54    TYPES = optparse.Option.TYPES + ("vcs",)
55    TYPE_CHECKER = copy.copy(optparse.Option.TYPE_CHECKER)
56    TYPE_CHECKER["vcs"] = check_seed_vcs
57
58
59def parse_options(argv):
60    parser = optparse.OptionParser(
61        prog='germinate',
62        version='%prog ' + germinate.version.VERSION,
63        option_class=GerminateOption)
64    parser.add_option('-v', '--verbose', dest='verbose', action='store_true',
65                      default=False,
66                      help='be more verbose when processing seeds')
67    parser.add_option('-S', '--seed-source', dest='seeds', metavar='SOURCE',
68                      help='fetch seeds from SOURCE (default: %s)' %
69                           germinate.defaults.seeds)
70    parser.add_option('-s', '--seed-dist', dest='release', metavar='DIST',
71                      default=germinate.defaults.release,
72                      help='fetch seeds for distribution DIST '
73                           '(default: %default)')
74    parser.add_option('-m', '--mirror', dest='mirrors', action='append',
75                      metavar='MIRROR',
76                      help='get package lists from MIRROR (default: %s)' %
77                           germinate.defaults.mirror)
78    parser.add_option('--source-mirror', dest='source_mirrors',
79                      action='append', metavar='MIRROR',
80                      help='get source package lists from mirror '
81                           '(default: value of --mirror)')
82    parser.add_option('-d', '--dist', dest='dist',
83                      default=germinate.defaults.dist,
84                      help='operate on distribution DIST (default: %default)')
85    parser.add_option('-a', '--arch', dest='arch',
86                      default=germinate.defaults.arch,
87                      help='operate on architecture ARCH (default: %default)')
88    parser.add_option('-c', '--components', dest='components',
89                      default='main,restricted', metavar='COMPS',
90                      help='operate on components COMPS (default: %default)')
91    parser.add_option('--vcs', dest='vcs', action='store', type='vcs',
92                      help='version control system to use '
93                           '(auto, bzr, git; defaults to none)')
94    parser.add_option('--bzr', dest='vcs',
95                      action='store_const', const=SeedVcs.BZR,
96                      help='fetch seeds using bzr (requires bzr to be '
97                           'installed; use --vcs=bzr instead)')
98    parser.add_option('--cleanup', dest='cleanup', action='store_true',
99                      default=False,
100                      help="don't cache Packages or Sources files")
101    parser.add_option('--no-rdepends', dest='want_rdepends',
102                      action='store_false', default=True,
103                      help='disable reverse-dependency calculations')
104    parser.add_option('--no-installer', dest='installer', action='store_false',
105                      default=True,
106                      help='do not consider debian-installer udeb packages')
107    parser.add_option('--seed-packages', dest='seed_packages',
108                      metavar='PARENT/PKG,PARENT/PKG,...',
109                      help='treat each PKG as a seed by itself, inheriting '
110                           'from PARENT')
111    options, _ = parser.parse_args(argv[1:])
112
113    if options.seeds is None:
114        if options.vcs is None:
115            options.seeds = germinate.defaults.seeds
116        elif options.vcs == SeedVcs.GIT:
117            options.seeds = germinate.defaults.seeds_git
118        else:
119            options.seeds = germinate.defaults.seeds_bzr
120    options.seeds = options.seeds.split(',')
121
122    if options.mirrors is None:
123        options.mirrors = [germinate.defaults.mirror]
124
125    options.dist = options.dist.split(',')
126    options.components = options.components.split(',')
127    if options.seed_packages is None:
128        options.seed_packages = []
129    else:
130        options.seed_packages = options.seed_packages.split(',')
131
132    return options
133
134
135def main(argv):
136    options = parse_options(argv)
137
138    if options.verbose:
139        germinate_logging(logging.DEBUG)
140    else:
141        germinate_logging(logging.INFO)
142
143    g = Germinator(options.arch)
144
145    archive = germinate.archive.TagFile(
146        options.dist, options.components, options.arch,
147        options.mirrors, source_mirrors=options.source_mirrors,
148        installer_packages=options.installer, cleanup=options.cleanup)
149    g.parse_archive(archive)
150
151    if os.path.isfile("hints"):
152        with open("hints") as hints:
153            g.parse_hints(hints)
154
155    try:
156        structure = SeedStructure(options.release, options.seeds, options.vcs)
157        for seed_package in options.seed_packages:
158            parent, pkg = seed_package.split('/')
159            structure.add(pkg, [" * " + pkg], parent)
160        g.plant_seeds(structure)
161    except SeedError:
162        sys.exit(1)
163
164    try:
165        with Seed(options.seeds, options.release, "blacklist",
166                  options.vcs) as blacklist:
167            g.parse_blacklist(structure, blacklist)
168    except SeedError:
169        pass
170
171    g.grow(structure)
172    g.add_extras(structure)
173    if options.want_rdepends:
174        g.reverse_depends(structure)
175
176    for seedname in structure.names + ["extra"]:
177        g.write_full_list(structure, seedname, seedname)
178        g.write_seed_list(structure, seedname + ".seed", seedname)
179        g.write_seed_recommends_list(structure,
180                                     seedname + ".seed-recommends", seedname)
181        g.write_depends_list(structure, seedname + ".depends", seedname)
182        g.write_build_depends_list(structure,
183                                   seedname + ".build-depends", seedname)
184
185        if seedname != "extra" and seedname in structure:
186            structure.write_seed_text(seedname + ".seedtext", seedname)
187            g.write_sources_list(structure, seedname + ".sources", seedname)
188        g.write_build_sources_list(structure,
189                                   seedname + ".build-sources", seedname)
190
191    g.write_all_list(structure, "all")
192    g.write_all_source_list(structure, "all.sources")
193
194    g.write_supported_list(structure, "%s+build-depends" % structure.supported)
195    g.write_supported_source_list(
196        structure, "%s+build-depends.sources" % structure.supported)
197
198    g.write_all_extra_list(structure, "all+extra")
199    g.write_all_extra_source_list(structure, "all+extra.sources")
200
201    g.write_provides_list(structure, "provides")
202
203    structure.write("structure")
204    structure.write_dot("structure.dot")
205
206    if os.path.exists("rdepends"):
207        shutil.rmtree("rdepends")
208    if options.want_rdepends:
209        os.mkdir("rdepends")
210        os.mkdir(os.path.join("rdepends", "ALL"))
211        for pkg in g.get_all(structure):
212            dirname = os.path.join("rdepends", g.get_source(pkg))
213            if not os.path.exists(dirname):
214                os.mkdir(dirname)
215
216            g.write_rdepend_list(structure, os.path.join(dirname, pkg), pkg)
217            os.symlink(os.path.join("..", g.get_source(pkg), pkg),
218                       os.path.join("rdepends", "ALL", pkg))
219
220    g.write_blacklisted(structure, "blacklisted")
221
222    return 0
Note: See TracBrowser for help on using the repository browser.