comparison bin/treepkgbuilder.py @ 177:df7498d0bd9d

Add bin/treepkgbuilder.py, a script to manage treepkg's pbuilder instance
author Bernhard Herzog <bh@intevation.de>
date Tue, 24 Jun 2008 17:52:14 +0000
parents
children 83c77307ffb1
comparison
equal deleted inserted replaced
176:7bde59aa611e 177:df7498d0bd9d
1 #! /usr/bin/python2.4
2 # Copyright (C) 2007, 2008 by Intevation GmbH
3 # Authors:
4 # Bernhard Herzog <bh@intevation.de>
5 #
6 # This program is free software under the GPL (>=v2)
7 # Read the file COPYING coming with the software for details.
8
9 """Usage: treepkgbuilder COMMAND [options]
10
11 Manage the pbuilder environment for a tree packager installation. The
12 pbuilder settings are taken from the configuration file, either the
13 default treepkg.cfg or the one given with the --config-file option.
14 Also, this script assumes that there is only one pbuilder setting for
15 all packagers. Use treepkgbuilder COMMAND --help for more details about
16 the commands.
17 """
18
19 import sys
20
21 import treepkgcmd
22 from treepkg.options import create_parser
23 from treepkg.packager import create_package_track, PackagerGroup
24 from treepkg.readconfig import read_config
25
26
27 class Command(object):
28
29 names = ()
30
31 def __init__(self, arguments):
32 parser = self.create_parser()
33 self.opts, self.rest = parser.parse_args(arguments)
34
35 def create_parser(self):
36 return create_parser()
37
38 def read_config(self):
39 self.treepkg_opts, self.packager_opts \
40 = read_config(self.opts.config_file)
41
42 def get_builder(self):
43 self.read_config()
44 group = PackagerGroup([create_package_track(**opts)
45 for opts in self.packager_opts],
46 **self.treepkg_opts)
47 track = group.get_package_tracks()[0]
48 return track.builder
49
50
51
52 class InitCommand(Command):
53
54 names = ("init",)
55
56 def __init__(self, arguments):
57 super(InitCommand, self).__init__(arguments)
58 if self.opts.mirrorsite is None:
59 print >>sys.stderr, "Missing required option --mirrorsite"
60 sys.exit(1)
61
62 def create_parser(self):
63 parser = super(InitCommand, self).create_parser()
64 parser.set_defaults(distribution="etch")
65 parser.add_option("--mirrorsite",
66 help=("The debian mirror site"
67 " (pbuilder MIRRORSITE setting). Required."))
68 parser.add_option("--othermirror",
69 help=("Extra contents of the OTHERMIRROR setting."
70 " See the pbuilder documentation for the"
71 " format."))
72 parser.add_option("--distribution",
73 help=("The debian distribution for the pbuilder"
74 " chroot. Default is etch."))
75 return parser
76
77 def run(self):
78 builder = self.get_builder()
79 builder.init_pbuilder(distribution=self.opts.distribution,
80 mirrorsite=self.opts.mirrorsite,
81 extramirrors=self.opts.othermirror)
82
83
84 class UpdateCommand(Command):
85
86 names = ("update",)
87
88 def run(self):
89 builder = self.get_builder()
90 builder.update(suppress_output=False, log_info=False)
91
92
93 class HelpCommand(Command):
94
95 names = ("help", "--help", "-h")
96
97 def run(self):
98 print __doc__.rstrip()
99 print "Supported commands:"
100 commands = sorted((cmd for cmd in iter_commands() if cmd.names),
101 key=lambda cmd: cmd.names[0])
102 for cmd in commands:
103 print " ", " ".join(cmd.names)
104
105
106 def iter_commands():
107 for key, obj in globals().items():
108 if key.endswith("Command"):
109 yield obj
110
111 def get_command_class(name):
112 for obj in iter_commands():
113 if name in obj.names:
114 return obj
115 return None
116
117
118 def main():
119 arguments = sys.argv[1:]
120
121 if len(arguments) < 1:
122 print >>sys.stderr, "Missing command"
123 sys.exit(1)
124
125 command_name = arguments[0]
126 arguments = arguments[1:]
127
128 command_class = get_command_class(command_name)
129 if command_class is None:
130 print >>sys.stderr, "Unknown command %r" % command_name
131 sys.exit(1)
132
133 command = command_class(arguments)
134 command.run()
135
136
137 main()
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)