This repository has been archived by the owner on Feb 10, 2023. It is now read-only.
forked from alphagov/backdrop-ga-collector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_config.py
67 lines (42 loc) · 1.49 KB
/
install_config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import argparse
import json
import os
import re
import shutil
TARGET_URL = "http://write.backdrop.dev.gov.uk/licensing_journey"
TARGET_TOKEN = "licensing_journey-bearer-token"
def is_json(filename):
return filename.endswith(".json")
def is_json_erb(filename):
return filename.endswith(".json.erb")
def target_filename(filename):
m = re.match("(.+\.json)(\.erb)?", filename)
return m.group(1)
def copy(filename):
source = os.path.join(source_path, filename)
output = os.path.join("config", filename)
print "Writing %s ..." % output
shutil.copyfile(source, output)
def install_config_template(filename):
source = os.path.join(source_path, filename)
output = os.path.join("config", target_filename(filename))
print "Writing %s ..." % output
with open(source) as stream:
config = json.load(stream)
config["target"]["url"] = TARGET_URL
config["target"]["token"] = TARGET_TOKEN
with open(output, 'w') as stream:
json.dump(config, stream)
def parse_args():
parser = argparse.ArgumentParser(
description='Install config files from a source directory')
parser.add_argument('source_path', metavar='source_path',
help='path to dir containing configs to install')
return parser.parse_args()
args = parse_args()
source_path = args.source_path
copy("credentials.json")
for filename in os.listdir(source_path):
if is_json_erb(filename):
install_config_template(filename)
print "Done"