origen 0.36.0 → 0.36.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cf61c021058415fdb5fe0aa76a1e66ed3c142803e1ebf29b4f3905ce4bbb1384
4
- data.tar.gz: dcc822d38c0fcdeea4686729c285d50f1d4a6ed9d5a9e2065f2ac5423a66bf88
3
+ metadata.gz: 2b7cd6e1fd31d6cf1cdcc85ced3c00da93d86b47b0bcdff4b882a88bac79ac45
4
+ data.tar.gz: d395df3f3faba1ed8c4a5d7d4e34e7193de1a75a62a116fcea80047727a1f99c
5
5
  SHA512:
6
- metadata.gz: 5b68ce80e155cec23d5b6639f3037126eebf7da4bb9d19b4ce80616a48884f6f2fe7ada074c2e9080d21341e95b801f2b439886d00cf69afd6a58e3ffbb9345d
7
- data.tar.gz: d6544cd0270caa0e71161a1a12e0231409fc60a7395387dac05811c1ca602b686ceb688d40d4b43cab00c990a70f6c7bdf71cf756c802aed2d27b54c21492c9d
6
+ metadata.gz: 928fa5eea49de2b7f75d1f023c2808f7bb9af6c4a7fd1d79c82cd0cfb83ecb2fdb93405fdd5e55fc959fffd4671e2383be47d1fa89b7c297107e98172972be1c
7
+ data.tar.gz: 12dc00e6e0557da57afb690ae34cada31ae633688c071ec26b91cef7e261ad234623635077a20b38add1058507b921763d7cc8f969ee83c0d9643e12a9d20281
data/bin/origen CHANGED
@@ -170,7 +170,8 @@ if origen_root && File.exist?(ENV['BUNDLE_GEMFILE']) && Origen.site_config.gem_m
170
170
  end
171
171
  end
172
172
  require 'bundler/setup'
173
- if Origen.site_config.use_bootsnap && !Origen.os.windows?
173
+ _exec_remote = ARGV.include?('--exec_remote') ? true : false
174
+ if Origen.site_config.use_bootsnap && !Origen.os.windows? && !_exec_remote
174
175
  ENV["BOOTSNAP_CACHE_DIR"] ||= "#{origen_root}/tmp/cache"
175
176
  require 'bootsnap/setup'
176
177
  end
@@ -1,7 +1,7 @@
1
1
  module Origen
2
2
  MAJOR = 0
3
3
  MINOR = 36
4
- BUGFIX = 0
4
+ BUGFIX = 1
5
5
  DEV = nil
6
6
 
7
7
  VERSION = [MAJOR, MINOR, BUGFIX].join(".") + (DEV ? ".pre#{DEV}" : '')
@@ -28,6 +28,7 @@ unless defined? RGen::ORIGENTRANSITION
28
28
  require 'bundler'
29
29
  require 'origen/undefined'
30
30
  require 'origen/componentable'
31
+ require 'socket'
31
32
 
32
33
  module Origen
33
34
  autoload :Features, 'origen/features'
@@ -670,6 +671,11 @@ unless defined? RGen::ORIGENTRANSITION
670
671
  end
671
672
  alias_method :interactive?, :running_interactively?
672
673
 
674
+ # Platform independent way of retrieving the hostname
675
+ def hostname
676
+ Socket.gethostbyname(Socket.gethostname).first.downcase
677
+ end
678
+
673
679
  # Returns true if Origen is running with the -d or --debug switches enabled
674
680
  def debug?
675
681
  @debug || false
@@ -244,6 +244,10 @@ when 'version'
244
244
  require 'origen/commands/version'
245
245
  exit 0
246
246
 
247
+ when 'site'
248
+ require 'origen/commands/site'
249
+ exit 0
250
+
247
251
  else
248
252
  if ['-h', '--help'].include?(@command)
249
253
  status = 0
@@ -273,6 +277,7 @@ The core origen commands are:
273
277
  web Web page tools, see -h for details
274
278
  time Tools for test time analysis and forecasting
275
279
  lint Lint and style check (and correct) your application code
280
+ site Monitor and manage the Origen site configuration
276
281
  EOT
277
282
  cmds.split(/\n/).each do |line|
278
283
  puts Origen.clean_help_line(line)
