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.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZmJkMGRmN2JlMzVhYjZlZDM1MjhjZDBhMjgxOWVkYmU5YWQzOGNkYQ==
5
+ data.tar.gz: !binary |-
6
+ MDBiYmNlNDVhZDBlOGFkOTBjOWJhYmEwMGJiYWRmMTlmMmMzMGZkYg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ Y2U1NzZhM2RiOWNiZDcyN2M4ZTUyZWQwNjFjOGEzM2ViMWFlMTE3NDc5YTQ3
10
+ Y2FmY2M4YjEwYmM0NDI5YjczZmJmNzA2YWMxZDcyNzM1MmUwOWE3ZmIwN2Yx
11
+ OWNlNDc5ZGIxNGE3NWUzOTZlZDViYzI1ZDk4NGFiOTVkODcxNDQ=
12
+ data.tar.gz: !binary |-
13
+ YmEyNThhNDAxODZjZjRhNWNhMDc5M2QxYTJhZDZmYmYzMWYxY2FmNjIzNDVk
14
+ NjNlNmNiMGQxNTI0MmJmMDU4ZDA5MjZiM2JlNTgwYWUyOWU1ODI4ODMwNjkw
15
+ ODZhODFkMDE5ZGZiNTZhOWYzMGNiZmM5OTlhODgyZWFkMjg1YTM=
data/Rakefile CHANGED
@@ -11,7 +11,7 @@ begin
11
11
  gem.homepage = "http://github.com/robi-wan/machine_setup"
12
12
  gem.authors = ["robi-wan"]
13
13
  gem.add_runtime_dependency "i18n", "~> 0.6"
14
- gem.add_runtime_dependency "inifile", "~> 1.1"
14
+ gem.add_runtime_dependency "inifile", "~> 2.0"
15
15
  gem.add_runtime_dependency "erubis", "~> 2.7"
16
16
  gem.add_development_dependency "shoulda"
17
17
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.1
1
+ 0.5.0
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  begin
4
- trace = ARGV.delete("--trace")
4
+ trace = ARGV.delete('--trace')
5
5
  param_def=ARGV[0]
6
6
 
7
- raise RuntimeError.new("Missing argument: file with parameter definition") if param_def.nil?
7
+ raise RuntimeError.new('Missing argument: file with parameter definition') if param_def.nil?
8
8
  raise RuntimeError.new("Wrong argument: file '#{param_def}' with parameter definition not found") unless File.file?(param_def)
9
9
 
10
10
  $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
@@ -17,11 +17,11 @@ begin
17
17
  suite=SetupConfiguration::Suite.instance
18
18
 
19
19
  #set output path
20
- generator = SetupConfiguration::SuiteGenerator.new()
20
+ generator = SetupConfiguration::SuiteGenerator.new
21
21
  generator.output_path=File.dirname(param_def)
22
22
 
23
23
  # load files with translations
24
- SetupConfiguration::Translation.translation_files(suite.name).each() do |t|
24
+ SetupConfiguration::Translation.translation_files(suite.name).each do |t|
25
25
  trans_file=File.join(File.dirname(param_def), t)
26
26
  if File.file?(trans_file)
27
27
  SetupConfiguration::Translation::Translator.i18n_load_path(trans_file)
@@ -30,16 +30,16 @@ begin
30
30
  end
31
31
  end
32
32
 
33
- generator.generate()
33
+ generator.generate
34
34
 
35
35
  puts("#{File.basename(__FILE__)} completed.")
36
36
  rescue Exception => ex
37
37
  $stderr.puts("#{File.basename(__FILE__)} aborted!")
38
38
  $stderr.puts(ex.message)
39
39
  if trace
40
- $stderr.puts(ex.backtrace().join("\n"))
40
+ $stderr.puts(ex.backtrace.join("\n"))
41
41
  else
42
- $stderr.puts "(See full trace by running with --trace)"
42
+ $stderr.puts '(See full trace by running with --trace)'
43
43
  end
44
44
 
45
45
  exit(1)
