diff --git a/cross-package.sh b/cross-package.sh index 41c929f0..b40d40e5 100755 --- a/cross-package.sh +++ b/cross-package.sh @@ -155,7 +155,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";; @@ -165,10 +165,12 @@ 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";; (hr) cp $neuron_modules_dir/build/plugins/libplugin-iec104.so \ - $package_dir/plugins/;; + $package_dir/plugins/; + python3 update_default_plugins.py $package_dir/config/default_plugins.json "libplugin-iec104.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)