[kdesrc-build/make_it_mojo] /: mojo: Add --launch-browser cmdline option.

Michael Pyne null at kde.org
Sat Apr 14 04:44:37 UTC 2018


Git commit c3d82f75916efed5bbb3f895e40545d31d9bf281 by Michael Pyne.
Committed on 14/04/2018 at 04:34.
Pushed by mpyne into branch 'make_it_mojo'.

mojo: Add --launch-browser cmdline option.

Launches the configured default browser to show the status viewer web
page recently introduced.

M  +11   -0    doc/index.docbook
M  +29   -0    doc/man-kdesrc-build.1.docbook
M  +25   -0    modules/ksb/Application.pm

https://commits.kde.org/kdesrc-build/c3d82f75916efed5bbb3f895e40545d31d9bf281

diff --git a/doc/index.docbook b/doc/index.docbook
index 0182369..e005630 100644
--- a/doc/index.docbook
+++ b/doc/index.docbook
@@ -3271,6 +3271,17 @@ kdepim: master
 </listitem>
 </varlistentry>
 
+<varlistentry id="cmdline-launch-browser">
+<term><parameter>--launch-browser</parameter></term>
+<listitem><para>
+    When &kdesrc-build; is already running (that is, in a separate terminal
+    session), you can use this option to have &kdesrc-build; launch a web
+    browser that will show a web page showing the status of the build process.
+    This does not require Internet access, and can be more convenient than the
+    command-line output.
+</para></listitem>
+</varlistentry>
+
 <varlistentry id="cmdline-no-rebuild-on-fail">
 <term><parameter>--no-rebuild-on-fail</parameter></term>
 <listitem><para>
diff --git a/doc/man-kdesrc-build.1.docbook b/doc/man-kdesrc-build.1.docbook
index 539b54a..0d0602f 100644
--- a/doc/man-kdesrc-build.1.docbook
+++ b/doc/man-kdesrc-build.1.docbook
@@ -43,6 +43,18 @@
 <arg rep="repeat"><replaceable>OPTIONS</replaceable></arg>
 <arg rep="repeat"><replaceable>Module name | Module set name</replaceable></arg>
 </cmdsynopsis>
+
+<cmdsynopsis>
+<command>kdesrc-build</command>
+<arg choice='plain'>--query</arg>
+<arg choice='req'><replaceable>VALUE TO QUERY</replaceable></arg>
+<arg rep="repeat"><replaceable>Module name</replaceable></arg>
+</cmdsynopsis>
+
+<cmdsynopsis>
+<command>kdesrc-build</command>
+<arg choice='plain'>--launch-browser</arg>
+</cmdsynopsis>
 </refsynopsisdiv>
 
 <refsect1>
@@ -568,6 +580,23 @@ combining short options into one at this point. (E.g. running
 </listitem>
 </varlistentry>
 
+<varlistentry>
+<term>
+<option>--launch-browser</option>
+</term>
+
+<listitem>
+<para>
+    When <command>kdesrc-build</command> is already running (in a separate
+    terminal), you can run this command to run a Web browser to show a web page
+    that will track the status of the running kdesrc-build session.  The
+    browser is opened using the <command>xdg-open</command> so this requires
+    your environment to be configured to associate your preferred browser to
+    web pages.
+</para>
+</listitem>
+</varlistentry>
+
 <varlistentry>
 <term>
 <option>--run=<replaceable>foo</replaceable></option>
diff --git a/modules/ksb/Application.pm b/modules/ksb/Application.pm
index 736f408..8745c31 100644
--- a/modules/ksb/Application.pm
+++ b/modules/ksb/Application.pm
@@ -24,6 +24,7 @@ use ksb::DependencyResolver 0.20;
 use ksb::Updater::Git;
 use ksb::Version qw(scriptVersion);
 
+use Mojo::File;
 use Mojo::IOLoop;
 use Mojo::JSON qw(encode_json);
 use Mojo::Message::Request;
@@ -294,6 +295,7 @@ DONE
         'rc-file=s', 'prefix=s', 'niceness|nice:10', 'ignore-modules=s{,}',
         'print-modules', 'pretend|dry-run|p', 'refresh-build',
         'query=s', 'start-program|run=s{,}',
+        'launch-browser',
         'revision=i', 'resume-from=s', 'resume-after=s',
         'rebuild-failures', 'resume', 'stop-on-failure',
         'stop-after=s', 'stop-before=s', 'set-module-option-value=s',
@@ -359,6 +361,10 @@ sub generateModuleList
     my %ignoredSelectors;
     @ignoredSelectors{@{$cmdlineGlobalOptions->{'ignore-modules'}}} = undef;
 
+    if (exists $cmdlineGlobalOptions->{'launch-browser'}) {
+        _launchStatusViewerBrowser(); # does not return
+    }
+
     my @startProgramAndArgs = @{$cmdlineGlobalOptions->{'start-program'}};
     delete @{$cmdlineGlobalOptions}{qw/ignore-modules start-program/};
 
@@ -2737,6 +2743,25 @@ sub _reachableModuleLogs
     return keys %tempHash;
 }
 
+# Runs xdg-open to the URL at $XDG_RUNTIME_DIR/kdesrc-build-status-server, if
+# that file exists and is readable.  Otherwise lets the user know there was an
+# error.  Either way this function always exits the process immediately.
+sub _launchStatusViewerBrowser
+{
+    my $run = $ENV{XDG_RUNTIME_DIR} // '/tmp';
+    my $file = "$run/kdesrc-build-status-server";
+    my $url = eval { Mojo::File->new($file)->slurp };
+
+    if ($url) {
+        exec { 'xdg-open' } 'xdg-open', $url or die
+            "Failed to launch browser, couldn't run xdg-open: $!";
+    }
+    else {
+        say "Unable to launch browser for the status server, couldn't find right URL";
+        exit 1;
+    }
+}
+
 # Installs the given subroutine as a signal handler for a set of signals which
 # could kill the program.
 #


More information about the kde-doc-english mailing list