@@ -24,6 +24,7 @@ require File.expand_path(File.dirname(__FILE__) + '/setup_configuration/paramete
24
24
  require File.expand_path(File.dirname(__FILE__) + '/setup_configuration/mps_template_binding')
25
25
  require File.expand_path(File.dirname(__FILE__) + '/setup_configuration/setup_code_generator')
26
26
  require File.expand_path(File.dirname(__FILE__) + '/setup_configuration/setup_code_binding')
27
+ require File.expand_path(File.dirname(__FILE__) + '/setup_configuration/binary_coded_values')
27
28
  require File.expand_path(File.dirname(__FILE__) + '/setup_configuration/setup_config')
28
29
  require File.expand_path(File.dirname(__FILE__) + '/setup_configuration/suite_generator')
29
30
  require File.expand_path(File.dirname(__FILE__) + '/setup_configuration/translation')
@@ -0,0 +1,43 @@
1
+ # encoding: utf-8
2
+
3
+ module SetupConfiguration
4
+
5
+ # The <code>BinaryCodedValues</code> mixin provides common methods for transforming meaningful values
6
+ # in binary coded values - and vice versa.
7
+ # The class must provide a method <code>values</code>, which
8
+ # delivers a hash with the values and its numbers.
9
+ module BinaryCodedValues
10
+
11
+ # Gets the number (or: numerical value) of the given value.
12
+ def number(value)
13
+ if values.has_key?(value)
14
+ values[value]
15
+ else
16
+ raise ArgumentError.new("'#{value}' is not a valid option. Valid values: #{self.pretty}")
17
+ end
18
+ end
19
+
20
+ # Gets the value to the given number.
21
+ def value(number)
22
+ # 60.to_s(2).chars.to_a.reverse.each_with_index { |s,i| puts s; puts i}
23
+ result=[]
24
+ unless number.eql?(0) then
25
+ number.to_s(2).chars.to_a.reverse.each_with_index do |value, index|
26
+ if value.eql?('1')
27
+ # invert hash with values to get meaningful value (key) for given binary coded value
28
+ r = values.invert[2**index]
29
+ result << r if r
30
+ end
31
+ end
32
+ end
33
+ result
34
+ end
35
+
36
+ def pretty
37
+ s = ''
38
+ PP.pp(values.keys, s)
39
+ s
40
+ end
41
+ end
42
+
43
+ end
@@ -11,7 +11,7 @@ module SetupConfiguration
11
11
  end
12
12
 
13
13
  def self.default_encoding
14
- "windows-1252"
14
+ 'windows-1252'
15
15
  end
16
16
 
17
17
  def self.encoding
@@ -1,7 +1,7 @@
1
1
  module SetupConfiguration
2
2
 
3
3
  module Generator
4
- @output_path=""
4
+ @output_path=''
5
5
 
6
6
  def output_path
7
7
  @output_path
@@ -15,7 +15,7 @@ module SetupConfiguration
15
15
  if template
16
16
  rhtml = Erubis::Eruby.new(template)
17
17
 
18
- File.open(File.join(output_path, bind.output), "w") do |f|
18
+ File.open(File.join(output_path, bind.output), 'w') do |f|
19
19
  f << rhtml.result(bind.get_binding)
20
20
  end
21
21
  else
@@ -29,7 +29,7 @@ module SetupConfiguration
29
29
  # [:en, "english", (0..199), "english1.lng"],
30
30
  # [:en, "english", (200..599), "english2.lng"],
31
31
  # [:en, "english", (600..1299), "english3.lng"],
32
- def description_bindings()
32
+ def description_bindings
33
33
  Translation.languages().collect() do |lang|
34
34
  SetupConfiguration.description_ranges().collect() do |range|
35
35
  # constructs the output file names
@@ -48,7 +48,7 @@ module SetupConfiguration
48
48
  }.gsub(/^\s*/, '')
49
49
  end
50
50
 
51
- def parameter_bindings()
51
+ def parameter_bindings
52
52
  Translation.languages().collect() do |lang|
53
53
  # constructs the output file names
54
54
  out= "#{Translation.language_name(lang)}.lng"
@@ -60,18 +60,18 @@ module SetupConfiguration
60
60
  find_template("#{lang.to_s}.lng.erb")
61
61
  end
62
62
 