@@ -0,0 +1,52 @@
1
+ require 'optparse'
2
+ require 'pathname'
3
+ require 'origen/commands/helpers'
4
+
5
+ module Origen
6
+ options = {}
7
+
8
+ # App options are options that the application can supply to extend this command
9
+ app_options = @application_options || []
10
+ opt_parser = OptionParser.new do |opts|
11
+ opts.banner = <<-END
12
+ env [filters...] Shows the current site environment configuration. Analogous to 'env' for shell environment.
13
+ In other words, lists all the site config variables and their values.
14
+ Aliased to 'environment'.
15
+
16
+ configs Shows the current config files used and their indexes.
17
+
18
+ inspect_config [config_indexes...] Inspects the configuration(s) at each index given.
19
+ Indexes can be found from 'origen site configs'
20
+ If no indexes are given, all configs are printed.
21
+
22
+ inspect_variable [variable_names...] Inspects and traces the variable(s) through the various sites configs.
23
+
24
+ refresh Forces a refresh of the centralized site config. This will reset the timer for the next automatc refresh.
25
+ END
26
+
27
+ # Apply any application option extensions to the OptionParser
28
+ Origen::CommandHelpers.extend_options(opts, app_options, options)
29
+ opts.separator ''
30
+ opts.on('-h', '--help', 'Show this message') { puts opts; exit }
31
+ end
32
+ opt_parser.parse! ARGV
33
+
34
+ if ARGV[0]
35
+ case ARGV.shift
36
+ when 'env', 'environment'
37
+ Origen.site_config.pretty_print_env(*ARGV)
38
+ when 'configs'
39
+ Origen.site_config.pretty_print_configs
40
+ when 'inspect_config', 'inspect_configs'
41
+ Origen.site_config.inspect_config(*ARGV)
42
+ when 'inspect_variable', 'inspect_variables'
43
+ Origen.site_config.inspect_variable(*ARGV)
44
+ when 'refresh'
45
+ Origen.site_config.refresh
46
+ else
47
+ puts "Unknown command, see 'origen site -h' for a list of commands"
48
+ end
49
+ else
50
+ puts "You must supply a command, see 'origen site -h' for a list of commands"
51
+ end
52
+ end
@@ -96,6 +96,10 @@ when '--version', '-v'
96
96
  require 'origen/commands/version'
97
97
  exit 0
98
98
 
99
+ when 'site'
100
+ require 'origen/commands/site'
101
+ exit 0
102
+
99
103
  # when 'fetch', 'f'
100
104
  # require 'origen/commands/fetch'
101
105
  # exit 0
@@ -115,6 +119,7 @@ The following commands are available:
115
119
  new origen application workspace in "./my_app"
116
120
  interactive Start an interactive Origen console (short-cut alias: "i"), this is just
117
121
  IRB with the 'origen' lib loaded automatically
122
+ site Monitor and manage the Origen site configuration
118
123
  EOT
119
124
  cmds.split(/\n/).each do |line|
120
125
  puts Origen.clean_help_line(line)
@@ -3,15 +3,20 @@ module Origen
3
3
  require 'pathname'
4
4
  require 'yaml'
5
5
  require 'etc'
6
+ require 'erb'
7
+ require 'colored'
8
+ require 'httparty'
9
+ require_relative 'site_config/config'
10
+
11
+ # require this version of Origen
12
+ require_relative '../origen'
6
13
 
7
14
  TRUE_VALUES = ['true', 'TRUE', '1', 1]
8
15
  FALSE_VALUES = ['false', 'FALSE', '0', 0]
9
16
 
10
17
  # Adding parameters to this array will prevent them from being converted to booleans if
11
18
  # they are assigned one of the values in the TRUE_VALUES/FALSE_VALUES arrays
12
- NON_BOOLEAN_PARAMETERS = [:lsf_cores]
13
-
14
- # Define a couple of site configs variables that need a bit of processing
19
+ NON_BOOLEAN_PARAMETERS = [:lsf_cores, :centralized_site_config_refresh]
15
20
 
16
21
  # Gets the gem_intall_dir. This is either site_config.home_dir/gems or the site configs gem_install_dir
17
22
  def gem_install_dir
@@ -76,11 +81,15 @@ module Origen
76
81
  path
77
82
  end
78
83
 
84
+ def centralized_site_config_cache_dir
85
+ File.expand_path(find_val('centralized_site_config_cache_dir'))
86
+ end
87
+
79
88
  # Dynamically remove the highest instance of :var
80
89
  def remove_highest(var)
81
90
  @configs.each do |c|
82
- if c.key?(var)
83
- return c.delete(var)
91
+ if c.has_var?(var)
92
+ return c.remove_var(var)
84
93
  end
85
94
  end
86
95
 
@@ -96,8 +105,8 @@ module Origen
96
105
  # If [] is returned, it implies that there was no instancs of :var to be removed.
97
106
  ret = []
98
107
  @configs.each do |c|
99
- if c.key?(var)
100
- ret << c.delete(var)
108
+ if c.has_var?(var)
109
+ ret << c.remove_var(var)
101
110
  end
102
111
  end
103
112
  ret
@@ -108,7 +117,8 @@ module Origen
108
117
  def add_as_highest(var, value)
109
118
  # Don't want to override anything, so just shift in a dummy site config instance at the highest level and
110
119
  # set the value there.
111
- configs.prepend(var.to_s => value)
120
+ c = Config.new(path: :runtime, parent: self, values: { var.to_s => value })
121
+ configs.prepend(Config.new(path: :runtime, parent: self, values: { var.to_s => value }))
112
122
  end
