blob: a82e01677e2c61cf625b76f27c29f01225e83e1b [file] [log] [blame]
garciadeblas5ea85ff2025-06-17 12:56:54 +02001# Copyright 2020 Canonical Ltd.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14import json
15import argparse
16
17CHANNEL_LIST = [
18 "stable",
19 "candidate",
20 "edge",
21]
22BUNDLE_PREFIX = "cs:~charmed-osm"
23DEFAULT_BUNDLE = "bundles/osm/bundle.yaml"
24HA_BUNDLE = "bundles/osm-ha/bundle.yaml"
25
26parser = argparse.ArgumentParser(description="Process some arguments.")
27
28parser.add_argument("--channel", help="Channel from the Charm Store")
29parser.add_argument("--destination", help="Destination for the generated bundle")
30parser.add_argument("--ha", help="Select HA bundle", action="store_true")
31parser.add_argument("--local", help="Path to the bundle directory", action="store_true")
32parser.add_argument("--store", help="Path to the bundle directory", action="store_true")
33
34args = parser.parse_args()
35print(args)
36if not args.local and not args.store:
37 raise Exception("--local or --store must be specified")
38if args.local and args.store:
39 raise Exception("Both --local and --store cannot be specified. Please choose one.")
40if not args.destination:
41 raise Exception("--destination must be specified")
42if args.channel and not args.channel in CHANNEL_LIST:
43 raise Exception(
44 "Channel {} does not exist. Please choose one of these: {}".format(
45 args.channel, CHANNEL_LIST
46 )
47 )
48channel = args.channel if args.channel else "stable"
49path = HA_BUNDLE if args.ha else DEFAULT_BUNDLE
50destination = args.destination
51prefix = "." if args.local else BUNDLE_PREFIX
52suffix = "/build" if args.local else ""
53
54data = {
55 "channel": channel,
56 "prefix": prefix,
57 "suffix": suffix,
58}
59
60with open(path) as template:
61 bundle_template = template.read()
62 template.close()
63with open("{}".format(destination), "w") as text_file:
64 text_file.write(bundle_template % data)
65 text_file.close()