63
- def mps_template()
64
- find_template("mps3.ini.erb")
63
+ def mps_template
64
+ find_template('mps3.ini.erb')
65
65
  end
66
66
 
67
- def mps_binding()
67
+ def mps_binding
68
68
  MPSTemplateBinding.new do |mps|
69
- mps.output="mps3.ini"
69
+ mps.output='mps3.ini'
70
70
  end
71
71
  end
72
72
 
73
73
  def find_template(name)
74
- template=File.join(File.dirname(__FILE__), "templates", name)
74
+ template=File.join(File.dirname(__FILE__), 'templates', name)
75
75
  if File.file?(template)
76
76
  File.read(template)
77
77
  else
@@ -5,8 +5,6 @@ module SetupConfiguration
5
5
 
6
6
  class Importer
7
7
 
8
- INI_LINE_SPLIT_PATTERN=','
9
-
10
8
  attr_reader :categories
11
9
 
12
10
  def initialize(folder, name, abbreviation)
@@ -30,27 +28,42 @@ module SetupConfiguration
30
28
  def output_language(output_path, lang)
31
29
  context = LanguageContext.new(@name, lang, self)
32
30
 
33
- template=File.join(File.dirname(__FILE__), "templates", "setup.param.language.yml.erb")
31
+ template=File.join(File.dirname(__FILE__), 'templates', 'setup.param.language.yml.erb')
34
32
  input = File.read(template)
35
33
  eruby = Erubis::Eruby.new(input)
36
34
 
37
- File.open(File.join(output_path, context.output ), "w") do |f|
35
+ File.open(File.join(output_path, context.output ), 'w') do |f|
38
36
  f << eruby.evaluate(context)
39
37
  end
40
38
 
41
39
  end
42
40
 
43
41
  def output_param(output_path)
44
- template=File.join(File.dirname(__FILE__), "templates", "setup.param.erb")
42
+ template=File.join(File.dirname(__FILE__), 'templates', 'setup.param.erb')
45
43
  input = File.read(template)
46
44
  eruby = Erubis::Eruby.new(input)
47
45
 
48
- File.open(File.join(output_path, "#@name.#{Translation::FILE_EXTENSION}" ), "w") do |f|
46
+ File.open(File.join(output_path, "#{@name}.#{Translation::FILE_EXTENSION}" ), 'w') do |f|
49
47
  f << eruby.result(binding())
50
48
  end
51
49
 
52
50
  end
53
51
 
52
+
53
+ def render_options(binary)
54
+ options = SetupConfiguration::SoftwareOptions.new.compute_options(binary)
55
+ render_symbols(options)
56
+ end
57
+
58
+ def render_roles(binary)
59
+ roles = SetupConfiguration::Roles.new.compute_roles(binary)
60
+ render_symbols(roles)
61
+ end
62
+
63
+ def render_symbols(symbols)
64
+ symbols.collect(){|s| ":#{s}"}.join(', ')
65
+ end
66
+
54
67
  def compute_machine_types(binary)
55
68
  # 60.to_s(2).chars.to_a.reverse.each_with_index { |s,i| puts s; puts i}
56
69
  result=[]
@@ -58,19 +71,19 @@ module SetupConfiguration
58
71
  result << machine_type_by_number(binary).name
59
72
  else
60
73
  Fixnum.induced_from(binary).to_s(2).chars.to_a.reverse.each_with_index do |value, index|
61
- if value.eql?("1")
74
+ if value.eql?('1')
62
75
  result << machine_type_by_number(index+1).name
63
76
  end
64
77
  end
65
78
  end
66
- result.join(" + ")
79
+ result.join(' + ')
67
80
  end
68
81
 
69
82
  def machine_type_by_number(number)
70
- @settings.machine_types.select() {|mt| mt.sequence_number.eql?(number)}.first
83
+ @settings.machine_types.detect() {|mt| mt.sequence_number.eql?(number)}
71
84
  end
72
85
 
73
- def init_settings()
86
+ def init_settings
74
87
  @settings.min(Range.new(sv('BEGIN_MIN'), sv('END_MIN')))
75
88
  @settings.max(Range.new(sv('BEGIN_MAX'), sv('END_MAX')))
