machine_setup 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,58 @@
1
+ # encoding: windows-1252
2
+
3
+ module SetupConfiguration
4
+
5
+ module Generator
6
+
7
+ class MPSTemplateBinding < TemplateBinding
8
+
9
+ def initialize
10
+ yield self
11
+ end
12
+
13
+ def languages
14
+ Translation.language_names
15
+ end
16
+
17
+ def settings
18
+ self.suite.settings
19
+ end
20
+
21
+ def param_infos(category_key)
22
+ parameters=suite.categories[category_key]
23
+ depends, machine_type, number=[], [], []
24
+ parameters.each() do |param|
25
+ machine_type << param.machine_type
26
+ number << param.number
27
+ depends << depends_on(param.dependency)
28
+ end
29
+ #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) } }
32
+ end
33
+
34
+ :private
35
+
36
+ def prepare(array)
37
+ array.join(',')
38
+ end
39
+
40
+ def depends_on(key)
41
+
42
+ if :none.eql?(key) then
43
+ -1
44
+ else
45
+ param=suite.find_param(key)
46
+ if param
47
+ param.number
48
+ else
49
+ $stderr.puts "ERROR: parameter with key '#{key}' not found."
50
+ # depends on no other parameter
51
+ -1
52
+ end
53
+ end
54
+ end
55
+
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,71 @@
1
+ # encoding: windows-1252
2
+
3
+ module SetupConfiguration
4
+
5
+ module Generator
6
+
7
+ class ParameterTemplateBinding < TemplateBinding
8
+ attr_accessor :lang
9
+ attr_accessor :parameter_range
10
+
11
+ def initialize(lang, range, output)
12
+ @lang=lang
13
+ @parameter_range=range
14
+ @output=output
15
+ @translator = Translation::Translator.new()
16
+ end
17
+
18
+ def lang_name
19
+ Translation.language_name(lang)
20
+ end
21
+
22
+
23
+ def cat_name(cat)
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)
26
+ name
27
+ end
28
+
29
+ def name(number)
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}")
33
+ end
34
+ p_name.empty? ? "placeholder for mps3.exe" : p_name
35
+ end
36
+
37
+ def description(number)
38
+ translate(number) do |name, desc|
39
+ $stderr.puts("WARNING: missing translation for key #{@lang}.#{find_param_by_number(number).key.to_s}.#{Translation::Translator::COMMENT}") if desc.empty?
40
+ escape(desc)
41
+ end
42
+ end
43
+
44
+ def translate(number, &extractor)
45
+ p=find_param_by_number(number)
46
+ if p
47
+ key=p.key
48
+ translation = @translator.translate(key, @lang)
49
+ if extractor
50
+ extractor.call(*translation)
51
+ else
52
+ translation
53
+ end
54
+ else
55
+ ""
56
+ end
57
+ end
58
+
59
+ private
60
+
61
+ #
62
+ # Zeilenumbr�che werden mit '��' dargestellt
63
+ # \302\247 - oktale Darstellung von � (Paragraphenzeichen)
64
+ #
65
+ def escape(message)
66
+ message.gsub(/\n\s?/, '��')
67
+ end
68
+
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,40 @@
1
+ module SetupConfiguration
2
+
3
+ class SetupCodeBinding < Generator::TemplateBinding
4
+
5
+ def initialize
6
+ super
7
+ end
8
+
9
+ def parameters
10
+ #TODO use set or something similar
11
+ suite.parameters.select() { |p| p.param? }
12
+ end
13
+
14
+ #
15
+ # Offset for setup parameter numbers. This offset is added to a parameter number when evaluated in controller.
16
+ #
17
+ def parameter_offset
18
+ 1300
19
+ end
20
+
21
+ def key(symbol)
22
+ s=symbol.to_s
23
+ delimiter='_'
24
+ s.split(delimiter).collect() { |splitter| splitter.capitalize }.join(delimiter).ljust(longest_key_length)
25
+ end
26
+
27
+ :private
28
+
29
+ def longest_key_length
30
+ # find the length of the longest word
31
+ unless @longest
32
+ longest = parameters.inject(0) do |memo, param|
33
+ memo >= param.key.to_s.length ? memo : param.key.to_s.length
34
+ end
35
+ @longest=longest + 5
36
+ end
37
+ @longest
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,24 @@
1
+ # encoding: windows-1252
2
+
3
+ module SetupConfiguration
4
+
5
+ class SetupCodeGenerator
6
+ include Generator
7
+
8
+ def generate(suite, output_path)
9
+ setup_code=SetupCodeBinding.new
10
+ setup_code.output="LOGCODE#{suite.name.to_s.upcase}SETUP.EXP"
11
+ setup_code.suite=suite
12
+ self.output_path=output_path
13
+ output(setup_code, template)
14
+ end
15
+
16
+ :private
17
+
18
+ def template
19
+ find_template("logcodesetup.exp.erb")
20
+ end
21
+
22
+ end
23
+
24
+ end
@@ -41,7 +41,7 @@ module SetupConfiguration
41
41
  # flatten is needed: Parameters#param returns an array which is inserted in an array...
