summaryrefslogtreecommitdiff
path: root/python/vyos/xml_ref/update_cache.py
diff options
context:
space:
mode:
authorNicolás Fort <95703796+nicolas-fort@users.noreply.github.com>2023-07-31 15:22:51 -0300
committerGitHub <noreply@github.com>2023-07-31 15:22:51 -0300
commit657a566df58478c2f5d4bccad952bfcb7991e847 (patch)
tree1cf6ab7548286f358d05389132cd82bc177c676a /python/vyos/xml_ref/update_cache.py
parent7ae9d8953ddc9ba38d62400187ce1ec44abb5a6e (diff)
parentdf33f450b4e8b7e0286e36540de81edfb5f52e73 (diff)
downloadvyos-1x-657a566df58478c2f5d4bccad952bfcb7991e847.tar.gz
vyos-1x-657a566df58478c2f5d4bccad952bfcb7991e847.zip
Merge branch 'current' into T5014-dnat
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()