geordi 2.10.1 → 3.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.ruby-version +1 -1
- data/.travis.yml +8 -2
- data/CHANGELOG.md +46 -0
- data/Gemfile +2 -5
- data/Gemfile.lock +10 -10
- data/README.md +11 -6
- data/Rakefile +6 -10
- data/{bin → exe}/b +0 -0
- data/{bin → exe}/cap-all +0 -0
- data/{bin → exe}/console-for +0 -0
- data/{bin → exe}/cuc +0 -0
- data/{bin → exe}/cuc-show +0 -0
- data/{bin → exe}/cuc-vnc-setup +0 -0
- data/{bin → exe}/deploy-to-production +0 -0
- data/{bin → exe}/dump-for +0 -0
- data/{bin → exe}/dumple +0 -0
- data/{bin → exe}/geordi +0 -0
- data/{bin → exe}/gitpt +0 -0
- data/{bin → exe}/launchy_browser +0 -0
- data/{bin → exe}/load-dump +0 -0
- data/{bin → exe}/migrate-all +0 -0
- data/{bin → exe}/rs +0 -0
- data/{bin → exe}/run_tests +0 -0
- data/{bin → exe}/shell-for +0 -0
- data/{bin → exe}/tests +0 -0
- data/geordi.gemspec +23 -20
- data/lib/geordi/COMMAND_TEMPLATE +4 -6
- data/lib/geordi/capistrano_config.rb +20 -17
- data/lib/geordi/chromedriver_updater.rb +9 -10
- data/lib/geordi/cli.rb +5 -2
- data/lib/geordi/commands/_setup_vnc.rb +23 -23
- data/lib/geordi/commands/apache_site.rb +3 -3
- data/lib/geordi/commands/bundle_install.rb +3 -3
- data/lib/geordi/commands/capistrano.rb +5 -6
- data/lib/geordi/commands/chromedriver_update.rb +0 -9
- data/lib/geordi/commands/clean.rb +5 -6
- data/lib/geordi/commands/commit.rb +0 -1
- data/lib/geordi/commands/console.rb +4 -4
- data/lib/geordi/commands/create_database_yml.rb +4 -4
- data/lib/geordi/commands/create_databases.rb +3 -3
- data/lib/geordi/commands/cucumber.rb +25 -25
- data/lib/geordi/commands/delete_dumps.rb +12 -12
- data/lib/geordi/commands/deploy.rb +27 -28
- data/lib/geordi/commands/drop_databases.rb +13 -15
- data/lib/geordi/commands/dump.rb +12 -13
- data/lib/geordi/commands/eurest.rb +2 -2
- data/lib/geordi/commands/firefox.rb +4 -4
- data/lib/geordi/commands/migrate.rb +3 -3
- data/lib/geordi/commands/png_optimize.rb +15 -14
- data/lib/geordi/commands/rake.rb +3 -3
- data/lib/geordi/commands/remove_executable_flags.rb +3 -3
- data/lib/geordi/commands/rspec.rb +11 -11
- data/lib/geordi/commands/security_update.rb +25 -25
- data/lib/geordi/commands/server.rb +6 -6
- data/lib/geordi/commands/setup.rb +8 -8
- data/lib/geordi/commands/shell.rb +3 -3
- data/lib/geordi/commands/tests.rb +1 -1
- data/lib/geordi/commands/unit.rb +3 -3
- data/lib/geordi/commands/update.rb +7 -7
- data/lib/geordi/commands/vnc.rb +1 -1
- data/lib/geordi/commands/with_rake.rb +3 -3
- data/lib/geordi/commands/yarn_install.rb +3 -3
- data/lib/geordi/cucumber.rb +35 -36
- data/lib/geordi/db_cleaner.rb +40 -41
- data/lib/geordi/dump_loader.rb +6 -5
- data/lib/geordi/firefox_for_selenium.rb +26 -29
- data/lib/geordi/gitpt.rb +14 -15
- data/lib/geordi/interaction.rb +2 -6
- data/lib/geordi/remote.rb +9 -10
- data/lib/geordi/util.rb +28 -25
- data/lib/geordi/version.rb +1 -1
- metadata +27 -39
- data/features/commit.feature +0 -17
- data/features/console.feature +0 -7
- data/features/cucumber.feature +0 -261
- data/features/deploy.feature +0 -66
- data/features/dump.feature +0 -34
- data/features/firefox.feature +0 -44
- data/features/server.feature +0 -31
- data/features/setup.feature +0 -11
- data/features/shell.feature +0 -78
- data/features/support/env.rb +0 -8
- data/features/support/step_definitions/aruba_backport_steps.rb +0 -5
- data/features/support/step_definitions/miscellaneous_steps.rb +0 -11
@@ -7,13 +7,13 @@ Lets you select the server to connect to when called with `--select-server`:
|
|
7
7
|
geordi shell production -s
|
8
8
|
LONGDESC
|
9
9
|
|
10
|
-
option :select_server, :
|
10
|
+
option :select_server, default: false, type: :boolean, aliases: '-s'
|
11
11
|
|
12
12
|
# This method has a triple 'l' because :shell is a Thor reserved word. However,
|
13
13
|
# it can still be called with `geordi shell` :)
|
14
|
-
def shelll(target, *
|
14
|
+
def shelll(target, *_args)
|
15
15
|
require 'geordi/remote'
|
16
16
|
|
17
|
-
announce 'Opening a shell on ' + target
|
17
|
+
Interaction.announce 'Opening a shell on ' + target
|
18
18
|
Geordi::Remote.new(target).shell(options)
|
19
19
|
end
|
data/lib/geordi/commands/unit.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
desc 'unit', 'Run Test::Unit'
|
2
2
|
def unit
|
3
|
-
if File.
|
3
|
+
if File.exist?('test/test_helper.rb')
|
4
4
|
invoke_cmd 'bundle_install'
|
5
5
|
invoke_cmd 'yarn_install'
|
6
6
|
|
7
|
-
announce 'Running Test::Unit'
|
7
|
+
Interaction.announce 'Running Test::Unit'
|
8
8
|
Util.system! 'bundle exec rake test'
|
9
9
|
else
|
10
|
-
note 'Test::Unit not employed.'
|
10
|
+
Interaction.note 'Test::Unit not employed.'
|
11
11
|
end
|
12
12
|
end
|
@@ -16,18 +16,18 @@ After updating, runs all tests when called with the `--test` option:
|
|
16
16
|
See `geordi help update` for details.
|
17
17
|
LONGDESC
|
18
18
|
|
19
|
-
option :dump, :
|
20
|
-
:
|
21
|
-
option :test, :
|
19
|
+
option :dump, type: :string, aliases: '-d', banner: 'TARGET',
|
20
|
+
desc: 'After updating, dump the TARGET db and source it into the development db'
|
21
|
+
option :test, type: :boolean, aliases: '-t', desc: 'After updating, run tests'
|
22
22
|
|
23
23
|
def update
|
24
|
-
announce 'Updating repository'
|
25
|
-
Util.system! 'git pull', :
|
24
|
+
Interaction.announce 'Updating repository'
|
25
|
+
Util.system! 'git pull', show_cmd: true
|
26
26
|
|
27
27
|
invoke_cmd 'migrate'
|
28
28
|
|
29
|
-
success 'Successfully updated the project.'
|
29
|
+
Interaction.success 'Successfully updated the project.'
|
30
30
|
|
31
|
-
invoke_cmd 'dump', options.dump, :
|
31
|
+
invoke_cmd 'dump', options.dump, load: true if options.dump
|
32
32
|
invoke_cmd 'tests' if options.test
|
33
33
|
end
|
data/lib/geordi/commands/vnc.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
desc 'with-rake', 'Run tests with `rake`', :
|
1
|
+
desc 'with-rake', 'Run tests with `rake`', hide: true
|
2
2
|
def with_rake
|
3
3
|
if Util.file_containing?('Rakefile', /^task.+default.+(spec|test|feature)/)
|
4
4
|
invoke_cmd 'bundle_install'
|
5
5
|
invoke_cmd 'yarn_install'
|
6
6
|
|
7
|
-
announce 'Running tests with `rake`'
|
7
|
+
Interaction.announce 'Running tests with `rake`'
|
8
8
|
Util.system! 'rake'
|
9
9
|
else
|
10
|
-
note '`rake` does not run tests.'
|
10
|
+
Interaction.note '`rake` does not run tests.'
|
11
11
|
:did_not_perform
|
12
12
|
end
|
13
13
|
end
|
@@ -1,8 +1,8 @@
|
|
1
|
-
desc 'yarn-install', 'Runs yarn install if required', :
|
1
|
+
desc 'yarn-install', 'Runs yarn install if required', hide: true
|
2
2
|
|
3
3
|
def yarn_install
|
4
|
-
if File.
|
5
|
-
announce 'Yarn install'
|
4
|
+
if File.exist?('package.json') && !system('yarn check --integrity > /dev/null 2>&1')
|
5
|
+
Interaction.announce 'Yarn install'
|
6
6
|
Util.system! 'yarn install'
|
7
7
|
end
|
8
8
|
end
|
data/lib/geordi/cucumber.rb
CHANGED
@@ -3,17 +3,16 @@ require 'tempfile'
|
|
3
3
|
|
4
4
|
# This require-style is to prevent Ruby from loading files of a different
|
5
5
|
# version of Geordi.
|
6
|
-
require File.expand_path('
|
7
|
-
require File.expand_path('
|
6
|
+
require File.expand_path('interaction', __dir__)
|
7
|
+
require File.expand_path('firefox_for_selenium', __dir__)
|
8
8
|
|
9
9
|
module Geordi
|
10
10
|
class Cucumber
|
11
|
-
include Geordi::Interaction
|
12
11
|
|
13
|
-
VNC_DISPLAY = ':17'
|
14
|
-
VNC_SERVER_COMMAND = "vncserver #{VNC_DISPLAY} -localhost -nolisten tcp -SecurityTypes None -geometry 1280x1024"
|
15
|
-
VNC_VIEWER_COMMAND = "vncviewer #{VNC_DISPLAY}"
|
16
|
-
VNC_ENV_VARIABLES = %w[DISPLAY BROWSER LAUNCHY_BROWSER]
|
12
|
+
VNC_DISPLAY = ':17'.freeze
|
13
|
+
VNC_SERVER_COMMAND = "vncserver #{VNC_DISPLAY} -localhost -nolisten tcp -SecurityTypes None -geometry 1280x1024".freeze
|
14
|
+
VNC_VIEWER_COMMAND = "vncviewer #{VNC_DISPLAY}".freeze
|
15
|
+
VNC_ENV_VARIABLES = %w[DISPLAY BROWSER LAUNCHY_BROWSER].freeze
|
17
16
|
|
18
17
|
def run(files, cucumber_options, options = {})
|
19
18
|
self.argv = files + cucumber_options.map { |option| option.split('=') }.flatten
|
@@ -23,27 +22,27 @@ module Geordi
|
|
23
22
|
setup_vnc
|
24
23
|
|
25
24
|
command = use_parallel_tests?(options) ? parallel_execution_command : serial_execution_command
|
26
|
-
note_cmd(command) if options[:verbose]
|
25
|
+
Interaction.note_cmd(command) if options[:verbose]
|
27
26
|
|
28
27
|
puts # Make newline
|
29
28
|
system command # Util.system! would reset the Firefox PATH
|
30
29
|
end
|
31
30
|
|
32
31
|
def launch_vnc_viewer
|
33
|
-
fork
|
32
|
+
fork do
|
34
33
|
error = capture_stderr do
|
35
34
|
system(VNC_VIEWER_COMMAND)
|
36
35
|
end
|
37
36
|
unless $?.success?
|
38
37
|
if $?.exitstatus == 127
|
39
|
-
fail 'VNC viewer not found. Install it with `geordi vnc --setup`.'
|
38
|
+
Interaction.fail 'VNC viewer not found. Install it with `geordi vnc --setup`.'
|
40
39
|
else
|
41
|
-
note 'VNC viewer could not be opened:'
|
40
|
+
Interaction.note 'VNC viewer could not be opened:'
|
42
41
|
puts error
|
43
42
|
puts
|
44
43
|
end
|
45
44
|
end
|
46
|
-
|
45
|
+
end
|
47
46
|
end
|
48
47
|
|
49
48
|
def restore_env
|
@@ -57,10 +56,10 @@ module Geordi
|
|
57
56
|
VNC_ENV_VARIABLES.each do |variable|
|
58
57
|
ENV["OUTER_#{variable}"] = ENV[variable] if ENV[variable]
|
59
58
|
end
|
60
|
-
ENV[
|
61
|
-
ENV[
|
59
|
+
ENV['BROWSER'] = ENV['LAUNCHY_BROWSER'] = File.expand_path('../../bin/launchy_browser', __dir__)
|
60
|
+
ENV['DISPLAY'] = VNC_DISPLAY
|
62
61
|
|
63
|
-
note 'Run `geordi vnc` to view the Selenium test browsers'
|
62
|
+
Interaction.note 'Run `geordi vnc` to view the Selenium test browsers'
|
64
63
|
end
|
65
64
|
end
|
66
65
|
|
@@ -73,11 +72,11 @@ module Geordi
|
|
73
72
|
unless argv.include?('--format') || argv.include?('-f')
|
74
73
|
format_args = spinner_available? ? ['--format', 'CucumberSpinner::CuriousProgressBarFormatter'] : ['--format', 'progress']
|
75
74
|
end
|
76
|
-
[use_firefox_for_selenium,
|
75
|
+
[use_firefox_for_selenium, 'b', 'cucumber', format_args, escape_shell_args(argv)].flatten.compact.join(' ')
|
77
76
|
end
|
78
77
|
|
79
78
|
def parallel_execution_command
|
80
|
-
note 'Using parallel_tests'
|
79
|
+
Interaction.note 'Using parallel_tests'
|
81
80
|
self.argv = argv - command_line_features
|
82
81
|
|
83
82
|
type_arg = Util.gem_version('parallel_tests') > Gem::Version.new('0.7.0') ? 'cucumber' : 'features'
|
@@ -87,8 +86,8 @@ module Geordi
|
|
87
86
|
[
|
88
87
|
use_firefox_for_selenium,
|
89
88
|
'b parallel_test -t ' + type_arg,
|
90
|
-
%(-o '#{
|
91
|
-
"-- #{
|
89
|
+
%(-o '#{command_line_options.join(' ')} --tags "#{not_tag('@solo')}"'),
|
90
|
+
"-- #{features.join(' ')}",
|
92
91
|
].compact.join(' ')
|
93
92
|
end
|
94
93
|
|
@@ -109,21 +108,21 @@ module Geordi
|
|
109
108
|
|
110
109
|
def escape_shell_args(*args)
|
111
110
|
args.flatten.collect do |arg|
|
112
|
-
arg.gsub(/([\\ "])/) { |
|
111
|
+
arg.gsub(/([\\ "])/) { |_match| "\\#{Regexp.last_match(1)}" }
|
113
112
|
end
|
114
113
|
end
|
115
114
|
|
116
115
|
def show_features_to_run
|
117
116
|
if command_line_options.include? '@solo'
|
118
|
-
note 'All features tagged with @solo'
|
117
|
+
Interaction.note 'All features tagged with @solo'
|
119
118
|
elsif command_line_options.include? 'rerun'
|
120
|
-
note 'Rerunning failed scenarios'
|
119
|
+
Interaction.note 'Rerunning failed scenarios'
|
121
120
|
elsif features_to_run.empty?
|
122
|
-
note 'All features in features/'
|
121
|
+
Interaction.note 'All features in features/'
|
123
122
|
else
|
124
123
|
notification = 'Only: ' + features_to_run.join(', ')
|
125
124
|
notification << ' (from rerun.txt)' if (features_to_run == rerun_txt_features) && (features_to_run != command_line_features)
|
126
|
-
note notification
|
125
|
+
Interaction.note notification
|
127
126
|
end
|
128
127
|
end
|
129
128
|
|
@@ -137,8 +136,8 @@ module Geordi
|
|
137
136
|
|
138
137
|
def rerun_txt_features
|
139
138
|
@rerun_txt_features ||= begin
|
140
|
-
if File.
|
141
|
-
IO.read(
|
139
|
+
if File.exist?('rerun.txt')
|
140
|
+
IO.read('rerun.txt').to_s.strip.split(/\s+/)
|
142
141
|
else
|
143
142
|
[]
|
144
143
|
end
|
@@ -150,7 +149,7 @@ module Geordi
|
|
150
149
|
end
|
151
150
|
|
152
151
|
def command_line_options
|
153
|
-
@command_line_options ||=
|
152
|
+
@command_line_options ||= [].tap do |args|
|
154
153
|
# Sorry for this mess. Option parsing doesn't get much prettier.
|
155
154
|
argv.each_cons(2) do |a, b|
|
156
155
|
break if a == '--' # This is the common no-options-beyond marker
|
@@ -171,9 +170,9 @@ module Geordi
|
|
171
170
|
end
|
172
171
|
|
173
172
|
def consolidate_rerun_txt_files
|
174
|
-
parallel_rerun_files = Dir.glob(
|
173
|
+
parallel_rerun_files = Dir.glob('parallel_rerun*.txt')
|
175
174
|
unless parallel_rerun_files.empty?
|
176
|
-
note 'Consolidating parallel_rerun.txt files ...'
|
175
|
+
Interaction.note 'Consolidating parallel_rerun.txt files ...'
|
177
176
|
|
178
177
|
rerun_content = []
|
179
178
|
parallel_rerun_files.each do |filename|
|
@@ -181,8 +180,8 @@ module Geordi
|
|
181
180
|
File.unlink(filename)
|
182
181
|
end
|
183
182
|
|
184
|
-
File.open(
|
185
|
-
f.puts(rerun_content.join(
|
183
|
+
File.open('rerun.txt', 'w') do |f|
|
184
|
+
f.puts(rerun_content.join(' '))
|
186
185
|
end
|
187
186
|
end
|
188
187
|
end
|
@@ -190,14 +189,14 @@ module Geordi
|
|
190
189
|
def find_all_features_recursively(files_or_dirs)
|
191
190
|
Array(files_or_dirs).map do |file_or_dir|
|
192
191
|
if File.directory?(file_or_dir)
|
193
|
-
file_or_dir = Dir.glob(File.join(file_or_dir,
|
192
|
+
file_or_dir = Dir.glob(File.join(file_or_dir, '**', '*.feature'))
|
194
193
|
end
|
195
194
|
file_or_dir
|
196
195
|
end.flatten.uniq.compact
|
197
196
|
end
|
198
197
|
|
199
198
|
def spinner_available?
|
200
|
-
@spinner_available ||= File.
|
199
|
+
@spinner_available ||= File.exist?('Gemfile') && File.open('Gemfile').read.scan(/cucumber_spinner/).any?
|
201
200
|
end
|
202
201
|
|
203
202
|
def use_parallel_tests?(options)
|
@@ -209,7 +208,7 @@ module Geordi
|
|
209
208
|
|
210
209
|
def try_and_start_vnc
|
211
210
|
# check if vnc is already running
|
212
|
-
#return true if vnc_server_running?
|
211
|
+
# return true if vnc_server_running?
|
213
212
|
error = capture_stderr do
|
214
213
|
system(VNC_SERVER_COMMAND)
|
215
214
|
end
|
@@ -218,10 +217,10 @@ module Geordi
|
|
218
217
|
98 # was already running after all
|
219
218
|
true
|
220
219
|
when 127 # not installed
|
221
|
-
warn 'Could not launch VNC server. Install it with `geordi vnc --setup`.'
|
220
|
+
Interaction.warn 'Could not launch VNC server. Install it with `geordi vnc --setup`.'
|
222
221
|
false
|
223
222
|
else
|
224
|
-
warn 'Starting VNC failed:'
|
223
|
+
Interaction.warn 'Starting VNC failed:'
|
225
224
|
puts error
|
226
225
|
puts
|
227
226
|
false
|
data/lib/geordi/db_cleaner.rb
CHANGED
@@ -4,17 +4,16 @@ require 'tempfile'
|
|
4
4
|
|
5
5
|
module Geordi
|
6
6
|
class DBCleaner
|
7
|
-
include Geordi::Interaction
|
8
7
|
|
9
8
|
def initialize(extra_flags)
|
10
9
|
puts 'Please enter your sudo password if asked, for db operations as system users'
|
11
10
|
puts "We're going to run `sudo -u postgres psql` for PostgreSQL"
|
12
11
|
puts ' and `sudo mysql` for MariaDB (which uses PAM auth)'
|
13
12
|
`sudo true`
|
14
|
-
fail 'sudo access is required for database operations as database users' if $? != 0
|
13
|
+
Interaction.fail 'sudo access is required for database operations as database users' if $? != 0
|
15
14
|
@derivative_dbname = /_(test\d*|development|cucumber)$/
|
16
15
|
base_directory = ENV['XDG_CONFIG_HOME']
|
17
|
-
base_directory =
|
16
|
+
base_directory = Dir.home.to_s if base_directory.nil?
|
18
17
|
@whitelist_directory = File.join(base_directory, '.config', 'geordi', 'whitelists')
|
19
18
|
FileUtils.mkdir_p(@whitelist_directory) unless File.directory? @whitelist_directory
|
20
19
|
@mysql_command = decide_mysql_command(extra_flags['mysql'])
|
@@ -23,11 +22,11 @@ module Geordi
|
|
23
22
|
|
24
23
|
def edit_whitelist(dbtype)
|
25
24
|
whitelist = whitelist_fname(dbtype)
|
26
|
-
if File.exist? whitelist
|
27
|
-
|
25
|
+
whitelisted_dbs = if File.exist? whitelist
|
26
|
+
Geordi::Util.stripped_lines(File.read(whitelist))\
|
28
27
|
.delete_if { |l| l.start_with? '#' }
|
29
28
|
else
|
30
|
-
|
29
|
+
[]
|
31
30
|
end
|
32
31
|
all_dbs = list_all_dbs(dbtype)
|
33
32
|
tmp = Tempfile.open("geordi_whitelist_#{dbtype}")
|
@@ -66,7 +65,7 @@ HEREDOC
|
|
66
65
|
tmpfile_content.push(['keep', db_name]) unless db_name.empty?
|
67
66
|
end
|
68
67
|
if warn_manual_whitelist
|
69
|
-
warn <<-ERROR_MSG.gsub(/^\s*/, '')
|
68
|
+
Interaction.warn <<-ERROR_MSG.gsub(/^\s*/, '')
|
70
69
|
Your whitelist #{whitelist} seems to have been generated manually.
|
71
70
|
In that case, make sure to use only one database name per line and omit the 'keep' prefix."
|
72
71
|
|
@@ -82,16 +81,16 @@ HEREDOC
|
|
82
81
|
texteditor = Geordi::Util.decide_texteditor
|
83
82
|
system("#{texteditor} #{tmp.path}")
|
84
83
|
File.open(tmp.path, 'r') do |wl_edited|
|
85
|
-
whitelisted_dbs =
|
84
|
+
whitelisted_dbs = []
|
86
85
|
whitelist_storage = File.open(whitelist, 'w')
|
87
86
|
lines = Geordi::Util.stripped_lines(wl_edited.read)
|
88
87
|
lines.each do |line|
|
89
88
|
next if line.start_with?('#')
|
90
89
|
unless line.split.length == 2
|
91
|
-
fail "Invalid edit to whitelist file: \`#{line}\` - Syntax is: ^[keep|drop] dbname$"
|
90
|
+
Interaction.fail "Invalid edit to whitelist file: \`#{line}\` - Syntax is: ^[keep|drop] dbname$"
|
92
91
|
end
|
93
92
|
unless %w[keep drop k d].include? line.split.first
|
94
|
-
fail "Invalid edit to whitelist file: \`#{line}\` - must start with either drop or keep."
|
93
|
+
Interaction.fail "Invalid edit to whitelist file: \`#{line}\` - must start with either drop or keep."
|
95
94
|
end
|
96
95
|
db_status, db_name = line.split
|
97
96
|
if db_status == 'keep'
|
@@ -107,32 +106,32 @@ HEREDOC
|
|
107
106
|
cmd = 'sudo mysql'
|
108
107
|
unless extra_flags.nil?
|
109
108
|
if extra_flags.include? 'port'
|
110
|
-
port = Integer(extra_flags.split('=')[1].split
|
111
|
-
fail "Port #{port} is not open" unless Geordi::Util.is_port_open? port
|
109
|
+
port = Integer(extra_flags.split('=')[1].split[0])
|
110
|
+
Interaction.fail "Port #{port} is not open" unless Geordi::Util.is_port_open? port
|
112
111
|
end
|
113
112
|
cmd << " #{extra_flags}"
|
114
113
|
end
|
115
|
-
Open3.popen3("#{cmd} -e 'QUIT'") do |
|
114
|
+
Open3.popen3("#{cmd} -e 'QUIT'") do |_stdin, _stdout, stderr, thread|
|
116
115
|
break if thread.value.exitstatus == 0
|
117
116
|
# sudo mysql was not successful, switching to mysql-internal user management
|
118
117
|
mysql_error = stderr.read.lines[0].chomp.strip.split[1]
|
119
|
-
if %w[1045 1698].include? mysql_error
|
118
|
+
if %w[1045 1698].include? mysql_error # authentication failed
|
120
119
|
cmd = 'mysql -uroot'
|
121
120
|
cmd << " #{extra_flags}" unless extra_flags.nil?
|
122
121
|
unless File.exist? File.join(Dir.home, '.my.cnf')
|
123
122
|
puts "Please enter your MySQL/MariaDB password for account 'root'."
|
124
|
-
warn "You should create a ~/.my.cnf file instead, or you'll need to enter your MySQL root password for each db."
|
125
|
-
warn
|
126
|
-
cmd << ' -p'
|
123
|
+
Interaction.warn "You should create a ~/.my.cnf file instead, or you'll need to enter your MySQL root password for each db."
|
124
|
+
Interaction.warn 'See https://makandracards.com/makandra/50813-store-mysql-passwords-for-development for more information.'
|
125
|
+
cmd << ' -p' # need to ask for password now
|
127
126
|
end
|
128
|
-
Open3.popen3("#{cmd} -e 'QUIT'") do |
|
129
|
-
fail 'Could not connect to MySQL/MariaDB' unless
|
127
|
+
Open3.popen3("#{cmd} -e 'QUIT'") do |_stdin_2, _stdout_2, _stderr_2, thread_2|
|
128
|
+
Interaction.fail 'Could not connect to MySQL/MariaDB' unless thread_2.value.exitstatus == 0
|
130
129
|
end
|
131
|
-
elsif mysql_error == '2013'
|
132
|
-
fail 'MySQL/MariaDB connection failed, is this the correct port?'
|
130
|
+
elsif mysql_error == '2013' # connection to port or socket failed
|
131
|
+
Interaction.fail 'MySQL/MariaDB connection failed, is this the correct port?'
|
133
132
|
end
|
134
133
|
end
|
135
|
-
|
134
|
+
cmd
|
136
135
|
end
|
137
136
|
private :decide_mysql_command
|
138
137
|
|
@@ -141,22 +140,22 @@ HEREDOC
|
|
141
140
|
unless extra_flags.nil?
|
142
141
|
begin
|
143
142
|
port = Integer(extra_flags.split('=')[1])
|
144
|
-
fail "Port #{port} is not open" unless Geordi::Util.is_port_open? port
|
143
|
+
Interaction.fail "Port #{port} is not open" unless Geordi::Util.is_port_open? port
|
145
144
|
rescue ArgumentError
|
146
145
|
socket = extra_flags.split('=')[1]
|
147
|
-
fail "Socket #{socket} does not exist" unless File.exist? socket
|
146
|
+
Interaction.fail "Socket #{socket} does not exist" unless File.exist? socket
|
148
147
|
end
|
149
148
|
cmd << " #{extra_flags}"
|
150
149
|
end
|
151
|
-
|
150
|
+
cmd
|
152
151
|
end
|
153
152
|
private :decide_postgres_command
|
154
153
|
|
155
154
|
def list_all_dbs(dbtype)
|
156
155
|
if dbtype == 'postgres'
|
157
|
-
|
156
|
+
list_all_postgres_dbs
|
158
157
|
else
|
159
|
-
|
158
|
+
list_all_mysql_dbs
|
160
159
|
end
|
161
160
|
end
|
162
161
|
|
@@ -172,7 +171,7 @@ HEREDOC
|
|
172
171
|
end
|
173
172
|
|
174
173
|
def clean_mysql
|
175
|
-
announce 'Checking for MySQL databases'
|
174
|
+
Interaction.announce 'Checking for MySQL databases'
|
176
175
|
database_list = list_all_dbs('mysql')
|
177
176
|
# confirm_deletion includes option for whitelist editing
|
178
177
|
deletable_dbs = confirm_deletion('mysql', database_list)
|
@@ -181,19 +180,19 @@ HEREDOC
|
|
181
180
|
if @mysql_command.include? '-p'
|
182
181
|
puts "Please enter your MySQL/MariaDB account 'root' for: DROP DATABASE #{db}"
|
183
182
|
else
|
184
|
-
note "Dropping MySQL/MariaDB database #{db}"
|
183
|
+
Interaction.note "Dropping MySQL/MariaDB database #{db}"
|
185
184
|
end
|
186
185
|
`#{@mysql_command} -e 'DROP DATABASE \`#{db}\`;'`
|
187
186
|
end
|
188
187
|
end
|
189
188
|
|
190
189
|
def clean_postgres
|
191
|
-
announce 'Checking for Postgres databases'
|
190
|
+
Interaction.announce 'Checking for Postgres databases'
|
192
191
|
database_list = list_all_dbs('postgres')
|
193
192
|
deletable_dbs = confirm_deletion('postgres', database_list)
|
194
193
|
return if deletable_dbs.nil?
|
195
194
|
deletable_dbs.each do |db|
|
196
|
-
note "Dropping PostgreSQL database `#{db}`."
|
195
|
+
Interaction.note "Dropping PostgreSQL database `#{db}`."
|
197
196
|
`#{@postgres_command} -c 'DROP DATABASE "#{db}";'`
|
198
197
|
end
|
199
198
|
end
|
@@ -207,27 +206,27 @@ HEREDOC
|
|
207
206
|
until %w[y n].include? proceed
|
208
207
|
deletable_dbs = filter_whitelisted(dbtype, database_list)
|
209
208
|
if deletable_dbs.empty?
|
210
|
-
note "No #{dbtype} databases found that were not whitelisted"
|
211
|
-
if prompt('Edit the whitelist? [y]es or [n]o') == 'y'
|
209
|
+
Interaction.note "No #{dbtype} databases found that were not whitelisted"
|
210
|
+
if Interaction.prompt('Edit the whitelist? [y]es or [n]o') == 'y'
|
212
211
|
proceed = 'e'
|
213
212
|
else
|
214
213
|
return []
|
215
214
|
end
|
216
215
|
end
|
217
216
|
if proceed.empty?
|
218
|
-
note "The following #{dbtype} databases are not whitelisted and could be deleted:"
|
217
|
+
Interaction.note "The following #{dbtype} databases are not whitelisted and could be deleted:"
|
219
218
|
deletable_dbs.sort.each do |db|
|
220
219
|
puts db
|
221
220
|
end
|
222
|
-
note "Those #{dbtype} databases are not whitelisted and could be deleted."
|
223
|
-
proceed = prompt('Proceed? [y]es, [n]o or [e]dit whitelist')
|
221
|
+
Interaction.note "Those #{dbtype} databases are not whitelisted and could be deleted."
|
222
|
+
proceed = Interaction.prompt('Proceed? [y]es, [n]o or [e]dit whitelist')
|
224
223
|
end
|
225
224
|
case proceed
|
226
225
|
when 'e'
|
227
|
-
proceed = ''
|
226
|
+
proceed = '' # reset user selection
|
228
227
|
edit_whitelist dbtype
|
229
228
|
when 'n'
|
230
|
-
success 'Not deleting anything'
|
229
|
+
Interaction.success 'Not deleting anything'
|
231
230
|
return []
|
232
231
|
when 'y'
|
233
232
|
return deletable_dbs
|
@@ -245,10 +244,10 @@ HEREDOC
|
|
245
244
|
end
|
246
245
|
|
247
246
|
def is_whitelisted?(dbtype, database_name)
|
248
|
-
if File.exist? whitelist_fname(dbtype)
|
249
|
-
|
247
|
+
whitelist_content = if File.exist? whitelist_fname(dbtype)
|
248
|
+
Geordi::Util.stripped_lines(File.open(whitelist_fname(dbtype), 'r').read)
|
250
249
|
else
|
251
|
-
|
250
|
+
[]
|
252
251
|
end
|
253
252
|
# Allow explicit whitelisting of derivative databases like projectname_test2
|
254
253
|
if whitelist_content.include? database_name
|