42
42
  categories[cat].flatten!
43
43
  else
44
- puts "WARNING: Empty category '#{category}' will be ignored. "
44
+ $stderr.puts "WARNING: Empty category '#{category}' will be ignored. "
45
45
  end
46
46
  end
47
47
 
@@ -111,7 +111,7 @@ module SetupConfiguration
111
111
 
112
112
  self.parameters().each() do |p|
113
113
 
114
- puts "WARNING: parameter number 404 is reserved for machine type. you are using it for '#{p.key}'." if p.number.eql?(404)
114
+ $stderr.puts "WARNING: parameter number 404 is reserved for machine type. you are using it for '#{p.key}'." if p.number.eql?(404)
115
115
  throw RuntimeError.new("ERROR: parameter number '#{p.number}' not supported. Number must be in range #{valid_param_numbers}.") unless valid_param_numbers.member?(p.number)
116
116
 
117
117
  if p.param?
@@ -180,6 +180,7 @@ module SetupConfiguration
180
180
  @balance_maximum=range
181
181
  end
182
182
 
183
+ #TODO remove range argument
183
184
  def machine_type(name, number, range)
184
185
  machine_type = MachineType.new(name, number, range)
185
186
  @machine_types << machine_type
@@ -228,6 +229,7 @@ module SetupConfiguration
228
229
  p = Parameter.new(parameter, number)
229
230
  p.instance_eval(&parameter_def) if parameter_def
230
231
  params << p
232
+ p
231
233
  end
232
234
 
233
235
  def param_ref(parameter)
@@ -235,6 +237,34 @@ module SetupConfiguration
235
237
  params << p
236
238
  end
237
239
 
240
+
241
+ #
242
+ # Additional block is allowed, it may contain call for_machine_type and depends_on.
243
+ # This additional information is applied only to generated parameter
244
+ # <drive>_selection.
245
+ # The additional for_machine_type is also applied to other generated parameters.
246
+ #
247
+ def drive(drive, number, &parameter_def)
248
+
249
+ key = symbol(drive, "drive")
250
+ drive_selection = symbol(key, "selection")
251
+
252
+ drive_param=param(drive_selection, number)
253
+ drive_param.instance_eval(&parameter_def) if parameter_def
254
+
255
+ properties=[%w(distance revolution), %w( gear in ), %w( gear out ), "length", "motortype" ]
256
+ properties.each_with_index do |prop, index|
257
+ parameter = param(symbol(key, *prop), number + index + 1) { depends_on drive_selection }
258
+ parameter.for_machine_type(drive_param.machine_type)
259
+ end
260
+
261
+ end
262
+
263
+ :private
264
+
265
+ def symbol(*strings)
266
+ strings.join('_').to_sym
267
+ end
238
268
  end
239
269
 
240
270
  class Parameter
@@ -316,6 +346,8 @@ module SetupConfiguration
316
346
  class MachineType
317
347
  include Enumerable
318
348
 
349
+ RANGES = [0..999, 1000..1999, 2000..2499, 2500..2999, 3000..3999, 4000..4999, 5000..5999, 6000..6999].freeze
350
+
319
351
  attr_reader :name
320
352
  attr_reader :range
321
353
  attr_reader :sequence_number
@@ -323,8 +355,9 @@ module SetupConfiguration
323
355
 
324
356
  def initialize(name, sequence_number, range)
325
357
  @name=name
