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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/python
#
# Copyright 2009 Canonical Ltd.  This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).

from __future__ import print_function

import os

archtag = os.popen("dpkg --print-architecture").read().strip()

from optparse import OptionParser

parser = OptionParser()
parser.add_option("-n", "--name", dest="NAME",
                  help="the name for this buildd",
                  metavar="NAME",
                  default="default")

parser.add_option("-H", "--host", dest="BINDHOST",
                  help="the IP/host this buildd binds to",
                  metavar="HOSTNAME",
                  default="localhost")

parser.add_option("-p", "--port", dest="BINDPORT",
                  help="the port this buildd binds to",
                  metavar="PORT",
                  default="8221")

parser.add_option("-a", "--arch", dest="ARCHTAG",
                  help="the arch tag this buildd claims",
                  metavar="ARCHTAG",
                  default=archtag)

parser.add_option("-t", "--template", dest="TEMPLATE",
                  help="the template file to use",
                  metavar="FILE",
                  default="/usr/share/launchpad-buildd/template-buildd-slave.conf")

parser.add_option("--snap-proxy-port", dest="SNAPPROXYPORT",
                  help="the port the local snap proxy binds to",
                  metavar="PORT",
                  default="8222")

(options, args) = parser.parse_args()

template = open(options.TEMPLATE, "r").read()

replacements = {
    "@NAME@": options.NAME,
    "@BINDHOST@": options.BINDHOST,
    "@ARCHTAG@": options.ARCHTAG,
    "@BINDPORT@": options.BINDPORT,
    "@SNAPPROXYPORT@": options.SNAPPROXYPORT,
    }

for replacement_key in replacements:
    template = template.replace(replacement_key,
                                replacements[replacement_key])

print(template.strip())