Add database import action to menu
This commit is contained in:
@@ -4,7 +4,9 @@ use strict;
|
|||||||
use warnings;
|
use warnings;
|
||||||
use diagnostics;
|
use diagnostics;
|
||||||
|
|
||||||
|
use Curses;
|
||||||
use Curses::UI;
|
use Curses::UI;
|
||||||
|
use Curses::UI::Common;
|
||||||
|
|
||||||
# Singleton
|
# Singleton
|
||||||
my $_cui;
|
my $_cui;
|
||||||
@@ -125,4 +127,60 @@ sub select_from_list {
|
|||||||
return @selection;
|
return @selection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Returns the entered string or undef when cancelled
|
||||||
|
sub read_string {
|
||||||
|
my ( $title, $default ) = @_;
|
||||||
|
|
||||||
|
my $value;
|
||||||
|
|
||||||
|
my $cui = init_cui();
|
||||||
|
my $win = $cui->add( 'root', 'Window', );
|
||||||
|
|
||||||
|
my $entry;
|
||||||
|
$entry = $win->add(
|
||||||
|
'string_entry',
|
||||||
|
'TextEntry',
|
||||||
|
-title => $title,
|
||||||
|
-border => 1,
|
||||||
|
-text => ( defined $default ? $default : '' ),
|
||||||
|
);
|
||||||
|
|
||||||
|
$win->add(
|
||||||
|
'info', 'Label',
|
||||||
|
-y => -1,
|
||||||
|
-text => "Enter = confirm, Esc = cancel",
|
||||||
|
);
|
||||||
|
|
||||||
|
# Set cursor to the end
|
||||||
|
$entry->pos( length $entry->get() );
|
||||||
|
|
||||||
|
# Enter would otherwise just leave the entry
|
||||||
|
$entry->clear_binding('loose-focus');
|
||||||
|
|
||||||
|
$entry->set_binding(
|
||||||
|
sub {
|
||||||
|
$value = $entry->get();
|
||||||
|
$value =~ s/^\s+|\s+$//g;
|
||||||
|
$cui->mainloopExit();
|
||||||
|
},
|
||||||
|
KEY_ENTER(),
|
||||||
|
);
|
||||||
|
|
||||||
|
$entry->set_binding(
|
||||||
|
sub {
|
||||||
|
$value = undef;
|
||||||
|
$cui->mainloopExit();
|
||||||
|
},
|
||||||
|
CUI_ESCAPE(),
|
||||||
|
);
|
||||||
|
|
||||||
|
$entry->focus();
|
||||||
|
$cui->mainloop();
|
||||||
|
|
||||||
|
$cui->leave_curses();
|
||||||
|
$cui->delete('root');
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|||||||
@@ -817,6 +817,37 @@ my %handlers = (
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
'32. Import Database (Mars)' => sub {
|
||||||
|
|
||||||
|
# Import databse dump on mars
|
||||||
|
die "No dumps in $local_dump_dir" unless -d $local_dump_dir;
|
||||||
|
my @dumps = grep { /\.sql$/ } Util::find_files($local_dump_dir);
|
||||||
|
my @selected_dumps =
|
||||||
|
TUI::select_from_list( "Select Dump to Import into Mars", 0, @dumps );
|
||||||
|
die "No dump selected" unless @selected_dumps;
|
||||||
|
my $dump_file = "$local_dump_dir/$selected_dumps[0]";
|
||||||
|
|
||||||
|
# Determine database name
|
||||||
|
my $db = TUI::read_string(
|
||||||
|
"Database Name to Import Into",
|
||||||
|
$selected_dumps[0] =~ s/\.sql$//r
|
||||||
|
);
|
||||||
|
die "No database name given" unless defined $db && length $db;
|
||||||
|
die "Invalid database name: $db" unless $db =~ /^[\w.:-]+$/;
|
||||||
|
die "Database $db already exists on mars"
|
||||||
|
if grep { $_ eq $db } Mars::db_list();
|
||||||
|
|
||||||
|
# mariadb-dump doesn't create the database, so create it here
|
||||||
|
Mars::db_create($db);
|
||||||
|
|
||||||
|
# point db.conf at the database
|
||||||
|
Util::rewrite_file( $local_db_conf, "database=", "database=$db\n" );
|
||||||
|
|
||||||
|
say "Importing $dump_file into $db...";
|
||||||
|
Util::run( join ' ', 'mariadb', "--defaults-file=$local_db_conf",
|
||||||
|
'<', Util::shell_quote($dump_file) );
|
||||||
|
},
|
||||||
|
|
||||||
'95. Delete Builds' => sub {
|
'95. Delete Builds' => sub {
|
||||||
|
|
||||||
# Delete old build files
|
# Delete old build files
|
||||||
|
|||||||
Reference in New Issue
Block a user