76
89
  @settings.balance_min(Range.new(sv('BEGIN_WAAG_MIN'), sv('END_WAAG_MIN')))
@@ -115,39 +128,9 @@ module SetupConfiguration
115
128
 
116
129
 
117
130
  #todo preserve original parameter order
118
- def init_params()
119
- params = @mps3['PARAMANZEIGE']
120
- params.each do |key, value|
121
- cat_regexp = /TAB((\d\d?)([abc]))/
122
- if key =~ cat_regexp then
123
- unless value.empty?
124
- cat_level=key.scan(cat_regexp).flatten[0]
125
- cat_number=key.scan(cat_regexp).flatten[1].to_i
126
-
127
- deps = param_dependencies(params, "#{cat_level}")
128
- types = machine_types(params, "#{cat_level}")
129
-
130
- cat = category_by_number(cat_number)
131
- value.split(INI_LINE_SPLIT_PATTERN).each_with_index do |param_number, index|
132
-
133
- #check for multiple defined parameters (in different categories)
134
- #warn and skip
135
- if param_by_number(param_number)
136
- $stderr.puts("WARNING: parameter '#{ param_key(param_number)}' with number '#{param_number}' multiple defined. Duplicate found in category '#{category_name(cat_number)}'.")
137
- parameter = ParameterReference.new( param_key(param_number) )
138
- cat.parameter << parameter
139
- else
140
- parameter = Parameter.new(param_number)
141
- parameter.depends_on(deps[index])
142
- parameter.for_machine_type(types[index].to_i)
143
- parameter.key = param_key(param_number)
144
- cat.parameter << parameter
145
- end
146
- end
147
-
148
- end
149
- end
150
- end
131
+ def init_params
132
+ extractor = ParameterExtractor.new(@mps3['PARAMANZEIGE'], self)
133
+ extractor.extract()
151
134
 
152
135
  # replace parameter numbers with parameter keys
153
136
  parameters.each() do |param|
@@ -157,7 +140,7 @@ module SetupConfiguration
157
140
  end
158
141
  end
159
142
 
160
- #get categorie names
143
+ #get category names
161
144
  self.categories.each do |cat|
162
145
  cat.name = category_name(cat.number)
163
146
  end
@@ -218,14 +201,14 @@ module SetupConfiguration
218
201
  file_number= index + 1 if range.include?(param_number.to_i)
219
202
  end
220
203
 
221
- filename = lang.downcase << file_number.to_s << ".lng"
204
+ filename = lang.downcase << file_number.to_s << '.lng'
222
205
  key_ini= @ini_files[filename]
223
206
  desc=key_ini[lang.upcase]["HILFEPARAM#{param_number}"]
224
207
  escape_param_description(desc)
225
208
  end
226
209
 
227
210
  def escape_param_description(description)
228
- description unless description.eql?("not used")
211
+ description unless description.eql?('not used')
229
212
  end
230
213
 
231
214
  def parameters
@@ -233,11 +216,11 @@ module SetupConfiguration
233
216
  end
234
217
 
235
218
  def param_by_number(number)
236
- self.parameters().select(){|p| p.number.eql?(number)}.first
219
+ self.parameters().detect(){|p| p.number.eql?(number)}
237
220
  end
238
221
 
239
222
  def category_by_number(number)
240
- cat = self.categories.select(){|c| c.number.eql?(number)}.first
223
+ cat = self.categories.detect(){|c| c.number.eql?(number)}
241
224
  unless cat
242
225
  cat = Category.new
243
226
  cat.number = number
@@ -246,15 +229,7 @@ module SetupConfiguration
246
229
  cat
247
230
  end
248
231
 
249
- # key = 2CF#{level}
250
- def param_dependencies(params, level)
251
- params["2CF#{level}"].split(INI_LINE_SPLIT_PATTERN)
252
- end
253
-
254
- # key = 1CF#{level}
255
- def machine_types(params, level)
256
- params["1CF#{level}"].split(INI_LINE_SPLIT_PATTERN)
257
- end
232
+
258
233
 
259
234
  end
260
235
 
@@ -2,5 +2,6 @@
2
2
  require 'inifile'
3
3
 