113
123
  alias_method :[]=, :add_as_highest
114
124
 
@@ -117,17 +127,19 @@ module Origen
117
127
  def add_as_lowest(var, value)
118
128
  # Don't want to override anything, so just shift in a dummy site config at the lowest level and
119
129
  # set the value there.
120
- configs.append(var.to_s => value)
130
+ configs.append(Config.new(path: :runtime, parent: self, values: { var.to_s => value }))
121
131
  end
122
132
 
123
133
  # Adds a new site config file as the highest priority
124
134
  def add_site_config_as_highest(site_config_file)
125
- configs.prepend YAML.load_file(File.expand_path('../../../origen_site_config.yml', __FILE__))
135
+ # configs.prepend YAML.load_file(File.expand_path('../../../origen_site_config.yml', __FILE__))
136
+ configs.prepend(Config.new(path: site_config_file, parent: self))
126
137
  end
127
138
 
128
139
  # Adds a new site config file as the highest priority
129
140
  def add_site_config_as_lowest(site_config_file)
130
- configs.append YAML.load_file(File.expand_path('../../../origen_site_config.yml', __FILE__))
141
+ # configs.append YAML.load_file(File.expand_path('../../../origen_site_config.yml', __FILE__))
142
+ configs.append(Config.new(path: site_config_file, parent: self))
131
143
  end
132
144
 
133
145
  def method_missing(method, *args, &block)
@@ -148,15 +160,10 @@ module Origen
148
160
  val
149
161
  end
150
162
 
151
- def get(val)
152
- find_val(val)
153
- end
154
- alias_method :[], :get
155
-
156
163
  def get_all(val)
157
164
  ret = []
158
165
  @configs.each do |c|
159
- if c.key?(val)
166
+ if c.has_var?(val)
160
167
  ret << c[val]
161
168
  end
162
169
  end
@@ -171,16 +178,162 @@ module Origen
171
178
  configs!
172
179
  end
173
180
 
174
- private
181
+ def refresh
182
+ @configs.each(&:refresh)
183
+ end
184
+
185
+ def pretty_print_configs
186
+ puts 'The following config files are ordered from last-encountered (highest priority) first-encountered (lowest priority)'
187
+ puts
188
+ configs.each_with_index do |config, i|
189
+ puts "#{i}: #{config.path} (#{config.type})"
190
+ end
191
+ end
192
+ alias_method :pp_configs, :pretty_print_configs
193
+
194
+ def all_vars
195
+ vars = {}
196
+ configs.each do |c|
197
+ vars = c.values.merge(vars)
198
+ end
199
+ vars
200
+ end
201
+ alias_method :env, :all_vars
202
+
203
+ # Gets all config variables as a hash, but the hash's values are the Config instances which defines the highest
204
+ # priority of each var, instead of the var's value itself.
205
+ def vars_by_configs
206
+ vars = {}
207
+ configs.each do |c|
208
+ vars = c.values.map { |k, v| [k, c] }.to_h.merge(vars)
209
+ end
210
+ vars
211
+ end
212
+ alias_method :vars_by_config, :vars_by_configs
213
+
214
+ def pretty_print_env(*vars)
215
+ puts
216
+ spacing = ' ' * 2
217
+ r = vars.empty? ? nil : Regexp.union(vars.map { |v| Regexp.new(v) })
218
+ all_vars.each do |var, val|
219
+ if !r.nil? && !(var.match r)
220
+ next
221
+ end
222
+
223
+ if val.is_a?(Array)
224
+ puts "#{var}: ["
225
+ val.each { |v| puts "#{spacing} #{v}" }
226
+ puts ']'
227
+ elsif val.is_a?(Hash)
228
+ puts "#{var}: {"
229
+ val.each { |v| puts "#{spacing} #{v}" }
230
+ puts '}'
231
+ else
232
+ puts "#{var}: #{val}"
233
+ end
234
+ end
235
+ puts
236
+ end
237
+ alias_method :pp_env, :pretty_print_env
238
+
239
+ def to_env(val)
240
+ "ORIGEN_#{val.upcase}"
241
+ end
242
+
243
+ def env_contains?(val)
244
+ ENV.key?(val)
245
+ end
246
+
247
+ def env(val)
248
+ if env_contains?(val)
249
+ ENV[val]
250
+ end
251
+ end
252
+
253
+ def inspect_variable(*vars)
254
+ vars.each do |var|
255
+ puts "Inspecting Variable: #{var}"
256
+ if env_contains?(to_env(var))
257
+ puts "Environment Variable (#{to_env(var)}): #{env(to_env(var))}"
258
+ else
259
+ puts "(No enviornment variable #{to_env(var)} defined)"
260
+ end
261
+ @configs.each do |c|
262
+ if c.has_var?(var)
263
+ puts "#{c.path} (#{c.type}): #{c[var]}"
264
+ end
265
+ end
266
+ puts
267
+ end
268
+ end
269
+ alias_method :inspect_var, :inspect_variable
270
+ alias_method :inspect_variables, :inspect_variable
271
+ alias_method :inspect_vars, :inspect_variable
272
+
273
+ # Inspects the config(s) at the incex given.
274
+ def inspect_configs(*config_indexes)
275
+ config_indexes.each do |i|
276
+ if i.to_i > @configs.size
277
+ puts "Origen::SiteConfig: index #{i} is out of range of the available configs! Total configs: #{@configs.size}.".red
278
+ elsif i.to_i < 0
279
+ puts "Origen::SiteConfig: index #{i} is less than 0. This index is ignored.".red
280
+ else
281
+ c = @configs[i.to_i]
282
+ puts "Inspecting config \##{i}"
283
+ puts "Type: #{c.type}"
284
+ puts "Path: #{c.path}"
285
+ if c.centralized?
286
+ # Add a safeguard in case something happened being bootup and now and the cache is no longer present
287
+ puts "Cached At: #{c.cache_file}" if c.cache_file
288
+ puts "Cached On: #{c.cache_file.ctime}" if c.cache_file
289
+ end
290
+
291
+ puts
292
+ puts 'Values from this config:'
293
+ spacing = ' ' * 2
294
+ c.values.each do |var, val|
295
+ if val.is_a?(Array)
296
+ puts "#{var}: ["
297
+ val.each { |v| puts "#{spacing} #{v}" }
298
+ puts ']'
299
+ elsif val.is_a?(Hash)
300
+ puts "#{var}: {"
301
+ val.each { |v| puts "#{spacing} #{v}" }
302
+ puts '}'
303
+ else
304
+ puts "#{var}: #{val}"
305
+ end
306
+ end
307
+
308
+ puts
309
+ puts 'Active (highest-level) values from this config:'
310
+ spacing = ' ' * 2
311
+ vars_by_config.select { |k, v| v == c }.map { |k, v| [k, v[k]] }.to_h.each do |var, val|
312
+ if val.is_a?(Array)
313
+ puts "#{var}: ["
314
+ val.each { |v| puts "#{spacing} #{v}" }
315
+ puts ']'
316
+ elsif val.is_a?(Hash)
317
+ puts "#{var}: {"
318
+ val.each { |v| puts "#{spacing} #{v}" }
319
+ puts '}'
320
+ else
321
+ puts "#{var}: #{val}"
322
+ end
323
+ end
324
+ puts
325
+ end
326
+ end
327
+ end
328
+ alias_method :inspect_config, :inspect_configs
175
329
 
