rpc_server: Avoid casts in DBG statements
[Samba.git] / bootstrap / template.py
blob48c008c53ed2655381c08c6d1159a73a7154c946
1 #!/usr/bin/env python3
3 # Copyright (C) Catalyst.Net Ltd 2019
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 """
19 Manage dependencies and bootstrap environments for Samba.
21 CLI script to render bootstrap.sh/Dockerfile/Vagrantfile.
23 Author: Joe Guo <joeg@catalyst.net.nz>
24 """
26 import io
27 import os
28 import logging
29 import argparse
30 from config import DISTS, VAGRANTFILE, OUT
32 logging.basicConfig(level='INFO')
33 log = logging.getLogger(__file__)
36 def render(dists):
37 """Render files for all dists"""
38 for dist, config in dists.items():
39 home = config['home']
40 os.makedirs(home, exist_ok=True)
41 for key in ['packages.yml', 'bootstrap.sh', 'Dockerfile']:
42 path = os.path.join(home, key)
43 log.info('%s: render "%s" to %s', dist, key, path)
44 with io.open(path, mode='wt', encoding='utf8') as fp:
45 fp.write(config[key])
47 key = 'Vagrantfile'
48 path = os.path.join(OUT, key)
49 log.info('%s: render "%s" to %s', dist, key, path)
50 with io.open(path, mode='wt', encoding='utf8') as fp:
51 fp.write(VAGRANTFILE)
54 def main():
55 parser = argparse.ArgumentParser(
56 formatter_class=argparse.ArgumentDefaultsHelpFormatter,
57 description=('Render templates with samba dependencies '
58 'to bootstrap multiple distributions.'))
60 parser.add_argument(
61 '-r', '--render', action='store_true', help='Render templates')
63 args = parser.parse_args()
65 if args.render:
66 render(DISTS)
67 else:
68 parser.print_help()
71 if __name__ == '__main__':
72 main()