Motr  M0
s3_overrides.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 #
3 # Copyright (c) 2020 Seagate Technology LLC and/or its Affiliates
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #
17 # For any questions about this software or licensing,
18 # please email opensource@seagate.com or cortx-questions@seagate.com.
19 #
20 
21 
22 import argparse
23 import yaml
24 
25 def parse_args():
26  description="""
27  s3_overrides.py: Apply overrides to the specified s3config.yaml
28  """
29 
30  parser = argparse.ArgumentParser(description=description)
31  parser.add_argument("overrides", help="Overrides string in format key=value")
32  parser.add_argument("s3config", help="s3config.yaml file")
33 
34  return parser.parse_args()
35 
36 def main():
37  args = parse_args()
38 
39  data = []
40  if args.overrides:
41  with open(args.s3config, 'r') as f:
42  for line in f.readlines():
43  data.append(line)
44 
45  for kv in args.overrides.split(" "):
46  key, value = kv.split('=')
47  for idx, line in enumerate(data):
48  if key in line.split(': ')[0]:
49  k = line.split(': ')[0]
50  print(f"Overriding {k} with new value: {value}, old value: {line.split(': ')[1].split('#')[0]}")
51  nl='\n'
52  data[idx] = f"{k}: {value} # Override by s3_overrides.py{nl}"
53 
54  with open(args.s3config, 'w') as f:
55  for line in data:
56  f.write(line)
57 
58 if __name__ == '__main__':
59  main()
def parse_args()
Definition: s3_overrides.py:25
static M0_UNUSED void print(struct m0_be_list *list)
Definition: list.c:186
Definition: main.py:1