176
330
  def find_val(val, options = {})
177
331
  env = "ORIGEN_#{val.upcase}"
178
332
  if ENV.key?(env)
179
333
  value = ENV[env]
180
- value
181
334
  else
182
- config = configs.find { |c| c.key?(val) }
183
- value = config ? config[val] : nil
335
+ config = configs.find { |c| c.has_var?(val) }
336
+ value = config ? config.find_val(val) : nil
184
337
  end
185
338
 
186
339
  unless NON_BOOLEAN_PARAMETERS.include?(val.to_s.downcase.to_sym)
@@ -192,56 +345,82 @@ module Origen
192
345
  end
193
346
  value
194
347
  end
348
+ alias_method :get, :find_val
349
+ alias_method :[], :find_val
350
+
351
+ private
195
352
 
196
353
  def configs
197
354
  @configs ||= configs!
198
355
  end
199
356
 
357
+ # Searches a directory and returns an array of config objects (from lowest to highest priority) that were found
358
+ # @note This includes searching for <code>./config/</code> in <code>dir</code>. In other words, this searches both
359
+ # <code>dir</code> and <code>dir/config</code>.
360
+ def load_directory(dir, prepend: false)
361
+ [
362
+ File.join(dir, 'config', 'origen_site_config.yml'),
363
+ File.join(dir, 'config', 'origen_site_config.yml.erb'),
364
+ File.join(dir, 'origen_site_config.yml'),
365
+ File.join(dir, 'origen_site_config.yml.erb')
366
+ ].each do |f|
367
+ if File.exist?(f)
368
+ if prepend
369
+ configs.unshift(Config.new(path: f, parent: self))
370
+ else
371
+ configs << Config.new(path: f, parent: self)
372
+ end
373
+ end
374
+ end
375
+ end
376
+
200
377
  # Forces a reparse of the site configs.
201
378
  # This will set the @configs along the current path first,
202
379
  # then, using those values, will add a site config at the home directory.
203
380
  def configs!
