openc3 5.0.8 → 5.0.9

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of openc3 might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3a1e753382bf9c7d98b63dad72fed1aa08e3a234ce140327d0bbf07ed2a913dd
4
- data.tar.gz: 4b61da453f0fc1c75b7ec5df06516970b1a0d3325425e15f550322a505e90883
3
+ metadata.gz: ce13d20a53c970d01c019afff0088ee574998e393eb0e56be1ea3bc1af2dbc3c
4
+ data.tar.gz: '079099f252bf45fcbbcec9f05239de9c84858a166cfb2077806554bcdae76258'
5
5
  SHA512:
6
- metadata.gz: 3cfaad4b9103a68a6608d48513f1e1161df68325bfb0684d9dac6aebcc47af0e4c2a3225692dff08b7d28aa96ce33a3b7812928e0191620bffb08686fbe511d6
7
- data.tar.gz: a385b3d5ac4524c8919adf9cc1050793c1ce5e30fb62c679a711b79f7523d3908301de23cfd97d426ec0c58ce1815d16047807802afb8530cbb1faf91392a444
6
+ metadata.gz: bf8762aa78976151e1c561e55fd08de0593f82055d759a6c1c2ed5db9fd3b0510141077f70592cade4a7dbf1ff957657ea4252b6a7d4839046b6b69f853a5cda
7
+ data.tar.gz: 457563612d61588d7f18da69a48df88b0368b0fba3e9840d7a316eabf334d3e88218cfca584327f927f23f119c005aef4dba63e033b011a7d4c8bcdc071df15c
data/bin/openc3cli CHANGED
@@ -21,9 +21,11 @@
21
21
  # This file will handle OpenC3 tasks such as instantiating a new project
22
22
 
23
23
  require 'openc3'
24
+ require 'openc3/utilities/local_mode'
24
25
  require 'openc3/utilities/s3'
25
26
  require 'openc3/models/scope_model'
26
27
  require 'openc3/models/plugin_model'
28
+ require 'openc3/models/gem_model'
27
29
  require 'openc3/packets/packet_config'
28
30
  require 'openc3/bridge/bridge'
29
31
  require 'ostruct'
@@ -35,6 +37,7 @@ require 'json'
35
37
  require 'redis'
36
38
  require 'psych'
37
39
  require 'erb'
40
+ require 'pp'
38
41
 
39
42
  $redis_url = "redis://#{ENV['OPENC3_REDIS_HOSTNAME']}:#{ENV['OPENC3_REDIS_PORT']}"
40
43
 
@@ -313,18 +316,30 @@ ensure
313
316
  exit(result)
314
317
  end
315
318
 
316
- def update_plugin(plugin_file_path, plugin_name, variables: nil, plugin_txt_lines: nil, scope:)
319
+ def update_plugin(plugin_file_path, plugin_name, variables: nil, plugin_txt_lines: nil, scope:, existing_plugin_name:)
317
320
  new_gem = File.basename(plugin_file_path)
318
- old_gem = plugin_name.split("__")[0]
319
- puts "Updating existing plugin: #{plugin_name} with #{File.basename(plugin_file_path)}"
320
- plugin_model = OpenC3::PluginModel.get_model(name: plugin_name, scope: scope)
321
+ old_gem = existing_plugin_name.split("__")[0]
322
+ puts "Updating existing plugin: #{existing_plugin_name} with #{File.basename(plugin_file_path)}"
323
+ plugin_model = OpenC3::PluginModel.get_model(name: existing_plugin_name, scope: scope)
321
324
  begin
322
325
  # Only update if something has changed
323
- if (new_gem != old_gem) or (variables != plugin_model.variables) or (plugin_txt_lines != plugin_model.plugin_txt_lines)
326
+ if (new_gem != old_gem) or (variables and variables != plugin_model.variables) or (plugin_txt_lines and plugin_txt_lines != plugin_model.plugin_txt_lines)
327
+ puts "Gem version change detected - New: #{new_gem}, Old: #{old_gem}" if new_gem != old_gem
328
+ if variables and variables != plugin_model.variables
329
+ pp_variables = ""
330
+ PP.pp(variables, pp_variables)
331
+ pp_plugin_model_variables = ""
332
+ PP.pp(plugin_model.variables, pp_plugin_model_variables)
333
+ puts "Variables change detected\nNew:\n#{pp_variables}\nOld:\n#{pp_plugin_model_variables}"
334
+ end
335
+ puts "plugin.txt change detected\nNew:\n#{plugin_txt_lines.join("\n")}\n\nOld:\n#{plugin_model.plugin_txt_lines.join("\n")}\n" if plugin_txt_lines and plugin_txt_lines != plugin_model.plugin_txt_lines
324
336
  variables = plugin_model.variables unless variables
