From 0af6d6519e1c1ad52f7d4b56d0f211c78666ed44 Mon Sep 17 00:00:00 2001 From: "xiang.zhou" Date: Wed, 5 Jun 2024 17:01:31 +0800 Subject: [PATCH] update default plugins --- cross-package.sh | 5 +++-- update_default_plugins.py | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 update_default_plugins.py diff --git a/cross-package.sh b/cross-package.sh index ae9f434f..1ef353f2 100755 --- a/cross-package.sh +++ b/cross-package.sh @@ -153,7 +153,7 @@ case $cnc in $neuron_modules_dir/build/plugins/libplugin-mitsubishi_cnc.so \ $neuron_modules_dir/build/plugins/libplugin-heidenhain_cnc.so \ $package_dir/plugins/; - + python3 update_default_plugins.py $package_dir/config/default_plugins.json "libplugin-focas.so,libplugin-mitsubishi_cnc.so,libplugin-heidenhain_cnc.so"; cp $neuron_modules_dir/build/plugins/focas/libfocas32.so.1 $package_dir/;; (false) echo "no cnc";; @@ -163,7 +163,8 @@ case $custom in (cun) cp $neuron_modules_dir/build/plugins/libplugin-gewu2.so \ $neuron_modules_dir/build/plugins/libplugin-s7comm-for-un.so \ - $package_dir/plugins/;; + $package_dir/plugins/; + python3 update_default_plugins.py $package_dir/config/default_plugins.json "libplugin-gewu2.so,libplugin-s7comm-for-un.so";; (default) echo "no custom";; esac diff --git a/update_default_plugins.py b/update_default_plugins.py new file mode 100644 index 00000000..d94ef84b --- /dev/null +++ b/update_default_plugins.py @@ -0,0 +1,38 @@ +import sys +import json + + +def update(file_path, plugins_str): + with open(file_path, 'r') as file: + data = file.read() + + try: + json_data = json.loads(data) + except json.JSONDecodeError as e: + print(f"Error parsing JSON file: {e}") + sys.exit(1) + + if 'plugins' not in json_data: + print(f"Error no plugins array:") + sys.exit(1) + + plugins = plugins_str.split(',') + for plugin in plugins: + if plugin not in json_data['plugins']: + json_data['plugins'].append(plugin) + + with open(file_path, 'w') as file: + json.dump(json_data, file, indent=4) + + print(f"Plugins have been added to {file_path}") + + +if __name__ == '__main__': + if len(sys.argv) != 3: + print("Usage: python script.py file_path plugins_str") + sys.exit(1) + + file_path = sys.argv[1] + plugins_str = sys.argv[2] + + update(file_path, plugins_str)