326
- @range=range
358
+ raise RuntimeError.new("ERROR: More than #{RANGES.length} different machine types are not supported: [name=#{name}] [number=#{sequence_number}]") if sequence_number >= RANGES.length
327
359
  @sequence_number=sequence_number
360
+ @range=RANGES[@sequence_number]
328
361
  if @sequence_number <= 0
329
362
  @binary_number=0
330
363
  else
@@ -339,4 +372,4 @@ module SetupConfiguration
339
372
  end
340
373
 
341
374
  end
342
-
375
+
@@ -1,332 +1,50 @@
1
- # encoding: utf-8
1
+ # encoding: windows-1252
2
2
 
3
- module SetupConfiguration::Generator
4
- @output_path=""
3
+ module SetupConfiguration
5
4
 
6
- def output_path
7
- @output_path
8
- end
9
-
10
- def output_path=(out)
11
- @output_path=out
12
- end
13
-
14
- class TemplateBinding
5
+ class SuiteGenerator
6
+ include Generator
15
7
 
16
8
  attr_accessor :suite
17
- attr_accessor :output
18
-
19
- def categories
20
- #TODO maybe cache these values for better performance...?
21
- suite.categories.keys().sort()
22
- end
23
-
24
- # Support templating of member data.
25
- def get_binding
26
- binding
27
- end
28
-
29
- end
30
-
31
- class ParameterTemplateBinding < TemplateBinding
32
- attr_accessor :lang
33
- attr_accessor :parameter_range
34
-
35
- def initialize(lang, range, output)
36
- @lang=lang
37
- @parameter_range=range
38
- @output=output
39
- @translator = SetupConfiguration::Translation::Translator.new()
40
- end
41
-
42
- def lang_name
43
- SetupConfiguration::Translation.language_name(lang)
44
- end
45
-
46
-
47
- def cat_name(cat)
48
- name, desc=@translator.translate(cat.name, @lang)
49
- name
50
- end
51
-
52
- def name(number)
53
- p_name= translate(number) { |name, desc| name }
54
- p_name.empty? ? "placeholder for mps3.exe" : p_name
55
- end
56
-
57
- def description(number)
58
- translate(number) do |name, desc|
59
- escape(desc)
60
- end
61
- end
62
-
63
- def translate(number, &extractor)
64
- p=self.suite.find_param_by_number(number)
65
- if p
66
- key=p.key
67
- translation = @translator.translate(key, @lang)
68
- if extractor
69
- extractor.call( *translation )
70
- else
71
- translation
72
- end
73
- else
74
- ""
75
- end
76
- end
9
+ attr_accessor :do_not_run
77
10
 
78
- private
79
-
80
- #
81
- # Zeilenumbr�che werden mit '��' dargestellt
82
- # \302\247 - oktale Darstellung von �
83
- #
84
- def escape(message)
85
- message.gsub(/\n\s?/, '��' )
11
+ def initialize
12
+ self.do_not_run = false
13
+ self.suite = Suite.instance
86
14
  end
87
15
 
88
- end
89
-
90
- class MPSTemplateBinding < TemplateBinding
91
-
92
- def languages
93
- SetupConfiguration::Translation.language_names.values
16
+ def self.do_not_run
17
+ self.do_not_run=true
94
18
  end
95
19
 
96
- def settings
97
- self.suite.settings
98
- end
20
+ def generate
21
+ return "no output" if self.do_not_run
99
22
 
100
- def param_infos(category_key)
101
- parameters=suite.categories[category_key]
102
- depends, machine_type, number=[], [], []
103
- parameters.each() do |param|
104
- machine_type << param.machine_type
105
- number << param.number
106
- depends << depends_on(param.dependency)
107
- end
108
- #TODO compute value for max_number_parameters_per_tab of value maximum_numbers_per_category
109
- max_number_parameters_per_tab=50
110
- [depends, machine_type, number].collect(){ |arr| (arr.in_groups_of(max_number_parameters_per_tab, false)).collect(){|a| prepare(a)}}
111
- end
23
+ description_bindings().each() do |bind|
24
+ bind.suite=self.suite
112
25
 
113
- :private
114
-
115
- def prepare(array)
116
- array.join(',')
117
- end
118
-
119
- def depends_on(key)
120
-
121
- if :none.eql?(key) then
122
- -1
123
- else
124
- param=suite.find_param(key)
125
- if param
126
- param.number
127
- else
128
- puts "ERROR: parameter with key '#{key}' not found."
129
- # depends on no other parameter
130
- -1
131
- end
26
+ output(bind, description_template)
132
27
  end