325
337
  plugin_model.destroy
338
+
326
339
  plugin_hash = OpenC3::PluginModel.install_phase1(plugin_file_path, existing_variables: variables, existing_plugin_txt_lines: plugin_txt_lines, process_existing: true, scope: scope)
327
- OpenC3::PluginModel.install_phase2(plugin_hash, scope: scope)
340
+ puts "Updating plugin: #{plugin_file_path}\n#{plugin_hash}"
341
+ plugin_hash = OpenC3::PluginModel.install_phase2(plugin_hash, scope: scope)
342
+ OpenC3::LocalMode.update_local_plugin(plugin_file_path, plugin_hash, old_plugin_name: plugin_name, scope: scope)
328
343
  else
329
344
  puts "No changes detected - Exiting without change"
330
345
  end
@@ -354,6 +369,7 @@ def load_plugin(plugin_file_path, scope:, plugin_hash_file: nil)
354
369
  # Only create the scope if it doesn't already exist
355
370
  unless OpenC3::ScopeModel.names.include?(scope)
356
371
  begin
372
+ puts "Creating scope: #{scope}"
357
373
  scope_model = OpenC3::ScopeModel.new(name: scope, scope: scope)
358
374
  scope_model.create
359
375
  scope_model.deploy(".", {})
@@ -381,7 +397,9 @@ def load_plugin(plugin_file_path, scope:, plugin_hash_file: nil)
381
397
  found = true
382
398
  # Upgrade if version changed else do nothing
383
399
  if file_full_name != full_name
384
- update_plugin(plugin_file_path, plugin_name, scope: scope)
400
+ update_plugin(plugin_file_path, plugin_name, scope: scope, existing_plugin_name: plugin_name)
401
+ else
402
+ puts "No version change detected for: #{plugin_name}"
385
403
  end
386
404
  end
387
405
  end
@@ -394,16 +412,24 @@ def load_plugin(plugin_file_path, scope:, plugin_hash_file: nil)
394
412
  existing_plugin_hash = OpenC3::PluginModel.get(name: plugin_hash['name'], scope: scope)
395
413
 
396
414
  # Existing plugin hash will be present if plugin is being edited or upgraded
397
- # If editing, gem name will match existing hash name
398
- # If upgrading, gem name will not match the existing hash name
415
+ # However, a missing existing could also be that a plugin was updated in local mode directly from across installations
416
+ # changing the plugin name without really meaning to create a new instance of the plugin
417
+ # ie.
418
+ # User on machine 1 checks in a changed plugin_instance.json with a different name - There is still only one plugin desired and committed
419
+ # User on machine 2 starts up with the new configuration, OpenC3::PluginModel.get will return nil because the exact name is different
420
+ # In this case, the plugin should be updated without installing a second instance. analyze_local_mode figures this out.
421
+ unless existing_plugin_hash
422
+ existing_plugin_hash = OpenC3::LocalMode.analyze_local_mode(plugin_name: plugin_hash['name'], scope: scope)
423
+ end
399
424
 
400
425
  if existing_plugin_hash
401
426
  # Upgrade or Edit
402
- update_plugin(plugin_file_path, plugin_hash['name'], variables: plugin_hash['variables'], plugin_txt_lines: plugin_hash['plugin_txt_lines'], scope: scope)
427
+ update_plugin(plugin_file_path, plugin_hash['name'], variables: plugin_hash['variables'], plugin_txt_lines: plugin_hash['plugin_txt_lines'], scope: scope, existing_plugin_name: existing_plugin_hash['name'])
403
428
  else
404
429
  # New Install
405
430
  puts "Loading new plugin: #{plugin_file_path}\n#{plugin_hash}"
406
- OpenC3::PluginModel.install_phase2(plugin_hash, scope: scope)
431
+ plugin_hash = OpenC3::PluginModel.install_phase2(plugin_hash, scope: scope)
432
+ OpenC3::LocalMode.update_local_plugin(plugin_file_path, plugin_hash, scope: scope)
407
433
  end
408
434
  rescue => err
409
435
  abort("Error installing plugin: #{scope}: #{plugin_file_path}: #{err.formatted}")
@@ -414,6 +440,7 @@ def unload_plugin(plugin_name, scope:)
414
440
  scope ||= 'DEFAULT'
415
441
  begin
416
442
  OpenC3::PluginModel.new(name: plugin_name, scope: scope).destroy
