Skip to content

Commit

Permalink
Merge pull request #198 from ZhouBox/v2.9
Browse files Browse the repository at this point in the history
[v2.9]update default plugins
  • Loading branch information
fengzeroz authored Jun 6, 2024
2 parents 1d305c7 + 75364f8 commit 52fe315
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
8 changes: 5 additions & 3 deletions cross-package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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";;
Expand All @@ -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
Expand Down
38 changes: 38 additions & 0 deletions update_default_plugins.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 52fe315

Please sign in to comment.