openc3 6.4.2 → 6.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  # encoding: ascii-8bit
2
2
 
3
- # Copyright 2024 OpenC3, Inc.
3
+ # Copyright 2025 OpenC3, Inc.
4
4
  # All Rights Reserved.
5
5
  #
6
6
  # This program is free software; you can modify and/or redistribute it
@@ -18,7 +18,7 @@
18
18
 
19
19
  module OpenC3
20
20
  class CliGenerator
21
- GENERATORS = %w(plugin target microservice widget conversion limits_response tool tool_vue tool_angular tool_react tool_svelte)
21
+ GENERATORS = %w(plugin target microservice widget conversion processor limits_response tool tool_vue tool_angular tool_react tool_svelte)
22
22
  TEMPLATES_DIR = "#{File.dirname(__FILE__)}/../../../templates"
23
23
 
24
24
  # Called by openc3cli with ARGV[1..-1]
@@ -32,8 +32,8 @@ module OpenC3
32
32
 
33
33
  def self.check_args(args)
34
34
  args.each do |arg|
35
- if arg =~ /\s/
36
- abort("#{args[0].to_s.downcase} arguments can not have spaces!") unless args[0].to_s.downcase[0..3] == 'tool'
35
+ if arg =~ /\s/ and args[0].to_s.downcase[0..3] != 'tool'
36
+ abort("#{args[0].to_s.downcase} arguments can not have spaces!")
37
37
  end
38
38
  end
39
39
  # All generators except 'plugin' must be within an existing plugin
@@ -58,12 +58,12 @@ module OpenC3
58
58
  def self.process_template(template_dir, the_binding)
59
59
  Dir.glob("#{template_dir}/**/*", File::FNM_DOTMATCH).each do |file|
60
60
  next if File.basename(file) == '.'
61
- if @@language == 'rb'
61
+ if @@language == 'rb' and File.extname(file) == '.py'
62
62
  # Ignore python files if we're ruby
63
- next if File.extname(file) == '.py'
64
- elsif @@language == 'py'
63
+ next
64
+ elsif @@language == 'py' and File.extname(file) == '.rb'
65
65
  # Ignore ruby files if we're python
66
- next if File.extname(file) == '.rb'
66
+ next
67
67
  end
68
68
  base_name = file.sub("#{template_dir}/", '')
69
69
  next if yield base_name
@@ -113,8 +113,8 @@ module OpenC3
113
113
  abort("Target #{target_path} already exists!")
114
114
  end
115
115
  target_lib_filename = "#{target_name.downcase}.#{@@language}"
116
- target_class = target_lib_filename.filename_to_class_name
117
- target_object = target_name.downcase
116
+ target_class = target_lib_filename.filename_to_class_name # NOSONAR
117
+ target_object = target_name.downcase # NOSONAR
118
118
 
119
119
  process_template("#{TEMPLATES_DIR}/target", binding) do |filename|
120
120
  # Rename the template TARGET to our actual target named after the plugin
@@ -175,7 +175,7 @@ module OpenC3
175
175
  abort("Microservice #{microservice_path} already exists!")
176
176
  end
177
177
  microservice_filename = "#{microservice_name.downcase}.#{@@language}"
178
- microservice_class = microservice_filename.filename_to_class_name
178
+ microservice_class = microservice_filename.filename_to_class_name # NOSONAR
179
179
 
180
180
  process_template("#{TEMPLATES_DIR}/microservice", binding) do |filename|
181
181
  # Rename the template MICROSERVICE to our actual microservice name
@@ -310,9 +310,8 @@ module OpenC3
310
310
  abort("Target '#{target_name}' does not exist! Conversions must be created for existing targets.")
311
311
  end
312
312
  conversion_name = "#{args[2].upcase.gsub(/_+|-+/, '_')}_CONVERSION"
313
- conversion_path = "targets/#{target_name}/lib/"
314
313
  conversion_basename = "#{conversion_name.downcase}.#{@@language}"
315
- conversion_class = conversion_basename.filename_to_class_name
314
+ conversion_class = conversion_basename.filename_to_class_name # NOSONAR
316
315
  conversion_filename = "targets/#{target_name}/lib/#{conversion_basename}"
317
316
  if File.exist?(conversion_filename)
318
317
  abort("Conversion #{conversion_filename} already exists!")
@@ -329,6 +328,35 @@ module OpenC3
329
328
  return conversion_name
330
329
  end
331
330
 
331
+ def self.generate_processor(args)
332
+ if args.length < 3 or args.length > 4
333
+ abort("Usage: cli generate processor <TARGET> <NAME> (--ruby or --python)")
334
+ end
335
+
336
+ # Create the local variables
337
+ target_name = args[1].upcase
338
+ unless File.exist?("targets/#{target_name}")
339
+ abort("Target '#{target_name}' does not exist! Processors must be created for existing targets.")
340
+ end
341
+ processor_name = "#{args[2].upcase.gsub(/_+|-+/, '_')}_PROCESSOR"
342
+ processor_basename = "#{processor_name.downcase}.#{@@language}"
343
+ processor_class = processor_basename.filename_to_class_name # NOSONAR
344
+ processor_filename = "targets/#{target_name}/lib/#{processor_basename}"
345
+ if File.exist?(processor_filename)
346
+ abort("Processor #{processor_filename} already exists!")
347
+ end
348
+
349
+ process_template("#{TEMPLATES_DIR}/processor", binding) do |filename|
350
+ filename.sub!("processor.#{@@language}", processor_filename)
351
+ false
352
+ end
353
+
354
+ puts "Processor #{processor_filename} successfully generated!"
355
+ puts "To use the processor add the following to a telemetry packet:"
356
+ puts " PROCESSOR #{args[2].upcase} #{processor_basename} <PARAMS...>"
357
+ return processor_name
358
+ end
359
+
332
360
  def self.generate_limits_response(args)
333
361
  if args.length < 3 or args.length > 4
334
362
  abort("Usage: cli generate limits_response <TARGET> <NAME> (--ruby or --python)")
@@ -340,10 +368,9 @@ module OpenC3
340
368
  abort("Target '#{target_name}' does not exist! Limits responses must be created for existing targets.")
341
369
  end
342
370
  response_name = "#{args[2].upcase.gsub(/_+|-+/, '_')}_LIMITS_RESPONSE"
343
- response_path = "targets/#{target_name}/lib/"
344
371
  response_basename = "#{response_name.downcase}.#{@@language}"
345
- response_class = response_basename.filename_to_class_name
346
372
  response_filename = "targets/#{target_name}/lib/#{response_basename}"
373
+ response_class = response_basename.filename_to_class_name # NOSONAR
347
374
  if File.exist?(response_filename)
348
375
  abort("response #{response_filename} already exists!")
349
376
  end