443
+ OpenC3::LocalMode.remove_local_plugin(plugin_name, scope: scope)
417
444
  OpenC3::Logger.info("PluginModel destroyed: #{plugin_name}", scope: scope)
418
445
  rescue => err
419
446
  abort("Error uninstalling plugin: #{scope}: #{plugin_name}: #{err.formatted}")
@@ -450,113 +477,119 @@ def get_redis_keys
450
477
  puts "Packets Defs: #{keys.select { |item| item[/^tlm__/] }}"
451
478
  end
452
479
 
453
- if not ARGV[0].nil? # argument(s) given
480
+ if __FILE__ == $0
481
+ if not ARGV[0].nil? # argument(s) given
454
482
 
455
- # Handle each task
456
- case ARGV[0].downcase
483
+ # Handle each task
484
+ case ARGV[0].downcase
457
485
 
458
- when 'rake'
459
- puts `rake #{ARGV[1..-1].join(' ')}`
486
+ when 'rake'
487
+ puts `rake #{ARGV[1..-1].join(' ')}`
460
488
 
461
- when 'validate'
462
- validate_plugin(ARGV[1], scope: ARGV[2], variables_file: ARGV[3])
489
+ when 'validate'
490
+ validate_plugin(ARGV[1], scope: ARGV[2], variables_file: ARGV[3])
463
491
 
464
- when 'load'
465
- load_plugin(ARGV[1], scope: ARGV[2], plugin_hash_file: ARGV[3])
492
+ when 'load'
493
+ load_plugin(ARGV[1], scope: ARGV[2], plugin_hash_file: ARGV[3])
466
494
 
467
- when 'unload'
468
- unload_plugin(ARGV[1], scope: ARGV[2])
495
+ when 'unload'
496
+ unload_plugin(ARGV[1], scope: ARGV[2])
469
497
 
470
- when 'geminstall'
471
- gem_install(ARGV[1])
498
+ when 'geminstall'
499
+ gem_install(ARGV[1])
472
500
 
473
- when 'generate'
474
- generate(ARGV[1..-1])
501
+ when 'generate'
502
+ generate(ARGV[1..-1])
475
503
 
476
- when 'migrate'
477
- migrate(ARGV[1..-1])
504
+ when 'migrate'
505
+ migrate(ARGV[1..-1])
478
506
 
479
- when 'rubysloc'
480
- puts `ruby /openc3/bin/rubysloc #{ARGV[1..-1].join(' ')}`
507
+ when 'rubysloc'
508
+ puts `ruby /openc3/bin/rubysloc #{ARGV[1..-1].join(' ')}`
481
509
 
482
- when 'cstol_converter'
483
- puts `ruby /openc3/bin/cstol_converter #{ARGV[1..-1].join(' ')}`
510
+ when 'cstol_converter'
511
+ puts `ruby /openc3/bin/cstol_converter #{ARGV[1..-1].join(' ')}`
484
512
 
485
- when 'xtce_converter'
486
- xtce_converter(ARGV[1..-1])
513
+ when 'xtce_converter'
514
+ xtce_converter(ARGV[1..-1])
487
515
 
488
- when 'bridge'
489
- ENV['OPENC3_NO_STORE'] = '1'
490
- filename = ARGV[1]
491
- filename = 'bridge.txt' unless filename
492
- bridge = OpenC3::Bridge.new(filename)
493
- begin
494
- while true
495
- sleep(1)
516
+ when 'bridge'
517
+ ENV['OPENC3_NO_STORE'] = '1'
518
+ filename = ARGV[1]
519
+ filename = 'bridge.txt' unless filename
520
+ bridge = OpenC3::Bridge.new(filename)
521
+ begin
522
+ while true
523
+ sleep(1)
524
+ end
525
+ rescue Interrupt
526
+ exit(0)
496
527
  end
497
- rescue Interrupt
498
- exit(0)
499
- end
500
528
 
501
- when 'bridgesetup'
502
- ENV['OPENC3_NO_STORE'] = '1'
503
- filename = ARGV[1]
504
- filename = 'bridge.txt' unless filename
505
- unless File.exist?(filename)
506
- OpenC3::BridgeConfig.generate_default(filename)
507
- end
508
-
509
- when 'help'
510
- print_usage()
529
+ when 'bridgesetup'
530
+ ENV['OPENC3_NO_STORE'] = '1'
531
+ filename = ARGV[1]
532
+ filename = 'bridge.txt' unless filename
533
+ unless File.exist?(filename)
534
+ OpenC3::BridgeConfig.generate_default(filename)
535
+ end
511
536
 
