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/>.
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>
31 from config import DISTS, VAGRANTFILE, OUT
33 HERE = os.path.abspath(os.path.dirname(__file__))
34 SHA1SUM_FILE_PATH = os.path.join(HERE, 'sha1sum.txt')
35 README_FILE_PATH = os.path.join(HERE, 'READMD.md')
37 logging.basicConfig(level='INFO')
38 log = logging.getLogger(__file__)
42 """Get all files recursively in path as a list"""
44 for root, dirnames, filenames in os.walk(path):
45 for filename in filenames:
46 filepath = os.path.join(root, filename)
47 filepaths.append(filepath)
51 def get_sha1sum(debug=False):
52 """Get sha1sum for dists + .gitlab-ci.yml"""
53 filepaths = get_files(HERE)
56 for filepath in sorted(list(filepaths)):
57 _filepath = os.path.relpath(filepath)
59 if filepath == SHA1SUM_FILE_PATH:
62 print("%s: %s: %s" % (i, d, _filepath))
64 if filepath == README_FILE_PATH:
67 print("%s: %s: %s" % (i, d, _filepath))
69 if filepath.endswith('.pyc'):
72 print("%s: %s: %s" % (i, d, _filepath))
74 with io.open(filepath, mode='rb') as _file:
81 print("%s: %s: %s" % (i, d, _filepath))
88 """Render files for all dists"""
89 for dist, config in dists.items():
91 os.makedirs(home, exist_ok=True)
92 for key in ['bootstrap.sh', 'locale.sh', 'packages.yml', 'Dockerfile']:
93 path = os.path.join(home, key)
94 log.info('%s: render "%s" to %s', dist, key, path)
95 with io.open(path, mode='wt', encoding='utf8') as fp:
97 if path.endswith('.sh'):
101 path = os.path.join(OUT, key)
102 log.info('%s: render "%s" to %s', dist, key, path)
103 with io.open(path, mode='wt', encoding='utf8') as fp:
104 fp.write(VAGRANTFILE)
106 # always calc sha1sum after render
107 sha1sum = get_sha1sum()
108 log.info('write sha1sum to %s: %s', SHA1SUM_FILE_PATH, sha1sum)
109 with io.open(SHA1SUM_FILE_PATH, mode='wt', encoding='utf8') as fp:
110 fp.write(sha1sum + "\n")
114 parser = argparse.ArgumentParser(
115 formatter_class=argparse.ArgumentDefaultsHelpFormatter,
116 description=('Render templates with samba dependencies '
117 'to bootstrap multiple distributions.'))
120 '-r', '--render', action='store_true', help='Render templates')
123 '-s', '--sha1sum', action='store_true', help='Print sha1sum')
125 '-d', '--debug', action='store_true', help='Debug sha1sum')
127 args = parser.parse_args()
134 # we will use the output to check sha1sum in ci
135 print(get_sha1sum(args.debug))
141 if __name__ == '__main__':