summaryrefslogtreecommitdiff
path: root/python/vyos/xml_ref/update_cache.py
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2023-07-26 22:24:16 -0500
committerJohn Estabrook <jestabro@vyos.io>2023-07-27 08:08:23 -0500
commit223a6c5cd63fbcf7ff265b2721d0cd9f0aafb369 (patch)
treed4956a12b94f54301e778c7e97dee1078c57797d /python/vyos/xml_ref/update_cache.py
parent3de59f1365e5b908d3b24748d77dcb0bd9477ca8 (diff)
downloadvyos-1x-223a6c5cd63fbcf7ff265b2721d0cd9f0aafb369.tar.gz
vyos-1x-223a6c5cd63fbcf7ff265b2721d0cd9f0aafb369.zip
xml: T5403: add support for supplemental xml cache
Diffstat (limited to 'python/vyos/xml_ref/update_cache.py')
-rwxr-xr-xpython/vyos/xml_ref/update_cache.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/python/vyos/xml_ref/update_cache.py b/python/vyos/xml_ref/update_cache.py
new file mode 100755
index 000000000..0842bcbe9
--- /dev/null
+++ b/python/vyos/xml_ref/update_cache.py
@@ -0,0 +1,51 @@
+#!/usr/bin/env python3
+#
+# Copyright (C) 2023 VyOS maintainers and contributors
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 or later as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+#
+import os
+from copy import deepcopy
+from generate_cache import pkg_cache
+from generate_cache import ref_cache
+
+def dict_merge(source, destination):
+ dest = deepcopy(destination)
+
+ for key, value in source.items():
+ if key not in dest:
+ dest[key] = value
+ elif isinstance(source[key], dict):
+ dest[key] = dict_merge(source[key], dest[key])
+
+ return dest
+
+def main():
+ res = {}
+ cache_dir = os.path.basename(pkg_cache)
+ for mod in os.listdir(pkg_cache):
+ mod = os.path.splitext(mod)[0]
+ if not mod.endswith('_cache'):
+ continue
+ d = getattr(__import__(f'{cache_dir}.{mod}', fromlist=[mod]), 'reference')
+ if mod == 'vyos_1x_cache':
+ res = dict_merge(res, d)
+ else:
+ res = dict_merge(d, res)
+
+ with open(ref_cache, 'w') as f:
+ f.write(f'reference = {str(res)}')
+
+if __name__ == '__main__':
+ main()