machine_setup 0.4.1 → 0.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.
@@ -21,6 +21,12 @@ SetupConfiguration :<%= @name.to_sym %>, :<%= @abbreviation.to_sym %> do
21
21
  <% if param.type? %>
22
22
  for_machine_type <%= compute_machine_types(param.machine_type) %>
23
23
  <% end %>
24
+ <% if param.options? %>
25
+ has_options <%= render_options(param.options) %>
26
+ <% end %>
27
+ <% if param.roles? %>
28
+ enabled_for_role <%= render_roles(param.roles) %>
29
+ <% end %>
24
30
  end
25
31
  <% else %>
26
32
 
@@ -7,7 +7,8 @@ module SetupConfiguration
7
7
  class MPSTemplateBinding < TemplateBinding
8
8
 
9
9
  def initialize
10
- yield self
10
+ yield self if block_given?
11
+ @max_number_parameters_per_tab=50
11
12
  end
12
13
 
13
14
  def languages
@@ -20,15 +21,18 @@ module SetupConfiguration
20
21
 
21
22
  def param_infos(category_key)
22
23
  parameters=suite.categories[category_key]
23
- depends, machine_type, number=[], [], []
24
+ depends, machine_type, number, options, roles=[], [], [], [], []
24
25
  parameters.each() do |param|
25
26
  machine_type << param.machine_type
26
27
  number << param.number
27
28
  depends << depends_on(param.dependency)
29
+ options << param.options
30
+ roles << param.roles
28
31
  end
29
32
  #TODO compute value for max_number_parameters_per_tab of value maximum_numbers_per_category
30
- max_number_parameters_per_tab=50
31
- [depends, machine_type, number].collect() { |arr| (arr.in_groups_of(max_number_parameters_per_tab, false)).collect() { |a| prepare(a) } }
33
+ bundle = [depends, machine_type, number, options, roles].collect() { |arr| arr.in_groups_of(@max_number_parameters_per_tab, false) }
34
+ bundle = sanitize(bundle)
35
+ bundle.collect(){ |v| v.collect(){ |arr| prepare(arr) } }
32
36
  end
33
37
 
34
38
  private
@@ -53,6 +57,53 @@ module SetupConfiguration
53
57
  end
54
58
  end
55
59
 
60
+ def sanitize(bundle)
61
+ count_params = bundle.first.flatten.length
62
+ if count_params <= @max_number_parameters_per_tab
63
+ bundle
64
+ else
65
+ depends, machine_type, number, options, roles = *bundle
66
+ # iterating with each_cons(2) would be much nicer, but how do I get the index for shifting...
67
+ length = number.length
68
+ number.each_with_index() do |param_num, index|
69
+ if index < length-1
70
+ next_number_dup = number[index+1].dup
71
+ # use next_number_dup for iteration as we are changing number[index+1]
72
+ # iterate second array until the parameter group ends
73
+ next_number_dup.each() do |second|
74
+ group = param_group?(param_num.last, second)
75
+ if group
76
+ bundle.each() do |member|
77
+ member[index] << member[index+1].shift
78
+ end
79
+ else
80
+ break
81
+ end
82
+ end
83
+ end
84
+ end
85
+
86
+ bundle
87
+ end
88
+ end
89
+
90
+ # Does these two parameters belong to the same "parameter group"?
91
+ # The definition of a parameter group (as needed for working around 'grouping bug' in new setup editor):
92
+ # Two parameters shall be grouped together if:
93
+ # - two 'physical' consecutive parameters have also consecutive parameter numbers
94
+ # and
95
+ # - these two parameters have the same dependency
96
+ # or
97
+ # the second parameter depends on the first parameter
98
+ def param_group?(last, first)
99
+ p1 = find_param_by_number(last)
100
+ p2 = find_param_by_number(first)
101
+ # parameters have sequenced numbers
102
+ result = (p1.number - p2.number).abs.eql?(1)
103
+ # parameters have same dependency or second parameter depends on first parameter
104
+ result && ( p1.dependency.eql?(p2.dependency) || p2.dependency.eql?(p1.key))
105
+ end
106
+
56
107
  end
57
108
  end
58
109
  end
@@ -22,22 +22,23 @@ module SetupConfiguration
22
22
 
23
23
  def cat_name(cat)
24
24
  name, desc=@translator.translate(cat.name, @lang)
25
- $stderr.puts("WARNING: missing translation for key #@lang.#{cat.name}.#{Translation::Translator::NAME}") if name.eql?(cat.name.to_s)
25
+ $stderr.puts("WARNING: missing translation for key #{@lang}.#{cat.name}.#{Translation::Translator::NAME}") if name.eql?(cat.name.to_s)
26
26
  name
27
27
  end
28
28
 
