summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorMagnus Hagander2020-02-09 15:59:32 +0000
committerMagnus Hagander2020-02-09 15:59:32 +0000
commitc26521cfd921e7fe251ed065fe7712ef3472c7aa (patch)
tree4ecf6e23264490c86b0806a88ae33421365d33b1 /tools
parent19ea4a3a0b94efaf459ba461d5907e1cb0eaf23c (diff)
Replace context.override.json with a directory context.override.d
Instead of loading a single override file in context.override.json, load every file called *.json in the directory context.override.d. This is useful for example for the case of downloading the schedule data into a file and then using it for testing, instead of having to "stitch" it into place in an existing file. NOTE! For test cases using context.override.json today, just create a context.override.d and move the existing override file into this directory, and things should work like before again. NOTE! As context.override.json is not supposed to be committed to the git repository, this should not affect any production installs, but will affect most local test setups.
Diffstat (limited to 'tools')
-rwxr-xr-xtools/deploystatic/deploystatic.py29
1 files changed, 26 insertions, 3 deletions
diff --git a/tools/deploystatic/deploystatic.py b/tools/deploystatic/deploystatic.py
index 219b738a..cc872620 100755
--- a/tools/deploystatic/deploystatic.py
+++ b/tools/deploystatic/deploystatic.py
@@ -16,6 +16,7 @@ import unicodedata
import io
import subprocess
import tarfile
+import copy
import jinja2
import jinja2.sandbox
@@ -102,7 +103,9 @@ class SourceWrapper(object):
yield (relpath, fn)
def listfiles(self, d):
- return os.listdir(os.path.join(self.root, d))
+ if os.path.isdir(os.path.join(self.root, d)):
+ return os.listdir(os.path.join(self.root, d))
+ return []
def copy_if_changed(self, relsource, fulldest):
fullsrc = os.path.join(self.root, relsource)
@@ -183,6 +186,23 @@ def load_context(jsondata):
return {}
+# XXX: keep in sync with confreg/contextutil.py
+def deep_update_context(target, source):
+ for k, v in source.items():
+ if type(v) == dict:
+ # If this is a dict stored in the dict
+ if k not in target:
+ # Target didn't have it, so copy it over
+ target[k] = copy.deepcopy(v)
+ elif type(target[k]) != dict:
+ # Target had something but it's not a dict, so overwrite it
+ target[k] = copy.deepcopy(v)
+ else:
+ deep_update_context(target[k], v)
+ else:
+ target[k] = copy.copy(v)
+
+
# Locate which git revision we're on
def find_git_revision(path):
while path != '/':
@@ -353,8 +373,11 @@ if __name__ == "__main__":
# Fetch the current git revision if this is coming out of a git repository
context['githash'] = git_revision
- # Load a context that can override everything, including static hashes
- context.update(load_context(source.readfile('templates/context.override.json')))
+ # Load contexts in override directory, if any
+ if os.path.isdir('templates/context.override.d'):
+ for f in sorted(source.listfiles('templates/context.override.d')):
+ if f.endswith('.json'):
+ deep_update_context(context, load_context(source.readfile(os.path.join('templates/context.override.d', f))))
knownfiles = []
knownfiles = _deploy_static(source, args.destpath)