~cjwatson/launchpad-buildd/better-snap-channel-handling-2

1 by Martin Pool
Add snapshot of buildd source extracted from the Launchpad tree
1
#!/usr/bin/python
2
#
3
# Copyright 2009 Canonical Ltd.  This software is licensed under the
4
# GNU Affero General Public License version 3 (see the file LICENSE).
5
212 by Colin Watson
Use Python-3-compatible forms of "print" and "except".
6
from __future__ import print_function
7
1 by Martin Pool
Add snapshot of buildd source extracted from the Launchpad tree
8
import os
9
10
archtag = os.popen("dpkg --print-architecture").read().strip()
11
12
from optparse import OptionParser
13
14
parser = OptionParser()
15
parser.add_option("-n", "--name", dest="NAME",
16
                  help="the name for this buildd",
17
                  metavar="NAME",
18
                  default="default")
19
20
parser.add_option("-H", "--host", dest="BINDHOST",
21
                  help="the IP/host this buildd binds to",
22
                  metavar="HOSTNAME",
23
                  default="localhost")
24
25
parser.add_option("-p", "--port", dest="BINDPORT",
26
                  help="the port this buildd binds to",
27
                  metavar="PORT",
28
                  default="8221")
29
30
parser.add_option("-a", "--arch", dest="ARCHTAG",
31
                  help="the arch tag this buildd claims",
32
                  metavar="ARCHTAG",
33
                  default=archtag)
34
35
parser.add_option("-t", "--template", dest="TEMPLATE",
36
                  help="the template file to use",
37
                  metavar="FILE",
38
                  default="/usr/share/launchpad-buildd/template-buildd-slave.conf")
39
215.6.1 by Colin Watson
Add a local unauthenticated proxy on port 8222, which proxies through to
40
parser.add_option("--snap-proxy-port", dest="SNAPPROXYPORT",
41
                  help="the port the local snap proxy binds to",
42
                  metavar="PORT",
43
                  default="8222")
44
1 by Martin Pool
Add snapshot of buildd source extracted from the Launchpad tree
45
(options, args) = parser.parse_args()
46
47
template = open(options.TEMPLATE, "r").read()
48
49
replacements = {
50
    "@NAME@": options.NAME,
51
    "@BINDHOST@": options.BINDHOST,
52
    "@ARCHTAG@": options.ARCHTAG,
53
    "@BINDPORT@": options.BINDPORT,
215.6.1 by Colin Watson
Add a local unauthenticated proxy on port 8222, which proxies through to
54
    "@SNAPPROXYPORT@": options.SNAPPROXYPORT,
1 by Martin Pool
Add snapshot of buildd source extracted from the Launchpad tree
55
    }
56
57
for replacement_key in replacements:
58
    template = template.replace(replacement_key,
59
                                replacements[replacement_key])
60
212 by Colin Watson
Use Python-3-compatible forms of "print" and "except".
61
print(template.strip())