From bce91e106f4bffef8448a78d69dda0454de15446 Mon Sep 17 00:00:00 2001 From: espie Date: Mon, 24 Aug 2015 10:16:18 +0000 Subject: [PATCH] a bit of interactive mode. Just hooks into the main loop and can prompt for commands now, can't do anything serious yet. --- infrastructure/bin/dpb | 11 +++-- infrastructure/lib/DPB/Config.pm | 10 +++-- infrastructure/lib/DPB/Interactive.pm | 63 +++++++++++++++++++++++++++ infrastructure/lib/DPB/State.pm | 44 ++++++++++++++++++- 4 files changed, 120 insertions(+), 8 deletions(-) create mode 100644 infrastructure/lib/DPB/Interactive.pm diff --git a/infrastructure/bin/dpb b/infrastructure/bin/dpb index 6368fde9f63..5c84355e1da 100755 --- a/infrastructure/bin/dpb +++ b/infrastructure/bin/dpb @@ -1,7 +1,7 @@ #! /usr/bin/perl # ex:ts=8 sw=4: -# $OpenBSD: dpb,v 1.113 2015/07/15 14:30:26 espie Exp $ +# $OpenBSD: dpb,v 1.114 2015/08/24 10:16:18 espie Exp $ # # Copyright (c) 2010-2013 Marc Espie # @@ -74,7 +74,7 @@ DPB::Trace->setup(\%SIG); my $state = DPB::State->new('dpb'); $state->handle_options; -$state->{all} = 1; +$state->{all} = !$state->is_interactive; my $default_handling = sub { @@ -191,7 +191,9 @@ sub handle_non_waiting_jobs } DPB::Core->log_concurrency(time(), $state->{concurrent}); DPB::Core->wake_jobs; - $reporter->report($force_report); + if ($state->want_report) { + $reporter->report($force_report); + } } sub main_loop @@ -221,7 +223,8 @@ sub main_loop } } } - if (!$state->opt('q') || !$state->engine->recheck_errors) { + if ($state->may_ask_for_commands) { + } elsif (!$state->opt('q') || !$state->engine->recheck_errors) { last; } } diff --git a/infrastructure/lib/DPB/Config.pm b/infrastructure/lib/DPB/Config.pm index 16e89e04864..75f3d2efd72 100644 --- a/infrastructure/lib/DPB/Config.pm +++ b/infrastructure/lib/DPB/Config.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: Config.pm,v 1.59 2015/08/22 09:24:42 espie Exp $ +# $OpenBSD: Config.pm,v 1.60 2015/08/24 10:16:18 espie Exp $ # # Copyright (c) 2010-2013 Marc Espie # @@ -103,7 +103,11 @@ sub parse_command_line $state->usage("-$l takes an integer argument, not $o"); } } - $state->{interactive} = $state->opt('i'); + if ($state->opt('i')) { + require DPB::Interactive; + $state->{interactive} = DPB::Interactive->new; + } + $state->{chroot} = $state->opt('B'); $state->{base_user} = DPB::User->from_uid($<); if (!defined $state->{base_user}) { @@ -215,7 +219,7 @@ sub parse_command_line $state->{size_log} = "%f/build-stats/%a-size"; - my $k = $state->{interactive} ? "STARTUPI" : "STARTUP"; + my $k = $state->is_interactive ? "STARTUPI" : "STARTUP"; if ($state->define_present($k)) { $state->{startup_script} = $state->{subst}->value($k); } diff --git a/infrastructure/lib/DPB/Interactive.pm b/infrastructure/lib/DPB/Interactive.pm new file mode 100644 index 00000000000..6c99ed630db --- /dev/null +++ b/infrastructure/lib/DPB/Interactive.pm @@ -0,0 +1,63 @@ +# ex:ts=8 sw=4: +# $OpenBSD: Interactive.pm,v 1.1 2015/08/24 10:16:18 espie Exp $ +# +# Copyright (c) 2015 Marc Espie +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +use strict; +use warnings; + +package DPB::Interactive; + +sub new +{ + my $class = shift; + require Term::ReadLine; + bless { + rl => Term::ReadLine->new('dpb'), + prompt => '$ ', + want_report => 1}, $class; +} + + +sub is_interactive +{ + return 1; +} + +sub want_report +{ + my $self = shift; + + return $self->{want_report}; +} + +sub may_ask_for_commands +{ + my $self = shift; + return 0 if $self->{quitting}; + my $cmd = $self->{rl}->readline($self->{prompt}); + $self->{want_report} = 0; + if ($cmd =~ m/^(?:port|pkgpath)\s+(\S+)/) { + $self->{current_port} = $1; + $self->{prompt} = $self->{current_port}.'$ '; + } elsif ($cmd =~ m/^quit\b/i) { + $self->{quitting} = 1; + } else { + print STDERR "Unknown command\n"; + } + return 1; +} + +1; diff --git a/infrastructure/lib/DPB/State.pm b/infrastructure/lib/DPB/State.pm index 0e584939d85..1dc5808710a 100644 --- a/infrastructure/lib/DPB/State.pm +++ b/infrastructure/lib/DPB/State.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: State.pm,v 1.14 2015/07/28 09:20:54 espie Exp $ +# $OpenBSD: State.pm,v 1.15 2015/08/24 10:16:18 espie Exp $ # # Copyright (c) 2010-2013 Marc Espie # @@ -18,6 +18,29 @@ use strict; use warnings; +package DPB::InteractiveStub; + +sub new +{ + my $class = shift; + bless {}, $class; +} + +sub is_interactive +{ + return 0; +} + +sub want_report +{ + return 1; +} + +sub may_ask_for_commands +{ + return 0; +} + package DPB::State; our @ISA = qw(OpenBSD::State); @@ -48,10 +71,29 @@ sub init $self->{heuristics} = DPB::Heuristics->new($self); $self->{make} = $ENV{MAKE} || OpenBSD::Paths->make; $self->{starttime} = time(); + $self->{interactive} = DPB::InteractiveStub->new; return $self; } +sub is_interactive +{ + my $self = shift; + return $self->{interactive}->is_interactive; +} + +sub want_report +{ + my $self = shift; + return $self->{interactive}->want_report; +} + +sub may_ask_for_commands +{ + my $self = shift; + return $self->{interactive}->may_ask_for_commands; +} + sub startdate { my $self = shift;