512
- when 'redis'
513
- case (ARGV[1])
514
- when 'keys'
515
- get_redis_keys()
516
- when 'hget'
517
- redis = Redis.new(url: $redis_url, username: ENV['OPENC3_REDIS_USERNAME'], password: ENV['OPENC3_REDIS_PASSWORD'])
518
- puts JSON.parse(redis.hget(ARGV[2], ARGV[3]), :allow_nan => true, :create_additions => true)
519
- else
520
- puts "Unknown redis task: #{ARGV[1]}\n"
521
- puts "Valid redis tasks: keys, hget"
522
- end
537
+ when 'help'
538
+ print_usage()
539
+
540
+ when 'redis'
541
+ case (ARGV[1])
542
+ when 'keys'
543
+ get_redis_keys()
544
+ when 'hget'
545
+ redis = Redis.new(url: $redis_url, username: ENV['OPENC3_REDIS_USERNAME'], password: ENV['OPENC3_REDIS_PASSWORD'])
546
+ puts JSON.parse(redis.hget(ARGV[2], ARGV[3]), :allow_nan => true, :create_additions => true)
547
+ else
548
+ puts "Unknown redis task: #{ARGV[1]}\n"
549
+ puts "Valid redis tasks: keys, hget"
550
+ end
523
551
 
524
- when 'removebase'
525
- # Used to remove tool base to better support enterprise upgrade
526
- scopes = OpenC3::ScopeModel.all
527
- scopes.each do |scope_name, scope|
528
- plugins = OpenC3::PluginModel.all(scope: scope_name)
529
- plugins.each do |plugin_name, plugin|
530
- if plugin["name"] =~ /tool-base/ and plugin["name"] !~ /enterprise/
531
- unload_plugin(plugin_name, scope: scope_name)
532
- end
533
- if plugin["name"] =~ /tool-admin/ and plugin["name"] !~ /enterprise/
534
- unload_plugin(plugin_name, scope: scope_name)
552
+ when 'removebase'
553
+ # Used to remove tool base to better support enterprise upgrade
554
+ scopes = OpenC3::ScopeModel.all
555
+ scopes.each do |scope_name, scope|
556
+ plugins = OpenC3::PluginModel.all(scope: scope_name)
557
+ plugins.each do |plugin_name, plugin|
558
+ if plugin["name"] =~ /tool-base/ and plugin["name"] !~ /enterprise/
559
+ unload_plugin(plugin_name, scope: scope_name)
560
+ end
561
+ if plugin["name"] =~ /tool-admin/ and plugin["name"] !~ /enterprise/
562
+ unload_plugin(plugin_name, scope: scope_name)
563
+ end
535
564
  end
536
565
  end
537
- end
538
566
 
539
- when 'removeenterprise'
540
- # Used to remove enterprise plugins to better support downgrade
541
- scopes = OpenC3::ScopeModel.all
542
- scopes.each do |scope_name, scope|
543
- plugins = OpenC3::PluginModel.all(scope: scope_name)
544
- plugins.each do |plugin_name, plugin|
545
- if plugin["name"] =~ /enterprise/
546
- unload_plugin(plugin_name, scope: scope_name)
567
+ when 'removeenterprise'
568
+ # Used to remove enterprise plugins to better support downgrade
569
+ scopes = OpenC3::ScopeModel.all
570
+ scopes.each do |scope_name, scope|
571
+ plugins = OpenC3::PluginModel.all(scope: scope_name)
572
+ plugins.each do |plugin_name, plugin|
573
+ if plugin["name"] =~ /enterprise/
574
+ unload_plugin(plugin_name, scope: scope_name)
575
+ end
547
576
  end
548
577
  end
549
- end
550
578
 
551
- when 'destroyscope'
552
- scope = OpenC3::ScopeModel.get_model(name: ARGV[1])
553
- scope.destroy
579
+ when 'destroyscope'
580
+ scope = OpenC3::ScopeModel.get_model(name: ARGV[1])
581
+ scope.destroy
582
+
583
+ when 'localinit'
584
+ OpenC3::LocalMode.local_init()
554
585
 
555
- else # Unknown task
586
+ else # Unknown task
587
+ print_usage()
588
+ abort("Unknown task: #{ARGV[0]}")
589
+ end
590
+
591
+ else # No arguments given
556
592
  print_usage()
557
- abort("Unknown task: #{ARGV[0]}")
558
593
  end
559
594
 
560
- else # No arguments given
561
- print_usage()
562
- end
595
+ end