204
- @configs = begin
205
- # This global is set when Origen is first required, it generally means that what is considered
206
- # to be the pwd for the purposes of looking for a site_config file is the place from where the
207
- # user invoked Origen. Otherwise if the running app switches the PWD it can lead to confusing
208
- # behavior - this was a particular problem when testing the new app generator which switches the
209
- # pwd to /tmp to build the new app
210
- path = $_origen_invocation_pwd
211
- configs = []
212
- # Add any site_configs from where we are currently running from, i.e. the application
213
- # directory area
214
- until path.root?
215
- file = File.join(path, 'config', 'origen_site_config.yml')
216
- configs << YAML.load_file(file) if File.exist?(file) && YAML.load_file(file)
217
- file = File.join(path, 'origen_site_config.yml')
218
- configs << YAML.load_file(file) if File.exist?(file) && YAML.load_file(file)
219
- path = path.parent
220
- end
221
-
222
- # Add and any site_configs from the directory hierarchy where Ruby is installed
223
- path = Pathname.new($LOAD_PATH.last)
224
- until path.root?
225
- file = File.join(path, 'origen_site_config.yml')
226
- configs << YAML.load_file(file) if File.exist?(file) && YAML.load_file(file)
227
- path = path.parent
228
- end
381
+ # This global is set when Origen is first required, it generally means that what is considered
382
+ # to be the pwd for the purposes of looking for a site_config file is the place from where the
383
+ # user invoked Origen. Otherwise if the running app switches the PWD it can lead to confusing
384
+ # behavior - this was a particular problem when testing the new app generator which switches the
385
+ # pwd to /tmp to build the new app
386
+ path = $_origen_invocation_pwd
387
+ @configs = []
388
+
389
+ # Add any site_configs from where we are currently running from, i.e. the application
390
+ # directory area
391
+ until path.root?
392
+ load_directory(path)
393
+ path = path.parent
394
+ end
229
395
 
230
- # Add the one from the Origen core as the lowest priority, this one defines
231
- # the default values
232
- configs << YAML.load_file(File.expand_path('../../../origen_site_config.yml', __FILE__))
233
- configs
396
+ # Add and any site_configs from the directory hierarchy where Ruby is installed
397
+ path = Pathname.new($LOAD_PATH.last)
398
+ until path.root?
399
+ load_directory(path)
400
+ path = path.parent
234
401
  end
235
402
 
403
+ # Add the one from the Origen core as the lowest priority, this one defines
404
+ # the default values
405
+ load_directory(File.expand_path('../../../', __FILE__))
406
+
236
407
  # Add the site_config from the user's home directory as highest priority, if it exists
237
408
  # But, make sure we take the site installation's setup into account.
238
409
  # That is, if user's home directories are somewhere else, make sure we use that directory to the find
239
410
  # the user's overwrite file. The user can then override that if they want."
240
- user_config = File.join(File.expand_path(user_install_dir), 'origen_site_config.yml')
241
- if File.exist?(user_config)
242
- @configs.unshift(YAML.load_file(user_config)) if YAML.load_file(user_config)
411
+ load_directory(File.expand_path(user_install_dir), prepend: true)
412
+
413
+ # Load any centralized site configs now.
414
+ centralized_site_config = find_val('centralized_site_config')
415
+ if centralized_site_config
416
+ # We know the last two site configs will exists (they are in Origen core) and that they contain the default
417
+ # values. We want the centralized config to load right after those.
418
+ @configs.insert(-3, Config.new(path: centralized_site_config, parent: self))
243
419
  end
244
420
 
421
+ # After all configs have been populated, see if the centralized needs refreshing
422
+ @configs.each { |c| c.refresh if c.needs_refresh? }
423
+
245
424
  @configs
246
425
  end
247
426
  end