29
29
  def name(number)
30
30
  p_name= translate(number) { |name, desc| name }
31
- if find_param_by_number(number) && p_name.eql?(find_param_by_number(number).key.to_s)
32
- $stderr.puts("WARNING: missing translation for key #@lang.#{find_param_by_number(number).key.to_s}.#{Translation::Translator::NAME}")
31
+ param = find_param_by_number(number)
32
+ if param && p_name.eql?(param.key.to_s)
33
+ $stderr.puts("WARNING: missing translation for key #{@lang}.#{param.key.to_s}.#{Translation::Translator::NAME}")
33
34
  end
34
- p_name.empty? ? "placeholder for mps3.exe" : p_name
35
+ p_name.empty? ? 'placeholder for mps3.exe' : p_name
35
36
  end
36
37
 
37
38
  def description(number)
38
39
  translate(number) do |name, desc|
39
40
  begin
40
- $stderr.puts("WARNING: missing translation for key #@lang.#{find_param_by_number(number).key.to_s}.#{Translation::Translator::COMMENT}") if desc.empty?
41
+ $stderr.puts("WARNING: missing translation for key #{@lang}.#{find_param_by_number(number).key.to_s}.#{Translation::Translator::COMMENT}") if desc.empty?
41
42
  rescue
42
43
  raise RuntimeError.new("ERROR: reading translation failed '#{desc.inspect()}'")
43
44
  end
@@ -56,7 +57,7 @@ module SetupConfiguration
56
57
  translation
57
58
  end
58
59
  else
59
- ""
60
+ ''
60
61
  end
61
62
  end
62
63
 
@@ -16,7 +16,7 @@ module SetupConfiguration
16
16
  private
17
17
 
18
18
  def template
19
- find_template("logcodesetup.exp.erb")
19
+ find_template('logcodesetup.exp.erb')
20
20
  end
21
21
 
22
22
  end
@@ -19,11 +19,13 @@ module SetupConfiguration
19
19
  attr_accessor :name
20
20
  attr_accessor :abbreviation
21
21
  attr_accessor :next_category_number
22
+ attr_reader :maximum_numbers_per_category
22
23
 
23
24
  def initialize
24
25
  self.categories= Hash.new { |hash, key| hash[key] = [] }
25
26
  self.settings= Setting.new()
26
27
  self.next_category_number = 0
28
+ @maximum_numbers_per_category = 150
27
29
  end
28
30
 
29
31
  def category(category, &category_params)
@@ -46,7 +48,7 @@ module SetupConfiguration
46
48
  end
47
49
 
48
50
  def category_by_name(name)
49
- cat = self.categories.keys.select(){|c| c.name.eql?(name)}.first
51
+ cat = self.categories.keys.detect(){|c| c.name.eql?(name)}
50
52
  unless cat
51
53
  cat = Category.new
52
54
  cat.number = self.next_category_number!
@@ -66,7 +68,7 @@ module SetupConfiguration
66
68
  end
67
69
 
68
70
  # Gets all known parameters.
69
- def parameters()
71
+ def parameters
70
72
  # cache parameters so sorting is necessary only once - this saves a lot of time...
71
73
  @parameters ||= categories.values.flatten.sort
72
74
  end
@@ -84,7 +86,7 @@ module SetupConfiguration
84
86
  # If there is no such parameter the method returns nil.
85
87
  #
86
88
  def find_param_by_key(key)
87
- self.parameters().select(){|p| p.key.eql?(key)}.first
89
+ self.parameters().detect(){|p| p.key.eql?(key)}
88
90
  end
89
91
 
90
92
  #
@@ -92,16 +94,16 @@ module SetupConfiguration
92
94
  # If there is no such parameter the method returns nil.
93
95
  #
94
96
  def find_param_by_number(number)
95
- self.parameters().select(){|p| p.number.eql?(number)}.first
97
+ self.parameters().detect(){|p| p.number.eql?(number)}
96
98
  end
97
99
 
98
100
  #
99
101
  # Validates the uniqueness of parameter keys and numbers.
100
102
  #
101
- def validate_params()
103
+ def validate_params
102
104
 
103
105
  categories.each() do |key, value|
104
- throw RuntimeError.new("ERROR: category '#{key}' contains more than 150 parameters. Reduce parameter count.") if value.size >150
106
+ throw RuntimeError.new("ERROR: category '#{key}' contains more than #{maximum_numbers_per_category} parameters. Reduce parameter count.") if value.size >maximum_numbers_per_category
105
107
  end
106
108
 
107
109
  keys=[]
@@ -137,7 +139,7 @@ module SetupConfiguration
137
139
  end#validate_params
138
140
 
139
141
  def assign_param_ref(ref)
