1 # Copyright 2020 Canonical Ltd.
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
22 BUNDLE_PREFIX
= "cs:~charmed-osm"
23 DEFAULT_BUNDLE
= "bundles/osm/bundle.yaml"
24 HA_BUNDLE
= "bundles/osm-ha/bundle.yaml"
26 parser
= argparse
.ArgumentParser(description
="Process some arguments.")
28 parser
.add_argument("--channel", help="Channel from the Charm Store")
29 parser
.add_argument("--destination", help="Destination for the generated bundle")
30 parser
.add_argument("--ha", help="Select HA bundle", action
="store_true")
31 parser
.add_argument("--local", help="Path to the bundle directory", action
="store_true")
32 parser
.add_argument("--store", help="Path to the bundle directory", action
="store_true")
34 args
= parser
.parse_args()
36 if not args
.local
and not args
.store
:
37 raise Exception("--local or --store must be specified")
38 if args
.local
and args
.store
:
39 raise Exception("Both --local and --store cannot be specified. Please choose one.")
40 if not args
.destination
:
41 raise Exception("--destination must be specified")
42 if args
.channel
and not args
.channel
in CHANNEL_LIST
:
44 "Channel {} does not exist. Please choose one of these: {}".format(
45 args
.channel
, CHANNEL_LIST
48 channel
= args
.channel
if args
.channel
else "stable"
49 path
= HA_BUNDLE
if args
.ha
else DEFAULT_BUNDLE
50 destination
= args
.destination
51 prefix
= "." if args
.local
else BUNDLE_PREFIX
52 suffix
= "/build" if args
.local
else ""
60 with
open(path
) as template
:
61 bundle_template
= template
.read()
63 with
open("{}".format(destination
), "w") as text_file
:
64 text_file
.write(bundle_template
% data
)