@@ -0,0 +1,205 @@
1
+ module Origen
2
+ class SiteConfig
3
+ class Config
4
+ attr_reader :path
5
+ attr_reader :parent
6
+ attr_reader :type
7
+ attr_reader :values
8
+
9
+ RESTRICTED_FROM_CENTRALIZED_VARIABLES = %w(centralized_site_config centralized_site_config_cache_dir centralized_site_config_verify_ssl)
10
+
11
+ def initialize(path:, parent:, values: nil)
12
+ @parent = parent
13
+ if path == :runtime
14
+ path = "runtime_#{object_id}"
15
+ @type = :runtime
16
+ elsif path.start_with?('http')
17
+ @path = path
18
+ @type = :centralized
19
+ else
20
+ @path = path
21
+ @type = :local
22
+ end
23
+ @contains_centralized = false
24
+ @loaded = false
25
+
26
+ if values
27
+ @values = values
28
+ @loaded = true
29
+ else
30
+ @values = nil
31
+ load
32
+ end
33
+ end
34
+
35
+ def needs_refresh?
36
+ if centralized?
37
+ if refresh_time < 0
38
+ false
39
+ elsif cached?
40
+ # If the refresh time is 0, this will always be true
41
+ # Note the difference of time objects below will give the difference in seconds.
42
+ (Time.now - cached_file.ctime) / 3600.0 > refresh_time
43
+ else
44
+ # If the cached file cannot be found, force a new fetch
45
+ true
46
+ end
47
+ else
48
+ false
49
+ end
50
+ end
51
+
52
+ def refresh_time
53
+ parent.find_val('centralized_site_config_refresh')
54
+ end
55
+
56
+ def cached_file
57
+ @cached_file ||= Pathname(parent.centralized_site_config_cache_dir).join('cached_config')
58
+ end
59
+
60
+ def cached?
61
+ File.exist?(cached_file)
62
+ end
63
+
64
+ def fetch
65
+ def inform_user_of_cached_file
66
+ if cached?
67
+ puts 'Origen: Site Config: Found previously cached site config. Using the older site config.'.yellow
68
+ else
69
+ puts 'Origen: Site Config: No cached file found. An empty site config will be used in its place.'.yellow
70
+ end
71
+ puts
72
+ end
73
+
74
+ if centralized?
75
+ puts "Pulling centralized site config from: #{path}"
76
+
77
+ begin
78
+ text = HTTParty.get(path, verify: parent.find_val('centralized_site_config_verify_ssl'))
79
+ puts "Caching centralized site config to: #{cached_file}"
80
+
81
+ unless Dir.exist?(cached_file.dirname)
82
+ FileUtils.mkdir_p(cached_file.dirname)
83
+ end
84
+ File.open(cached_file, 'w').write(text)
85
+
86
+ rescue SocketError => e
87
+ puts "Origen: Site Config: Unable to connect to #{path}".red
88
+ puts 'Origen: Site Config: Failed to retrieve centralized site config!'.red
89
+ puts "Error from exception: #{e.message}".red
90
+
91
+ inform_user_of_cached_file
92
+ rescue OpenSSL::SSL::SSLError => e
93
+ puts "Origen: Site Config: Unable to connect to #{path}".red
94
+ puts 'Origen: Site Config: Failed to retrieve centralized site config!'.red
95
+ puts "Error from exception: #{e.message}".red
96
+ puts 'It looks like the error is related to SSL certification. If this is a trusted server, you can use ' \
97
+ "the site config setting 'centralized_site_config_verify_ssl' to disable verifying the SSL certificate.".red
98
+
99
+ inform_user_of_cached_file
100
+ rescue Exception => e
101
+ # Rescue anything else to avoid any un-caught exceptions causing Origen not to boot.
102
+ # Print lots of red so that the users are aware that there's a problem, but don't ultimately want this
103
+ # to render Origen un-bootable
104
+ puts "Origen: Site Config: Unexpected exception ocurred trying to either retrieve or cache the site config at #{path}".red
105
+ puts 'Origen: Site Config: Failed to retrieve centralized site config!'.red
106
+ puts "Class of exception: #{e.class}".red
107
+ puts "Error from exception: #{e.message}".red
108
+
109
+ inform_user_of_cached_file
110
+ end
111
+ text
112
+ end
113
+ end
114
+ alias_method :refresh, :fetch
115
+
116
+ # Loads the site config into memory.
117
+ # Process the site config as an ERB, if indicated to do so (.erb file extension)
118
+ # After the initial load, any centralized site configs will be retreived (if needed), cached, and loaded.
119
+ def load
120
+ def read_erb(erb)
121
+ ERB.new(File.read(erb), 0, '%<>')
122
+ end
123
+
124
+ if centralized?
125
+ if !cached?
126
+ if fetch
127
+ # erb = ERB.new(File.read(cached_file), 0, '%<>')
128
+ erb = read_erb(cached_file)
129
+ else
130
+ # There was a problem fetching the cnofig. Just use an empty string.
131
+ # Warning message will come from #fetch
132
+ erb = ERB.new('')
133
+ end
134
+ else
135
+ # erb = ERB.new(File.read(cached_file), 0, '%<>')
136
+ erb = read_erb(cached_file)
137
+ end
138
+
139
+ @values = (YAML.load(erb.result) || {})
140
+ else
141
+ if File.extname(path) == '.erb'
142
+ # erb = ERB.new(File.read(path), 0, '%<>')
143
+ erb = read_erb(path)
144
+ @values = (YAML.load(erb.result) || {})
145
+ else
146
+ @values = (YAML.load_file(path) || {})
147
+ end
148
+ end
149
+
150
+ unless @values.is_a?(Hash)
151
+ puts "Origen: Site Config: The config at #{path} was not parsed as a Hash, but as a #{@values.class}".red
152
+ puts ' Please review the format of the this file.'.red
153
+ puts ' This config will not be loaded and will be replaced with an empty config.'.red
154
+ puts
155
+ @values = {}
156
+ end
157
+
158
+ if centralized?
159
+ # check for restricted centralized config values
160
+ RESTRICTED_FROM_CENTRALIZED_VARIABLES.each do |var|
161
+ if @values.key?(var)
162
+ val = @values.delete(var)
163
+ puts 'Origen: Site Config: ' \
164
+ "config variable #{var} is not allowed in the centralized site config and will be removed. " \
165
+ "Value #{val} will not be applied!".red
166
+ end
167
+ end
168
+ end
169
+
170
+ @loaded = true
171
+ @values
172
+ end
173
+
174
+ def remove_var(var)
175
+ @values.delete(var)
176
+ end
177
+
178
+ def has_var?(var)
179
+ @values.key?(var)
180
+ end
181
+
182
+ # Finds the value from this config, or from one of its centralized configs (if applicable)
183
+ def find_val(val)
184
+ @values[val]
185
+ end
186
+ alias_method :[], :find_val
187
+
188
+ def loaded?
189
+ @loaded
190
+ end
191
+
192
+ def local?
193
+ type == :local
194
+ end
195
+
196
+ def centralized?
197
+ type == :centralized
198
+ end
199
+
200
+ def runtime?
201
+ type == :runtime
202
+ end
203
+ end
204
+ end
205
+ end
@@ -44,10 +44,11 @@ module Origen
44
44
  Origen.mailer.send_email(options)