4
4
  require File.expand_path(File.dirname(__FILE__) + '/parameter')
5
+ require File.expand_path(File.dirname(__FILE__) + '/parameter_extractor')
5
6
  require File.expand_path(File.dirname(__FILE__) + '/language_context')
6
7
  require File.expand_path(File.dirname(__FILE__) + '/importer')
@@ -3,12 +3,9 @@ module SetupConfiguration
3
3
  module Legacy
4
4
 
5
5
  class Parameter < SetupConfiguration::Parameter
6
- def initialize(number)
7
- @number=number
8
- end
9
6
 
10
7
  def extended?
11
- dep? || type?
8
+ dep? || type? || roles? || options?
12
9
  end
13
10
 
14
11
  def dep?
@@ -19,6 +16,22 @@ module SetupConfiguration
19
16
  @machine_type != 0
20
17
  end
21
18
 
19
+ def roles?
20
+ @roles != 0
21
+ end
22
+
23
+ def roles=(r)
24
+ @roles = r
25
+ end
26
+
27
+ def options?
28
+ @options != 0
29
+ end
30
+
31
+ def options=(o)
32
+ @options = o
33
+ end
34
+
22
35
  def param?
23
36
  true
24
37
  end
@@ -0,0 +1,83 @@
1
+ # encoding: utf-8
2
+ module SetupConfiguration
3
+
4
+ module Legacy
5
+
6
+ class ParameterExtractor
7
+
8
+ INI_LINE_SPLIT_PATTERN=','
9
+
10
+ def initialize(p, importer=nil)
11
+ @params = p
12
+ @importer = importer
13
+ end
14
+
15
+ def extract
16
+ @params.each do |key, value|
17
+ cat_regexp = /TAB((\d\d?)([abc]))/
18
+ if key =~ cat_regexp then
19
+ unless value.empty?
20
+ cat_level=key.scan(cat_regexp).flatten[0]
21
+ cat_number=key.scan(cat_regexp).flatten[1].to_i
22
+
23
+ deps = param_dependencies("#{cat_level}")
24
+ types = machine_types("#{cat_level}")
25
+ options = param_options("#{cat_level}") # may be nil
26
+ roles = roles("#{cat_level}") # may be nil
27
+
28
+ cat = @importer.category_by_number(cat_number)
29
+ value.split(INI_LINE_SPLIT_PATTERN).each_with_index do |param_number, index|
30
+
31
+ #check for multiple defined parameters (in different categories)
32
+ #warn and skip
33
+ if @importer.param_by_number(param_number)
34
+ $stderr.puts("WARNING: parameter '#{ @importer.param_key(param_number)}' with number '#{param_number}' multiple defined. Duplicate found in category '#{@importer.category_name(cat_number)}'.")
35
+ parameter = ParameterReference.new(@importer.param_key(param_number))
36
+ cat.parameter << parameter
37
+ else
38
+ key = @importer.param_key(param_number)
39
+ parameter = Parameter.new(key, param_number)
40
+ parameter.depends_on(deps[index])
41
+ parameter.for_machine_type(types[index].to_i)
42
+ parameter.options = options[index].to_i if options
43
+ parameter.roles = roles[index].to_i if roles
44
+ cat.parameter << parameter
45
+ end
46
+ end
47
+
48
+ end
49
+ end
50
+ end
51
+
52
+ end
53
+
54
+ # key = 2CF#{level}
55
+ def param_dependencies(level)
56
+ split(@params["2CF#{level}"])
57
+ end
58
+
59
+ # key = 1CF#{level}
60
+ def machine_types(level)
61
+ split(@params["1CF#{level}"])
62
+ end
63
+
64
+ # key = 3CF#{level}
65
+ # may return nil
66
+ def param_options(level)
67
+ split(@params["3CF#{level}"])
68
+ end
69
+
70
+ # key = 4CF#{level}
71
+ # may return nil
72
+ def roles(level)
73
+ split(@params["4CF#{level}"])
74
+ end
75
+
76
+ def split(pars)
77
+ pars.split(INI_LINE_SPLIT_PATTERN) if pars
78
+ end
79
+
80
+ end
81
+
82
+ end
83
+ end