133
- end
134
-
135
- end
136
28
 
137
- # [:de, "deutsch", (0..199), "deutsch1.lng"],
138
- # [:de, "deutsch", (200..599), "deutsch2.lng"],
139
- # [:de, "deutsch", (600..1299), "deutsch3.lng"],
140
- # [:en, "english", (0..199), "english1.lng"],
141
- # [:en, "english", (200..599), "english2.lng"],
142
- # [:en, "english", (600..1299), "english3.lng"],
143
- def description_bindings()
144
- SetupConfiguration::Translation.languages().collect() do |lang|
145
- SetupConfiguration.description_ranges().collect() do |range|
146
- # constructs the output file names
147
- out= "#{SetupConfiguration::Translation.language_name(lang)}#{SetupConfiguration.description_ranges().index(range)+1}.lng"
148
- ParameterTemplateBinding.new(lang, range, out)
29
+ # extras:
30
+ # -every PARAMETER key needs a value!
31
+ # -use Windows line terminators CRLF - \r\n
32
+ # - do not use []
33
+ #- output is an INI-file
34
+ parameter_bindings().each() do |bind|
35
+ bind.suite=self.suite
36
+ template = parameter_template(bind.lang_name())
37
+ output(bind, template)
149
38
  end
150
- end.flatten()
151
- end
152
-
153
- def description_template
154
- %q{
155
- [<%= lang_name.upcase %>]
156
- <% parameter_range.each do |number| %>
157
- HILFEPARAM<%= number %>=<%= description(number) %>
158
- <% end %>
159
- }.gsub(/^\s*/, '')
160
- end
161
-
162
- def parameter_bindings()
163
- SetupConfiguration::Translation.languages().collect() do |lang|
164
- # constructs the output file names
165
- out= "#{SetupConfiguration::Translation.language_name(lang)}.lng"
166
- ParameterTemplateBinding.new(lang, SetupConfiguration.parameter_range(), out)
167
- end
168
- end
169
-
170
- def parameter_template(lang)
171
- template=File.join(File.dirname(__FILE__), "templates", "#{lang.to_s}.lng.erb")
172
- if File.file?(template)
173
- File.read(template)
174
- else
175
- puts "WARNING: Template file #{template} expected but not found"
176
- end
177
- end
178
-
179
- def mps_template()
180
- template=File.join(File.dirname(__FILE__), "templates", "mps3.ini.erb")
181
- if File.file?(template)
182
- File.read(template)
183
- else
184
- puts "WARNING: Template file #{template} expected but not found"
185
- end
186
- end
187
39
 
