workEnv 0.1.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,604 @@
1
+ module WorkEnvs
2
+ class Common < CLIClassTool::Common
3
+ end
4
+
5
+ class WorkEnvAction < Common
6
+ ACTION_LIST = [ :check, :clean, :config, :create, :get, :help, :list, :package_lookup, :query, :rename, :rm, :switch, :test, :update ]
7
+
8
+ ACTION_HELP = {
9
+ :check => "Check an environment validity.",
10
+ :clean => "Clean an environment.",
11
+ :config => "View and Edit WorkEnvs parameters.",
12
+ :create => "Create a new environment.",
13
+ :get => "Get the properties of the current environment.",
14
+ :help => "Display help or manual pages for WorkEnvs commands.",
15
+ :list => "List available environments.",
16
+ :package_lookup => "Lookup environments containing a package.",
17
+ :query => "Query database for packages and versions.",
18
+ :rename => "Rename an environment.",
19
+ :rm => "Remove an environment.",
20
+ :switch => "Switch to a different environment.",
21
+ :test => "Verify the type and properties of an environment.",
22
+ :update => "Update an environment with new versions."
23
+ }
24
+
25
+ # Set command-line options specifically for each action
26
+ def self.set_opts(action, parser, opts)
27
+ case action
28
+ when :clean
29
+ parser.on("-n", "--name <env_name>", String, "Name of the environment to clean.") {|val| opts[:name] = val}
30
+ WorkEnvs::configSelectorPrepare(opts, parser)
31
+
32
+ when :config
33
+ WorkEnvs::configSelectorPrepare(opts, parser)
34
+ parser.separator ""
35
+ parser.separator "Advanced Settings:"
36
+ parser.on("--[no-]confirm-delete", nil, "[Do not] Ask confirmation before removing an environment.") {
37
+ |val| opts[:settings][:global][:confirm_delete] = val}
38
+ parser.on("--[no-]confirm-update", nil, "[Do not] Ask confirmation before retrieving workEnv updates.") {
39
+ |val| opts[:settings][:global][:silent_update] = !val}
40
+ parser.on("--default-option <option-name=value>", String, "Default option. Can be overriden with --options.") {
41
+ |val|
42
+ opts[:settings][:global][:default_options] = WorkEnvs::EnvOpts.new() if opts[:settings][:global][:default_options] == nil
43
+ opts[:settings][:global][:default_options] << val}
44
+ parser.on("--global", nil, "Parse/Save only the global config file.") {
45
+ |val| opts[:settings][:control][:globalOnly] = true}
46
+ parser.on("--show <path/in/tree>", String, "Show a specific settings. Example: db/package_repos.") {
47
+ |val| opts[:show] = val}
48
+
49
+ when :create
50
+ opts[:type] = WorkEnvs::WORK_ENV_DEFAULT_TYPE
51
+ parser.on("-n", "--name <env_name>", String, "Name of the environment to create.") {|val| opts[:name] = val}
52
+ parser.on("-t", "--type <envType>", String, "Environment type: Default = #{opts[:type]}.") {|val| opts[:type] = val}
53
+ parser.on("-r", "--release ", nil, "Released versions only.") {|val| opts[:settings][:db][:package_default_table] = "releases"}
54
+ WorkEnvs::configSelectorPrepare(opts, parser)
55
+ parser.separator ""
56
+ WorkEnvs::addEnvToOptParser(parser)
57
+
58
+ when :help, :switch
59
+ opts[:ignore_opts] = true
60
+ if action == :switch
61
+ parser.on("-n", "--name <env_name>", String, "Name of the environment to switch to.") {|val| opts[:name] = val}
62
+ end
63
+
64
+ when :list
65
+ parser.on("-s", "--short", nil, "Short version.") {|val| opts[:listType] = :short}
66
+ parser.on("-l", "--long", nil, "Long version.") {|val| opts[:listType] = :long}
67
+ parser.on("-n", "--name-only", nil, "Only print env namess.") {|val| opts[:listType] = :name}
68
+
69
+ when :package_lookup
70
+ opts[:rec] = false
71
+ opts[:envOpts] = WorkEnvs::EnvOpts.new()
72
+ opts[:checkGitDependencies] = false
73
+ parser.on("-t", "--type <envType>", String, "Environment type: Default = #{opts[:type]}.") {|val| opts[:type] = val}
74
+ parser.on("-p", "--package <package>", String, "Package to lookup.") {|val| opts[:package] = val}
75
+ parser.on("-r", "--regex", String, "Allow extended package name matching.") {|val| opts[:regex] = true}
76
+
77
+ when :query
78
+ opts[:type] = WorkEnvs::WORK_ENV_DEFAULT_TYPE
79
+ opts[:envOpts][WorkEnvs::WENV_OPTS_EXTERNAL] = "true"
80
+ opts[:download] = false
81
+ opts[:rQuery] = false
82
+ opts[:raw] = false
83
+ opts[:updateLookup] = false
84
+ opts[:checkGitDependencies] = false
85
+ opts[:no_deps] = false
86
+
87
+ parser.on("-t", "--type <envType>", String, "Environment type: Default = #{opts[:type]}.") {|val| opts[:type] = val}
88
+ parser.on("-r", "--release ", nil, "Released versions only.") {|val| opts[:settings][:db][:package_default_table] = "releases"}
89
+ parser.on("-i", "--internal ", nil, "List internal packages.") {|val| opts[:envOpts][WorkEnvs::WENV_OPTS_EXTERNAL] = nil}
90
+ parser.on("-d", "--download [download_dir]", String, "Download the packages.") {|val| opts[:download] = val}
91
+ parser.on("-c", "--createrepo", nil, "Create a repository in the downloaded package repository. Requires --download" ) {|val| opts[:createRepo] = true}
92
+ parser.on("-r", "--raw", nil, "Generate YAML/B64 object to describe all packages" ) {|val| opts[:raw] = true}
93
+ parser.on("--check-git-dependencies", nil, "Check that git dependencies match RPMs" ) {|val| opts[:checkGitDependencies] = true}
94
+ parser.on("--show-environments", nil, "Show the list of environments being pulled") {|val| opts[:showEnvironments] = true }
95
+ parser.on("--no-dependencies", nil, "Only check the selected env type and not its dependencies") {|val| opts[:no_deps] = true }
96
+ parser.on("--list-envs", nil, "List existing environment types.") {|val|
97
+ envHash = WorkEnvs::listEnvTypes()
98
+ puts envHash.map(){|x, y| x.to_s()}.join(' ')
99
+ exit(0)
100
+ }
101
+ WorkEnvs::versionSelectorPrepare(opts, parser)
102
+ WorkEnvs::configSelectorPrepare(opts, parser)
103
+ parser.separator ""
104
+ WorkEnvs::addEnvToOptParser(parser)
105
+
106
+ when :rename
107
+ parser.on("-n", "--name <env_name>", String, "Original name of the environment.") {|val| opts[:name] = val}
108
+ parser.on("-N", "--new-name <new_env_name>", String, "New name to give the environment.") {|val| opts[:newname] = val}
109
+ WorkEnvs::configSelectorPrepare(opts, parser)
110
+
111
+ when :rm
112
+ parser.on("-n", "--name <env_name>", String, "Name of the environment to remove.") {|val| opts[:name] = val}
113
+ WorkEnvs::configSelectorPrepare(opts, parser)
114
+
115
+ when :test
116
+ opts[:rec] = false
117
+ opts[:envOpts] = WorkEnvs::EnvOpts.new()
118
+ opts[:checkGitDependencies] = false
119
+ parser.on("-n", "--name <env_name>", String, "Name of the environment to test.") {|val| opts[:name] = val}
120
+ parser.on("-t", "--type <envType>", String, "Environment type.") {|val| opts[:type] = val}
121
+
122
+ when :update
123
+ opts[:checkGitDependencies] = false
124
+ parser.on("-n", "--name <env_name>", String, "Name of the environment to update.") {|val| opts[:name] = val}
125
+ parser.on("-d", "--date <MM/DD/YYYY>", String, "License expiration date.") {|val| opts[:date] = val}
126
+ parser.on("-f", "--force", nil, "Force to update even if env looks up to date.") {|val| opts[:force_update] = true}
127
+ parser.on("--force-if-not-const", nil, "Force to update even if env looks up to date but is not const.") {|val| opts[:force_update_if_not_const] = true}
128
+ parser.on("-D", "--dump-infos <info.txt>", String, "Dump the version of the required packages.") {|val| opts[:dumpInfos] = val}
129
+ parser.on("-o", "--options <option-name=value>", String, "Pass extra options to an environment.") {|val| opts[:envOpts] << val}
130
+ parser.on("-k", "--install-dkms", nil, "Install DKMS packages.") {|val| opts[:installDKMS] = true}
131
+ parser.on("-K", "--keep-packages", nil, "Keep downloaded packages at the top of the env.") {|val| opts[:keepPackages] = true}
132
+ parser.on("--do-not-update", nil, "Skip the actual download/extract/install part.") {|val| opts[:doNotUpdate] = true}
133
+ parser.on("--check-git-dependencies", nil, "Check that git dependencies match RPMs" ) {|val| opts[:checkGitDependencies] = true}
134
+ parser.on("--no-dependencies", nil, "Only check the selected env type and not its dependencies") {|val| opts[:no_deps] = true }
135
+
136
+ WorkEnvs::versionSelectorPrepare(opts, parser)
137
+ WorkEnvs::configSelectorPrepare(opts, parser)
138
+ parser.separator ""
139
+
140
+ WorkEnvs::listEnvTypes.each(){|name, envClass|
141
+ sub_opts = []
142
+
143
+ begin
144
+ sub_opts = WorkEnvs::getOptions(envClass)
145
+ rescue
146
+ end
147
+
148
+ next if sub_opts.length == 0
149
+ if envClass == WorkEnvs::BasicEnv then
150
+ parser.separator "Supported options for any environment:"
151
+ else
152
+ parser.separator "Supported options for environment of type '#{WorkEnvs::getEnvType(envClass)}':"
153
+ end
154
+ sub_opts.each(){|str|
155
+ parser.separator str
156
+ }
157
+ }
158
+ end
159
+ end
160
+
161
+ # Perform command-line options checks and final configuration
162
+ def self.check_opts(opts)
163
+ case opts[:action]
164
+ when :clean, :create, :query, :rename, :rm, :update
165
+ # These all run the final config selector
166
+ WorkEnvs::configSelectorFinal(opts)
167
+ end
168
+
169
+ case opts[:action]
170
+ when :clean, :create, :rename, :rm
171
+ if opts[:name] == nil
172
+ raise WorkEnvs::RunError.new(1, "No name provided")
173
+ end
174
+ end
175
+
176
+ case opts[:action]
177
+ when :rename
178
+ if opts[:newname] == nil
179
+ raise WorkEnvs::RunError.new(1, "No new name provided")
180
+ end
181
+ end
182
+ end
183
+
184
+ # 1. Action: check
185
+ def check(opts)
186
+ curEnv = WorkEnvs::getCurrentEnv()
187
+ return 1 if curEnv == nil
188
+ curEnv.checkEnv(curEnv.versions)
189
+ return 0
190
+ end
191
+
192
+ # 2. Action: clean
193
+ def clean(opts)
194
+ name = WorkEnvs::nameToEnvName(opts[:name])
195
+
196
+ if WorkEnvs::getCurrentEnvName() == name
197
+ log(:ERROR, "You are actually using '#{name}'. You cannot clean your current environment")
198
+ return 1
199
+ end
200
+ if WorkEnvs::settings[:global][:confirm_delete] != false
201
+ WorkEnvs::Confirm.new("Are you sure you want to clean '#{opts[:name]}' ?")
202
+ WorkEnvs::Confirm.new("Are you really really really sure you want to clean '#{opts[:name]}' ?")
203
+ end
204
+
205
+ env = WorkEnvs::getEnv(name)
206
+ env.cleanup()
207
+ log(:INFO, "Environment '#{opts[:name]}' successfully cleaned")
208
+ return 0
209
+ end
210
+
211
+ # 3. Action: config
212
+ def config(opts)
213
+ if opts[:show] != nil then
214
+ path = opts[:show].split("/")
215
+ entry = WorkEnvs::settings()
216
+ while path.length > 0
217
+ d = path.shift
218
+ entry = entry[d.to_sym()]
219
+ end
220
+ begin
221
+ puts entry.join("\n")
222
+ rescue
223
+ puts entry
224
+ end
225
+ end
226
+ return 0
227
+ end
228
+
229
+ # 4. Action: create
230
+ def create(opts)
231
+ WorkEnvs::createEnv(opts[:name], opts[:type], nil)
232
+ log(:INFO, "Environment '#{opts[:name]}' successfully created")
233
+ return 0
234
+ end
235
+
236
+ # 5. Action: get
237
+ def get(opts)
238
+ curEnv = WorkEnvs::getCurrentEnv()
239
+ return 1 if curEnv == nil
240
+
241
+ puts "Current environment stored at: #{WorkEnvs::WORK_ENVS}\n\n"
242
+ puts WorkEnvs::listHeader()
243
+ puts curEnv
244
+ puts "Properties: " + curEnv.properties.to_s
245
+ return 0
246
+ end
247
+
248
+ # 6. Action: help
249
+ def help(opts)
250
+ args = opts[:extra_args] || []
251
+ root_dir = File.expand_path('../..', __dir__)
252
+ wenv_man_dir = root_dir + "/man"
253
+
254
+ if args.length != 1 then
255
+ if File.exist?(wenv_man_dir + "/man7/wenv.7") then
256
+ system("man " + wenv_man_dir + "/man7/wenv.7") or return 1
257
+ return 0
258
+ else
259
+ return 1
260
+ end
261
+ end
262
+
263
+ commands = WorkEnvs.getActionAttr("ACTION_LIST").map { |x| WorkEnvs.actionToString(x) }
264
+
265
+ name = args.shift
266
+ if commands.index(name) == nil then
267
+ found = 0
268
+ full_name = ""
269
+ commands.each(){|cmd|
270
+ next if cmd !~ /^#{name}/
271
+ found += 1
272
+ full_name = cmd
273
+ }
274
+ if found != 1 then
275
+ log(:ERROR, "No such action '#{name}'")
276
+ raise WorkEnvs::RunError.new(1, "No such command")
277
+ else
278
+ name = full_name
279
+ end
280
+ end
281
+
282
+ if File.exist?(wenv_man_dir + "/man1/wenv-" + name + ".1")
283
+ system("man " + wenv_man_dir + "/man1/wenv-" + name + ".1") or return 1
284
+ else
285
+ system("ruby " + root_dir + "/wenv " + name + " --help") or return 1
286
+ end
287
+ return 0
288
+ end
289
+
290
+ # 7. Action: list
291
+ def list(opts)
292
+ envs = WorkEnvs::getEnvs()
293
+ if opts[:listType] != :name then
294
+ puts "Environments stored at:\n"
295
+ WorkEnvs::getDirList().each{|label, dirpath|
296
+ puts " - #{label} => #{dirpath}"
297
+ }
298
+ puts "\n"
299
+ end
300
+ if envs.length == 0 then
301
+ puts "No environments"
302
+ else
303
+ puts WorkEnvs::listHeader() if opts[:listType] != :name
304
+ envs.each(){|env|
305
+ puts env.to_s(opts[:listType])
306
+ }
307
+ end
308
+ return 0
309
+ end
310
+
311
+ # 8. Action: package_lookup
312
+ def package_lookup(opts)
313
+ if opts[:package] != nil then
314
+ if opts[:type] != nil then
315
+ packages = WorkEnvs::listAllPackages(WorkEnvs::stringToEnvClass(opts[:type]))
316
+ if packages.index(opts[:package]) != nil then
317
+ puts "Env '#{opts[:type]}' contains package '#{opts[:package]}'"
318
+ return 0
319
+ else
320
+ puts "Env '#{opts[:type]}' does contains package '#{opts[:package]}'"
321
+ return 1
322
+ end
323
+ else
324
+ types = WorkEnvs::listEnvTypes()
325
+ containsList=[]
326
+ containsHash={}
327
+ types.each() {|label, envClass|
328
+ packages = WorkEnvs::listAllPackages(envClass)
329
+ index = nil
330
+ if (opts[:regex]) then
331
+ index = packages.index(){|e| e =~ /#{opts[:package]}/}
332
+ next if index == nil
333
+
334
+ containsHash[packages[index]] = [] if containsHash[packages[index]] == nil
335
+ containsHash[packages[index]] << label
336
+ else
337
+ index = packages.index(opts[:package])
338
+ containsList << label if index != nil
339
+ end
340
+ }
341
+ if containsList.length == 0 && containsHash.length == 0 then
342
+ puts "Package '#{opts[:package]}' does not belong to any environment"
343
+ return 1
344
+ else
345
+ if (opts[:regex]) then
346
+ containsHash.each(){|p, envs|
347
+ puts "Package '#{p}' matching regexp belongs to environments:"
348
+ puts " - " + envs.join("\n - ")
349
+ }
350
+ else
351
+ puts "Package '#{opts[:package]}' belongs to environments:"
352
+ puts containsList.join("\n")
353
+ end
354
+ end
355
+ end
356
+ else
357
+ packages = WorkEnvs::listAllPackages(WorkEnvs::stringToEnvClass(opts[:type]))
358
+ puts packages.join("\n")
359
+ end
360
+ return 0
361
+ end
362
+
363
+ # 9. Action: query
364
+ def query(opts)
365
+ if opts[:settings][:control][:rSettings] != nil then
366
+ rOpts = opts[:settings][:control][:rSettings][:opts]
367
+ opts[:raw] = true
368
+ opts[:infos] = rOpts[:infos]
369
+ opts[:infos_extra] = rOpts[:infos_extra]
370
+ opts[:type] = rOpts[:type]
371
+ opts[:release] = rOpts[:release]
372
+ opts[:envOpts] = rOpts[:envOpts]
373
+ opts[:no_deps] = rOpts[:no_deps]
374
+ end
375
+
376
+ env = WorkEnvs::instantiateEnv("QUERY_____", opts[:type], nil, opts[:release])
377
+
378
+ WorkEnvs::versionSelectorFinal(opts, env)
379
+
380
+ if opts[:infos].empty? then
381
+ if opts[:ignore_empty] == true then
382
+ puts "INFO: No matching packages found"
383
+ return 0
384
+ else
385
+ raise WorkEnvs::RunError.new(1, "Error: No version, sha1, or sub env provided")
386
+ end
387
+ end
388
+
389
+ filelist = nil
390
+ temp_list = nil
391
+
392
+ if opts[:raw] != false then
393
+ downloader, packages, temp_packages = env.get_dependencies_raw(opts)
394
+ packages.each(){|p| p.path = nil }
395
+ temp_packages.each(){|p| p.path = nil }
396
+ puts WorkEnvs::serialize({:packages => packages, :temp_packages => temp_packages})
397
+ return 0
398
+ end
399
+
400
+ if opts[:showEnvironments] == true then
401
+ puts "==========================================================="
402
+ puts "Requested environments"
403
+ puts opts[:infos].to_s
404
+ puts "==========================================================="
405
+ end
406
+ filelist, temp_list = env.get_dependencies(opts)
407
+ filelist.sort!
408
+ temp_list.sort!
409
+
410
+ puts "\n\nRequired packages:"
411
+ filelist.each(){|pack|
412
+ puts pack.path
413
+ }
414
+ if opts[:envOpts][WorkEnvs::WENV_OPTS_EXTERNAL] != "true" then
415
+ puts "\n\nExtra packages:"
416
+ temp_list.each(){|pack|
417
+ puts pack.path
418
+ }
419
+ end
420
+
421
+ if opts[:download] != false then
422
+ downloader = WorkEnvs::PackageDownloader.new()
423
+ downloader.be_silent = !WorkEnvs::VERBOSE
424
+ lastChoice = false
425
+ opts[:download] = "." if opts[:download] == nil || opts[:download] == ""
426
+ puts "Downloading selected RPMS to #{opts[:download]}"
427
+ if ! File.directory?(opts[:download]) then
428
+ Dir.mkdir(opts[:download])
429
+ end
430
+ curDir = Dir.pwd()
431
+ Dir.chdir(opts[:download])
432
+ list = filelist
433
+ list += temp_list if opts[:envOpts][WorkEnvs::WENV_OPTS_EXTERNAL] != "true"
434
+ tName=runCmd("mktemp", !WorkEnvs::VERBOSE)
435
+ runCmd("rm -f #{tName}", !WorkEnvs::VERBOSE)
436
+ list.each(){|pack|
437
+ fName = File.basename(pack.path)
438
+ if File.exist?(fName) then
439
+ lastChoice = WorkEnvs::OverWrite.check("File #{fName} already exists. Do you want to overwrite it?:", lastChoice)
440
+ next if lastChoice == false
441
+ File.delete(fName)
442
+ end
443
+ downloader.download(pack, tName)
444
+ runCmd("mv -Z #{tName} #{File.basename(pack.path)} || mv #{tName} #{File.basename(pack.path)}", !WorkEnvs::VERBOSE)
445
+ }
446
+ if opts[:createRepo] == true then
447
+ arch = WorkEnvs::PackageDownloader.getArch()
448
+ raise("Target machine is not RHEL based. Cannot create a repo") if arch[:base] != "RHEL"
449
+ puts "Creating repository in #{opts[:download]}"
450
+ runCmd("createrepo #{opts[:download]}", !WorkEnvs::VERBOSE)
451
+ end
452
+ end
453
+ return 0
454
+ end
455
+
456
+ # 10. Action: rename
457
+ def rename(opts)
458
+ if !WorkEnvs::isEnv?(opts[:name])
459
+ log(:ERROR, "'#{opts[:name]} is not a valid environment")
460
+ return 1
461
+ end
462
+ if WorkEnvs::getCurrentEnvName() == opts[:name]
463
+ log(:ERROR, "You are actually using '#{opts[:name]}'. You cannot rename your current environment")
464
+ return 1
465
+ end
466
+
467
+ env = WorkEnvs::getEnv(opts[:name])
468
+ env.rename(opts[:newname])
469
+ log(:INFO, "Environment '#{opts[:name]}' successfully renamed")
470
+ return 0
471
+ end
472
+
473
+ # 11. Action: rm
474
+ def rm(opts)
475
+ if !WorkEnvs::isEnv?(opts[:name])
476
+ log(:ERROR, "'#{opts[:name]}' is not a valid environment")
477
+ return 1
478
+ end
479
+ if WorkEnvs::getCurrentEnvName() == opts[:name]
480
+ log(:ERROR, "You are actually using '#{opts[:name]}'. You cannot delete your current environment")
481
+ return 1
482
+ end
483
+ if WorkEnvs::settings[:global][:confirm_delete] != false
484
+ WorkEnvs::Confirm.new("Are you sure you want to delete '#{opts[:name]}' ?")
485
+ WorkEnvs::Confirm.new("Are you really really really sure you want to delete '#{opts[:name]}' ?")
486
+ end
487
+
488
+ WorkEnvs::deleteEnv(opts[:name])
489
+ log(:INFO, "Environment '#{opts[:name]}' successfully deleted")
490
+ return 0
491
+ end
492
+
493
+ # 12. Action: switch
494
+ def switch(opts)
495
+ args = opts[:extra_args] || []
496
+ envName = opts[:name]
497
+
498
+ if envName.to_s == ""
499
+ if args.length == 0
500
+ raise WorkEnvs::RunError.new(1, "No environment name provided")
501
+ end
502
+ envName = args[0]
503
+ args.shift
504
+ end
505
+
506
+ envName = WorkEnvs::nameToEnvName(envName)
507
+
508
+ if WorkEnvs::getCurrentEnvName() == envName
509
+ log(:ERROR, "You are already in this environment")
510
+ return 1
511
+ end
512
+
513
+ if !WorkEnvs::isSwitchable?(envName)
514
+ log(:ERROR, "Cannot switch to an uninitialized environment")
515
+ return 1
516
+ end
517
+ env = WorkEnvs::getEnv(envName)
518
+
519
+ cmd = ""
520
+ if args.length > 0 then
521
+ cmd = "-c " + "'" + 0.upto(args.length - 1).map(){|x| "$#{x}"}.join(" ") + "' '"+
522
+ + args.join("' '") + "'"
523
+ end
524
+
525
+ switchEnvFile = env.genPath() +"/" + WorkEnvs::ENV_SWITCH
526
+ env.genSwitchEnvScript()
527
+
528
+ exec_cmd = "BASH_ENV=\"#{switchEnvFile}\" bash --rcfile #{switchEnvFile} #{cmd}"
529
+ exec(exec_cmd)
530
+ end
531
+
532
+ # 13. Action: test
533
+ def test(opts)
534
+ opts[:name] = WorkEnvs::nameToEnvName(opts[:name])
535
+ env = WorkEnvs::getEnv(opts[:name])
536
+
537
+ raise WorkEnvs::EnvNoTypeErrorException if opts[:type].to_s == ""
538
+
539
+ envClass = WorkEnvs::stringToEnvClass(opts[:type])
540
+ raise("Environment has type '#{env.type}', expected '#{WorkEnvs::getEnvType(envClass)}'") if ! (envClass === env)
541
+
542
+ puts "Environment has type '#{env.type}'"
543
+ return 0
544
+ end
545
+
546
+ # 14. Action: update
547
+ def update(opts)
548
+ opts[:name] = WorkEnvs::nameToEnvName(opts[:name])
549
+ env = WorkEnvs::getEnv(opts[:name])
550
+
551
+ WorkEnvs::versionSelectorFinal(opts, env)
552
+
553
+ opts[:ignore_empty] = true if env.isDev?()
554
+
555
+ if opts[:infos].empty? then
556
+ if opts[:ignore_empty] == true then
557
+ puts "INFO: No matching packages found"
558
+ return 0 if !env.isDev?()
559
+ else
560
+ raise WorkEnvs::RunError.new(1, "Error: No version, sha1, or sub env provided")
561
+ end
562
+ end
563
+
564
+ ret = env.update(opts)
565
+
566
+ if ret == true
567
+ puts "Environment '#{opts[:name]}' successfully updated"
568
+ else
569
+ puts "Environment '#{opts[:name]}' looks already up-to-date. Use --force to force an env update."
570
+ end
571
+
572
+ if opts[:dumpInfos] != nil then
573
+ f = File.open(opts[:dumpInfos], "w+")
574
+ f.puts opts[:infos]
575
+ f.close()
576
+ dir = File.dirname(opts[:dumpInfos])
577
+
578
+ puts "==========================================================="
579
+ puts "Extras dependencies provided but not checkout :"
580
+ puts opts[:infos_extra].to_s
581
+ puts "==========================================================="
582
+ opts[:infos_extra].concat(opts[:infos])
583
+
584
+ if WorkEnvs::VERBOSE then
585
+ puts "==========================================================="
586
+ puts "Complete dependencies: Checkouted + extra:"
587
+ puts opts[:infos_extra].to_s
588
+ puts "==========================================================="
589
+ end
590
+
591
+ opts[:infos_extra].each(){|name, value|
592
+ tClass = WorkEnvs::symbolToClass(name)
593
+ revFile = WorkEnvs::getRevFile(tClass)
594
+ next if revFile.to_s == ""
595
+ revFile.gsub!(/_revision$/, '_version.txt')
596
+ f = File.open(dir + '/' + revFile, "w+")
597
+ f.puts value[:version]
598
+ f.close
599
+ }
600
+ end
601
+ return 0
602
+ end
603
+ end
604
+ end