140
- param = self.parameters().select(){|p| p.key.eql?(ref.key) && p.param?}.first
142
+ param = self.parameters().detect(){|p| p.key.eql?(ref.key) && p.param?}
141
143
 
142
144
  if param
143
145
  ref.assign(param)
@@ -205,7 +207,7 @@ module SetupConfiguration
205
207
  attr_accessor :name
206
208
  attr_accessor :parameter
207
209
 
208
- def initialize()
210
+ def initialize
209
211
  @parameter = []
210
212
  end
211
213
 
@@ -246,13 +248,13 @@ module SetupConfiguration
246
248
  #
247
249
  def drive(drive, number, added_props=[], &parameter_def)
248
250
 
249
- key = symbol(drive, "drive")
250
- drive_selection = symbol(key, "selection")
251
+ key = symbol(drive, 'drive')
252
+ drive_selection = symbol(key, 'selection')
251
253
 
252
254
  drive_param=param(drive_selection, number)
253
255
  drive_param.instance_eval(&parameter_def) if parameter_def
254
256
 
255
- properties=[%w(distance revolution), %w(gear in), %w(gear out), "length", "motortype"]
257
+ properties=[%w(distance revolution), %w(gear in), %w(gear out), 'length', 'motortype']
256
258
  properties += added_props if added_props
257
259
  properties.each_with_index do |prop, index|
258
260
  parameter = param(symbol(key, *prop), number + index + 1) { depends_on drive_selection }
@@ -268,6 +270,39 @@ module SetupConfiguration
268
270
  end
269
271
  end
270
272
 
273
+ class SoftwareOptions
274
+ include BinaryCodedValues
275
+
276
+ OPTIONS = {:do_not_copy => 1, :needs_licence => 2}
277
+
278
+ def values
279
+ OPTIONS
280
+ end
281
+
282
+ # TODO check for maximum and raise error
283
+ def compute_options(number)
284
+ value(number)
285
+ end
286
+
287
+ end
288
+
289
+ class Roles
290
+ include BinaryCodedValues
291
+
292
+ ROLES = {:foreman => 1, :service => 2, :application_engineer => 4, :test_bay => 8, :developer => 16}
293
+
294
+ def values
295
+ ROLES
296
+ end
297
+
298
+ # TODO check for maximum and raise error
299
+ def compute_roles(number)
300
+ value(number)
301
+ end
302
+
303
+
304
+ end
305
+
271
306
  class Parameter
272
307
  include Enumerable
273
308
  include ParameterMachineTypeBridge
@@ -276,14 +311,20 @@ module SetupConfiguration
276
311
  attr_accessor :number
277
312
  attr_reader :dependency
278
313
  attr_reader :machine_type
314
+ attr_reader :options
315
+ attr_reader :roles
279
316
 
280
317
  def initialize(name, number)
281
318
  # depends upon no other parameter
282
319
  @dependency=:none
283
320
  # valid on all machines
284
321
  @machine_type=0
322
+ @options=0
323
+ @roles=0
285
324
  @key= name
286
325
  @number=number
326
+ @role = Roles.new
327
+ @option = SoftwareOptions.new
287
328
  end
288
329
 
289
330
  def depends_on(dependency)
@@ -294,6 +335,22 @@ module SetupConfiguration
294
335
  @machine_type=machine_type
295
336
  end
296
337
 
338
+ def has_options(*opt)
339
+ # use @options as initial value: multiple calls to has_options are possible and result value is chained
340
+ # (and not reset if using '0' as explicit initial value)
341
+ @options = opt.uniq.inject(@options) do |sum, o|
342
+ sum + @option.number(o)
343
+ end
344
+ end
345
+
346
+ def enabled_for_role(*roles)
347
+ # use @roles as initial value: multiple calls to enabled_for_role are possible and result value is chained
348
+ # (and not reset if using '0' as explicit initial value)
349
+ @roles = roles.uniq.inject(@roles) do |sum, r|
350
+ sum + @role.number(r)
351
+ end
352
+ end
353
+
297
354
  def <=>(parameter)
298
355
  self.number <=> parameter.number
299
356
  end
@@ -334,6 +391,14 @@ module SetupConfiguration
334
391
  assigned? ? @param.dependency : :none
335
392
  end
336
393
 
394
+ def options
395
+ assigned? ? @param.options : 0
396
+ end
397
+
398
+ def roles
399
+ assigned? ? @param.roles : 0
400
+ end
401
+
337
402
  def <=>(parameter)
338
403
  self.number <=> parameter.number
339
404
  end
@@ -18,7 +18,7 @@ module SetupConfiguration
18
18
  end
19
19
 
20
20
  def generate
21
- return "no output" if self.do_not_run
21
+ return 'no output' if self.do_not_run
22
22
 
