[med-svn] [SCM] aghermann branch, master, updated. 4f7a3b774136ffffbaf9b05d90bd568347bc5461
Andrei Zavada
johnhommer at gmail.com
Fri Nov 16 00:50:47 UTC 2012
The following commit has been merged in the master branch:
commit ca0a07a9e160a1a977e5ca02b362474ab221882e
Author: Andrei Zavada <johnhommer at gmail.com>
Date: Wed Nov 7 01:37:34 2012 +0200
apply some bash-fu to control downloading process properly
diff --git a/data/Makefile.am b/data/Makefile.am
index a2968ba..162009e 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -8,7 +8,8 @@ ui_DATA := \
aghermann.png \
edfhed.glade \
aghermann.gresource \
- idle-bg.svg
+ idle-bg.svg \
+ experiment-dl.sh
CLEANFILES := \
aghermann.desktop edfhed-gtk.desktop
@@ -20,7 +21,8 @@ EXTRA_DIST := \
aghermann.gresource.xml \
session-chooser.glade main.glade dialogs.glade \
sf.glade mf.glade edfhed.glade \
- idle-bg.svg equations1.png equation-uc.png
+ idle-bg.svg equations1.png equation-uc.png \
+ experiment-dl.sh
GRESOURCES := \
session-chooser.glade main.glade dialogs.glade \
diff --git a/data/experiment-dl.sh b/data/experiment-dl.sh
new file mode 100644
index 0000000..b79a748
--- /dev/null
+++ b/data/experiment-dl.sh
@@ -0,0 +1,21 @@
+#!/bin/sh
+set -e
+URL="http://johnhommer.com/academic/code/aghermann/Experiment.tar.bz2"
+TARBALL=Experiment.tar.bz2
+echo "
+Now downloading sample data.
+Press Ctl-C to interrupt.
+"
+function kill_wget
+{
+ kill $!
+}
+trap kill_wget SIGTERM SIGINT
+wget -c $URL &
+wait %1
+
+tar xjf $TARBALL
+rm -f $TARBALL
+
+echo "Sample data set downloaded and unpacked"
+read -p "Press <Enter> to close this window..."
diff --git a/src/ui/mw/mw-splash.cc b/src/ui/mw/mw-splash.cc
index 648410b..ae8ee16 100644
--- a/src/ui/mw/mw-splash.cc
+++ b/src/ui/mw/mw-splash.cc
@@ -34,18 +34,20 @@ bDownload_clicked_cb( GtkButton*, gpointer userdata)
}
void
-download_process_child_exited_cb( VteTerminal*, gpointer userdata)
+download_process_child_exited_cb( VteTerminal *terminal, gpointer userdata)
{
auto& ED = *(aghui::SExpDesignUI*)userdata;
- if ( ED.dl_watch_busyblock ) {
- delete ED.dl_watch_busyblock;
- ED.dl_watch_busyblock = nullptr;
- ED.ED->scan_tree( bind (&aghui::SExpDesignUI::sb_main_progress_indicator, &ED,
- placeholders::_1, placeholders::_2, placeholders::_3));
- ED.populate( false);
- } else
- FAFA;
- //throw runtime_error ("Who's here?");
+ ED.set_wMainWindow_interactive( true, true);
+ int exit_status = vte_terminal_get_child_exit_status( terminal);
+ if ( exit_status != 0 )
+ aghui::pop_ok_message(
+ ED.wMainWindow,
+ "Download failed",
+ "Exit status %d. Try again next time.", exit_status);
+ ED.dl_pid = -1;
+ ED.ED->scan_tree( bind (&aghui::SExpDesignUI::sb_main_progress_indicator, &ED,
+ placeholders::_1, placeholders::_2, placeholders::_3));
+ ED.populate( false);
}
} // extern "C"
@@ -109,55 +111,44 @@ try_download()
gtk_container_foreach( (GtkContainer*)cMeasurements,
(GtkCallback) gtk_widget_destroy,
NULL);
- const char
- *url = "http://johnhommer.com/academic/code/aghermann/Experiment.tar.bz2",
- *archive_file = "Experiment.tar.bz2";
- snprintf_buf( " wget -c \"%s\" && "
- " tar xjf \"%s\" && "
- " rm -f \"%s\" && "
- " echo \"Sample data set downloaded and unpacked\" && "
- " read -p \"Press <Enter> to close this window...\"",
- url, archive_file, archive_file);
-
auto tTerm = (VteTerminal*)vte_terminal_new();
- // (dl_watch_busyblock = new aghui::SBusyBlock (wMainWindow),
- dl_watch_busyblock = nullptr;
g_signal_connect( tTerm, "child-exited",
(GCallback)download_process_child_exited_cb,
this);
gtk_box_pack_start( (GtkBox*)cMeasurements,
(GtkWidget*)tTerm,
TRUE, FALSE, 0);
+ set_wMainWindow_interactive( false, true);
// punch a hole for VteTerminal for any user ^C
- gtk_widget_set_sensitive( (GtkWidget*)tTerm, TRUE);
+ gtk_widget_set_sensitive( (GtkWidget*)cMeasurements, TRUE);
gtk_widget_show_all( (GtkWidget*)cMeasurements);
- GPid pid;
+ gtk_widget_grab_focus( (GtkWidget*)tTerm);
GError *Error = NULL;
- char *argv[] = {
- vte_get_user_shell(),
+ const char *argv[] = {
+ "/bin/sh", // vte_get_user_shell(),
"-c",
- __buf__,
+ "source " PACKAGE_DATADIR "/" PACKAGE "/experiment-dl.sh",
NULL
};
vte_terminal_fork_command_full(
tTerm,
VTE_PTY_DEFAULT,
ED->session_dir().c_str(),
- argv,
+ const_cast<char**> (argv),
NULL, // char **envv,
(GSpawnFlags)G_SPAWN_DO_NOT_REAP_CHILD, // GSpawnFlags spawn_flags,
NULL, // GSpawnChildSetupFunc child_setup,
NULL, // gpointer child_setup_data,
- &pid,
+ &dl_pid,
&Error); // GError **error);
if ( Error ) {
aghui::pop_ok_message(
wMainWindow,
- "Failed to download dataset",
+ "Error",
"%s\n", Error->message);
return 1;
} else {
- vte_terminal_watch_child( tTerm, pid);
+ vte_terminal_watch_child( tTerm, dl_pid);
return 0;
}
}
diff --git a/src/ui/mw/mw.cc b/src/ui/mw/mw.cc
index 09fdc54..ef930b0 100644
--- a/src/ui/mw/mw.cc
+++ b/src/ui/mw/mw.cc
@@ -13,6 +13,7 @@
#include <cstring>
#include <ctime>
#include <functional>
+#include <signal.h>
#include "common/config-validate.hh"
#include "libsigfile/page-metrics-base.hh"
@@ -116,6 +117,7 @@ SExpDesignUI (aghui::SSessionChooser *parent,
draw_nremrem_cycles (true),
finalize_ui (false),
suppress_redraw (false),
+ dl_pid (-1),
close_this_SF_now (nullptr),
display_profile_type (sigfile::TMetricType::Psd),
operating_range_from (2.),
@@ -352,6 +354,10 @@ figure_binsize_item()
aghui::SExpDesignUI::
~SExpDesignUI ()
{
+ if ( dl_pid > 0 ) {
+ fprintf( stderr, "killing dl process %d\n", dl_pid);
+ kill( dl_pid, SIGTERM);
+ }
save_settings();
save_artifact_detection_profiles();
delete ED;
diff --git a/src/ui/mw/mw.hh b/src/ui/mw/mw.hh
index 3ec9658..2e88284 100644
--- a/src/ui/mw/mw.hh
+++ b/src/ui/mw/mw.hh
@@ -166,7 +166,7 @@ class SExpDesignUI
void update_subject_details_interactively( agh::CSubject&);
void show_empty_experiment_blurb();
int try_download();
- aghui::SBusyBlock *dl_watch_busyblock;
+ GPid dl_pid;
// collected ED info
// ED strings (channels, sessions, etc)
--
Sleep experiment manager
More information about the debian-med-commit
mailing list