-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patht_set_instance.rb
executable file
·99 lines (80 loc) · 2.55 KB
/
t_set_instance.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#! /usr/bin/ruby
=begin
--------------------------------------------------------------------------------
Choose an instance from among the ~/Testing/instances/* directories, and
record that choice.
--------------------------------------------------------------------------------
To be eligible, a directory must include a instance.properties file. Display a
list of ineligible directories along with the eligible ones.
--------------------------------------------------------------------------------
=end
$: << File.dirname(File.expand_path(__FILE__))
require 'common'
class InstanceStub
attr_reader :filename
attr_reader :path
attr_reader :description
def initialize(filename, path, description)
@filename = filename
@path = path
@description = description
end
end
# Find out what instances we have available
def locate_instances()
instances_dir = ENV['HOME']+'/Testing/instances'
@instances = []
@invalid = []
Dir.entries(instances_dir).sort().each() do |filename|
next if filename.start_with?(".")
path = File.expand_path(filename, instances_dir)
props_file = File.expand_path('instance.properties', path)
if File.exist?(props_file)
props = PropertyFileReader.read(props_file)
description = props.description || "(no description)"
@instances.push(InstanceStub.new(filename, path, description))
else
@invalid.push(filename)
end
end
end
def choose_instance()
if ([email protected]?)
puts
puts "Ignored invalid directories: "
puts " #{@invalid.join(', ')}"
end
puts
puts "Enter instance number: "
@instances.each_index do |index|
instance = @instances[index]
puts " #{index+1} = #{instance.filename} -- #{instance.description}"
end
input = STDIN.gets.chomp
@choice = input.to_i
if @choice <= 0 || @choice > @instances.length
raise UserInputError.new("Invalid index: #{input}")
end
end
def save_choice()
full_instance = Instance.from_instance_path(@instances[@choice-1].path)
File.open($settings_file, "w") do |file|
file.puts("# The currently seleted instance")
file.puts("instance_path = #{full_instance.path}")
file.puts("logs_path = #{full_instance.tomcat.path}/logs")
file.puts("home_path = #{full_instance.props.vivo_home}")
end
puts "instance set to '#{full_instance.filename}'"
end
#
# ---------------------------------------------------------
# MAIN ROUTINE
# ---------------------------------------------------------
#
locate_instances()
begin
choose_instance()
save_choice()
rescue UserInputError
puts "ERROR: #{$!}"
end