23
23
  description_bindings().each() do |bind|
24
24
  bind.suite=self.suite
@@ -26,13 +26,19 @@ BEGIN_TYP<%= machine_type.sequence_number_coded %>=<%= machine_type.range.first
26
26
 
27
27
  [PARAMANZEIGE]
28
28
  <% categories.each_with_index do |category, index| %>
29
- <% dependencies, machine_types, parameters = param_infos(category) %>
29
+ <% dependencies, machine_types, parameters, options, roles = param_infos(category) %>
30
+ 4CF<%= index%>a=<%= roles[0] %>
31
+ 3CF<%= index%>a=<%= options[0] %>
30
32
  2CF<%= index%>a=<%= dependencies[0] %>
31
33
  1CF<%= index%>a=<%= machine_types[0] %>
32
34
  TAB<%= index%>a=<%= parameters[0] %>
35
+ 4CF<%= index%>b=<%= roles[1] %>
36
+ 3CF<%= index%>b=<%= options[1] %>
33
37
  2CF<%= index%>b=<%= dependencies[1] %>
34
38
  1CF<%= index%>b=<%= machine_types[1] %>
35
39
  TAB<%= index%>b=<%= parameters[1] %>
40
+ 4CF<%= index%>c=<%= roles[2] %>
41
+ 3CF<%= index%>c=<%= options[2] %>
36
42
  2CF<%= index%>c=<%= dependencies[2] %>
37
43
  1CF<%= index%>c=<%= machine_types[2] %>
38
44
  TAB<%= index%>c=<%= parameters[2] %>
@@ -4,7 +4,7 @@ module SetupConfiguration
4
4
 
5
5
  module Translation
6
6
 
7
- FILE_EXTENSION="setup.param".freeze
7
+ FILE_EXTENSION='setup.param'.freeze
8
8
 
9
9
  def self.translation_file(config_name, lang)
10
10
  "#{config_name}.#{FILE_EXTENSION}.#{lang}.yml"
@@ -15,26 +15,26 @@ module SetupConfiguration
15
15
  end
16
16
 
17
17
  # Returns all supported setup languages.
18
- def self.languages()
19
- language_defs().keys()
18
+ def self.languages
19
+ language_defs.keys
20
20
  end
21
21
 
22
22
  def self.language_name(lang)
23
- language_defs()[lang]
23
+ language_defs[lang]
24
24
  end
25
25
 
26
26
  def self.language_abbreviation(lang_name)
27
- language_defs.invert()[lang_name.downcase]
27
+ language_defs.invert[lang_name.downcase]
28
28
  end
29
29
 
30
- def self.language_names()
30
+ def self.language_names
31
31
  language_defs.values.sort
32
32
  end
33
33
 
34
34
  private
35
35
 
36
- def self.language_defs()
37
- {:de => "deutsch", :en => "english"}
36
+ def self.language_defs
37
+ {:de => 'deutsch', :en => 'english'}
38
38
  end
39
39
 
40
40
  class Translator
@@ -44,6 +44,10 @@ module SetupConfiguration
44
44
  COMMENT = :comment.freeze
45
45
  EMPTY = ''
46
46
 
47
+ if I18n.respond_to?(:enforce_available_locales)
48
+ I18n.enforce_available_locales = true
49
+ end
50
+
47
51
  # Adds a file with translations.
48
52
  def self.i18n_load_path(path)
49
53
  I18n.load_path << path
@@ -0,0 +1,35 @@
1
+ [EINSTELLUNG]
2
+ TABSTART=2
3
+ DRUCK=0
4
+ DATKONVERT=0
5
+
6
+ [SPRACHE]
7
+ AKTUELL=0
8
+ SPRACHE0=DEUTSCH
9
+ SPRACHE1=ENGLISH
10
+
11
+ [MINMAXWERTE]
12
+ BEGIN_MIN=0
13
+ END_MIN=0
14
+ BEGIN_MAX=0
15
+ END_MAX=0
16
+ BEGIN_WAAG_MIN=3000
17
+ END_WAAG_MIN=3029
18
+ BEGIN_WAAG_MAX=3030
19
+ END_WAAG_MAX=3059
20
+
21
+ [MASCHINENTYP]
22
+ BEGIN_TYP0=1000
23
+ BEGIN_TYP1=2000
24
+ BEGIN_TYP2=3000
25
+
26
+ [PARAMANZEIGE]
27
+ 2CF1a=-1,-1,-1,31
28
+ 1CF1a=0,0,0,0
29
+ TAB1a=29,30,31,32
30
+ 2CF1b=
31
+ 1CF1b=
32
+ TAB1b=
33
+ 2CF1c=
34
+ 1CF1c=
35
+ TAB1c=