45
45
  end
46
46
 
47
- def id
47
+ def id(options = {})
48
48
  @id.to_s.downcase
49
49
  end
50
50
  alias_method :core_id, :id
51
+ alias_method :username, :id
51
52
 
52
53
  # Returns true if the user is an admin for the current application
53
54
  def admin?
@@ -73,7 +74,7 @@ module Origen
73
74
  RevisionControl::Git.user_name
74
75
  end
75
76
 
76
- def email
77
+ def email(options = {})
77
78
  if current?
78
79
  @email ||= ENV['ORIGEN_EMAIL'] || email_from_rc || begin
79
80
  if Origen.site_config.email_domain
@@ -7,13 +7,18 @@ module Origen
7
7
  # Generic method to send an email, alternatively use one of the
8
8
  # pre-defined mail types using the other methods.
9
9
  def send_email(options = {})
10
- options = { server: Origen.site_config.email_server,
11
- port: Origen.site_config.email_port,
12
- from: current_user.email,
13
- from_alias: current_user.name,
14
- subject: 'Hello',
15
- body: 'Hello from Origen!',
16
- to: 'Stephen McGinty <stephen.mcginty@freescale.com>'
10
+ options = { server: Origen.site_config.email_server,
11
+ port: Origen.site_config.email_port,
12
+ from: current_user.email,
13
+ from_alias: current_user.name,
14
+ subject: 'Hello',
15
+ body: 'Hello from Origen!',
16
+ to: current_user.email,
17
+ authentication: (Origen.site_config.email_authentication || :none).to_sym,
18
+ domain: (Origen.site_config.email_domain || ''),
19
+
20
+ auth_user: (Origen.site_config.email_auth_user || current_user.email),
21
+ auth_password: (Origen.site_config.email_auth_password || current_user.password)
17
22
  }.merge(options)
18
23
 
19
24
  # Force to an array
@@ -32,10 +37,38 @@ Subject: #{options[:subject]}
32
37
  END_OF_MESSAGE
33
38
 
34
39
  begin
40
+ Origen.log.debug('Origen::Utility::Mailer Setup:')
41
+ options.each { |k, v| Origen.log.debug(" #{k}: #{v}") }
42
+
43
+ # Net::SMTP.start(options[:server], options[:port]) do |smtp|
44
+ # smtp.send_message msg, options[:from], addr
45
+ # end
46
+
35
47
  # Exceptions raised here will be caught by rescue clause
36
- Net::SMTP.start(options[:server], options[:port]) do |smtp|
37
- smtp.send_message msg, options[:from], addr
48
+ smtp = Net::SMTP.new(options[:server], options[:port])
49
+ smtp.enable_starttls if options[:authentication] != :none
50
+
51
+ opts = begin
52
+ if options[:authentication] == :none
53
+ # Trying to add username and password if there's no authentication will actually be rejected by
54
+ # the server.
55
+ [options[:domain]]
56
+ else
57
+ [options[:domain], options[:auth_user], options[:auth_password], options[:authentication]]
58
+ end
59
+ end
60
+
61
+ smtp.start(*opts) do |m|
62
+ m.send_message(msg, options[:from], addr)
38
63
  end
64
+
65
+ # Exceptions raised here will be caught by rescue clause
66
+ # smtp = Net::SMTP.new(options[:server], options[:port])
67
+ # smtp.enable_starttls
68
+
69
+ # smtp.start (options[:domain], options[:auth_user], options[:auth_password], options[:authentication]) do |smtp|
70
+ # smtp.send_message(msg, options[:from], addr)
71
+ # end
39
72
  rescue
40
73
  warn "Email not able to be sent to address '#{addr}'"
41
74
  end
@@ -12,6 +12,23 @@
12
12
  # # Or a reference to a plugin's Git repository can be used
13
13
  # - "http://bitbucket.mycompany.net/origen/my_app_generators.git"
14
14
 
15
+ # Centralized Site Config
16
+ # Origen +0.36 (versions after 36.0) supports a centralized site config. This site config will be implicitly read and
17
+ # injected into the site config following the default site configs from Origen.
18
+ # To surpress the number of requests and possible load time delays, the site config can be cached and read on each
19
+ # startup for :centralized_site_config_refresh number of hours.
20
+ centralized_site_config_cache_dir: '~/.origen/cache/site_config'
21
+
22
+ # Indicates how many hours should pass before the cached site config is refreshed (refetched, redownloaded)
23
+ # The default is to refresh once per day (every 24 hours). Decimal values can be used here to get more granularity
24
+ # if needed.
25
+ # 0 indidcates 'always refresh' (cache will still occur though)
26
+ # -1 indicates never refresh.
27
+ centralized_site_config_refresh: 24
28
+
29
+ # Indicates whether the SSL certificate should be verified when pulling the centralized site config
30
+ centralized_site_config_verify_ssl: true
31
+
15
32
  # GEM SETUP
16
33
 
17
34
  # If your company has an internal gem server enter it here
@@ -88,10 +105,16 @@ gem_use_from_system:
88
105
  # User.new("ax1234").email # => "ax1234@company.com"
89
106
  #
90
107
  # # Without email_domain specified
91
- # User.new("ax1234@company.com").email # => "ax1234@company.com"
108
+ # User.new("ax1234@company.com").email # => "ax1234@company.com"
109
+ # If authentication is needed to use the given server, email_authentication can be set to login.
110
+ # If a service user is used to access this account on behalf of the sending users, email_auth_user and email_auth_password
111
+ # can be set. If authentication is indicated but no auth user is given, the current user's email and password are used instead.
92
112
  #email_domain: company.com
93
113
  #email_server: smtp.company.net
94
114
  #email_port: 25
115
+ #email_authentication: login
116
+ #email_auth_user: service_email
117
+ #email_auth_password: service_password
95
118
 
96
119
  # Required parameters to connect to your company's LDAP system
97
120
  #ldap_username: cn=manager,dc=example,dc=com
@@ -69,7 +69,7 @@ module Origen
69
69
  model.add_virtual_pin :relay1
70
70
  model.add_virtual_pin :relay2, packages: { bga: {} }
71
71
 
72
- model.sub_block :block1, file: 'origen/export1/block1.rb', dir: '/home/stephen/Code/github/origen/vendor/lib/models', lazy: true
72
+ model.sub_block :block1, file: 'origen/export1/block1.rb', dir: '/proj/imxrt1170_test/users/nxa20023/origen/dev/trash/origen/vendor/lib/models', lazy: true
73
73
 
74
74
  end
75
75
  end
@@ -4,7 +4,7 @@ module Origen
4
4
  module Export1
5
5
  module Block1
6
6
  def self.extended(model)
7
- model.sub_block :x, file: 'origen/export1/block1/x.rb', dir: '/home/stephen/Code/github/origen/vendor/lib/models', lazy: true, base_address: 0x40000000
7
+ model.sub_block :x, file: 'origen/export1/block1/x.rb', dir: '/proj/imxrt1170_test/users/nxa20023/origen/dev/trash/origen/vendor/lib/models', lazy: true, base_address: 0x40000000
8
8
 
9
9
  end
10
10
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: origen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.36.0
4
+ version: 0.36.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen McGinty
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-08 00:00:00.000000000 Z
11
+ date: 2018-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -457,6 +457,7 @@ files:
457
457
  - lib/origen/commands/program.rb
458
458
  - lib/origen/commands/rc.rb
459
459
  - lib/origen/commands/save.rb
460
+ - lib/origen/commands/site.rb
460
461
  - lib/origen/commands/target.rb
461
462
  - lib/origen/commands/time.rb
462
463
  - lib/origen/commands/version.rb
@@ -568,6 +569,7 @@ files:
568
569
  - lib/origen/revision_control/subversion.rb
569
570
  - lib/origen/ruby_version_check.rb
570
571
  - lib/origen/site_config.rb
572
+ - lib/origen/site_config/config.rb
571
573
  - lib/origen/specs.rb
572
574
  - lib/origen/specs/checkers.rb
573
575
  - lib/origen/specs/creation_info.rb
@@ -652,7 +654,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
652
654
  version: 1.8.11
653
655
  requirements: []
654
656
  rubyforge_project:
655
- rubygems_version: 2.7.6
657
+ rubygems_version: 2.7.7
656
658
  signing_key:
657
659
  specification_version: 4
658
660
  summary: The Semiconductor Developer's Kit