188
- def mps_binding()
189
- mps=MPSTemplateBinding.new
190
- mps.output="mps3.ini"
191
- mps
192
- end
193
-
194
-
195
- end
196
-
197
-
198
-
199
- class SetupConfiguration::SetupCodeBinding < SetupConfiguration::Generator::TemplateBinding
200
-
201
- def initialize
202
- super
203
- end
204
-
205
- def parameters
206
- #TODO use set or something similar
207
- suite.parameters.select(){|p| p.param? }
208
- end
209
-
210
- #
211
- # Offset for setup parameter numbers. This offset is added to a parameter number when evaluated in controller.
212
- #
213
- def parameter_offset
214
- 1300
215
- end
216
-
217
- def key(symbol)
218
- s=symbol.to_s
219
- delimiter='_'
220
- s.split(delimiter).collect(){|splitter| splitter.capitalize}.join(delimiter).ljust(longest_key_length)
221
- end
222
-
223
- :private
224
-
225
- def longest_key_length
226
- # find the length of the longest word
227
- unless @longest
228
- longest = parameters.inject(0) do |memo, param|
229
- memo >= param.key.to_s.length ? memo : param.key.to_s.length
230
- end
231
- @longest=longest + 5
232
- end
233
- @longest
234
- end
235
- end
236
-
237
- class SetupConfiguration::SetupCodeGenerator
238
-
239
- def generate(suite, output_path)
240
- setup_code=SetupConfiguration::SetupCodeBinding.new
241
- setup_code.output="LOGCODE#{suite.name.to_s.upcase}SETUP.EXP"
242
- setup_code.suite=suite
243
-
244
- if template then
245
- rhtml = Erubis::Eruby.new( template )
246
-
247
- File.open(File.join(output_path, setup_code.output), "w") do |f|
248
- f << rhtml.result(setup_code.get_binding)
249
- end
250
- else
251
- puts "WARNING: No template found. Generation of #{setup_code.output} aborted."
252
- end
253
-
254
-
255
- end
256
-
257
- :private
258
-
259
- def template
260
- template=File.join(File.dirname(__FILE__), "templates", "logcodesetup.exp.erb")
261
- if File.file?(template)
262
- File.read(template)
263
- else
264
- puts "WARNING: Template file #{template} expected but not found"
265
- end
266
- end
267
-
268
- end
269
-
270
-
271
- class SetupConfiguration::SuiteGenerator
272
- include SetupConfiguration::Generator
273
-
274
- attr_accessor :suite
275
- attr_accessor :do_not_run
276
-
277
- def initialize
278
- self.do_not_run = false
279
- self.suite = SetupConfiguration::Suite.instance
280
- end
281
-
282
- def self.do_not_run
283
- self.do_not_run=true
284
- end
285
-
286
- def generate
287
- return "no output" if self.do_not_run
288
-
289
- description_bindings().each() do |bind|
290
- bind.suite=self.suite
291
- rhtml = Erubis::Eruby.new(description_template)
292
-
293
- File.open(File.join(output_path, bind.output), "w") do |f|
294
- f << rhtml.result(bind.get_binding)
295
- end
296
- end
297
-
298
- # extras:
299
- # -every PARAMETER key needs a value!
300
- # -use Windows line terminators CRLF - \r\n
301
- # - do not use [] - output is an INI-file
302
- parameter_bindings().each() do |bind|
40
+ bind=mps_binding()
303
41
  bind.suite=self.suite
304
- template = parameter_template(bind.lang_name())
305
- if template then
306
- rhtml = Erubis::Eruby.new(template)
307
-
308
- File.open(File.join(output_path, bind.output), "w") do |f|
309
- f << rhtml.result(bind.get_binding)
310
- end
311
- else
312
- puts "WARNING: No template found. Generation of #{bind.output} aborted."
313
- end
314
- end
315
-
316
- bind=mps_binding()
317
- bind.suite=self.suite
318
- mps_template=mps_template()
319
- if mps_template then
320
- rhtml = Erubis::Eruby.new(mps_template)
42
+ mps_template=mps_template()
43
+ output(bind, mps_template)
321
44
 
322
- File.open(File.join(output_path, bind.output), "w") do |f|
323
- f << rhtml.result(bind.get_binding)
324
- end
325
- else
326
- puts "WARNING: No template found. Generation of #{bind.output} aborted."
45
+ SetupCodeGenerator.new.generate(self.suite, output_path)
327
46
  end
328
47
 
329
- SetupConfiguration::SetupCodeGenerator.new.generate(self.suite, output_path)
330
48
  end
331
- end
332
49
 
50
+ end
@@ -0,0 +1,28 @@
1
+ # encoding: windows-1252
2
+
3
+ module SetupConfiguration
4
+
5
+ module Generator
6
+
7
+ class TemplateBinding
8
+
9
+ attr_accessor :suite
10
+ attr_accessor :output
11
+
12
+ def categories
13
+ #TODO maybe cache these values for better performance...?
14
+ suite.categories.keys().sort()
15
+ end
16
+
17
+ # Support templating of member data.
18
+ def get_binding
19
+ binding
20
+ end
21
+
22
+ def find_param_by_number(number)
23
+ self.suite.find_param_by_number(number)
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -67,8 +67,8 @@ SYSTEM18=Please select a language.
67
67
  SYSTEM19=Ok
68
68
  SYSTEM20=Cancel
69
69
  SYSTEM21=Info
70
- SYSTEM22=Setup program V5.0.25
71
- SYSTEM23=Progdat: Apr.08.04 Inidat: Aug.20.05
70
+ SYSTEM22=Setupprogramm V6.0.01
71
+ SYSTEM23=Progdat: Apr.08.04 Inidat: Sep.07.05
72
72
  SYSTEM24=(c) Weber GmbH
73
73
  SYSTEM25=Ready
74
74
  SYSTEM26=Closed