[stdout_pipe] Implement functional stdout sync

Implement functional real-time async function that livestreams stdout
buffer of process to Gtk TextView
main
Joaquin 3 years ago
parent b2d995926a
commit 6402ea4abc
Signed by: puly
GPG Key ID: 9E9299CD96C65EC6
  1. 2
      Makefile
  2. 81
      Window.vala
  3. BIN
      nostalgia

@ -1,5 +1,5 @@
nostalgia: Main.vala Window.vala HeaderBar.vala Nostalgia.vala nostalgia: Main.vala Window.vala HeaderBar.vala Nostalgia.vala
valac --pkg libnotify --pkg gtk+-3.0 Main.vala Window.vala HeaderBar.vala Nostalgia.vala -o nostalgia valac --pkg libnotify --pkg gtk+-3.0 --pkg gio-2.0 Main.vala Window.vala HeaderBar.vala Nostalgia.vala -o nostalgia
install: nostalgia nostalgia-launcher.desktop install: nostalgia nostalgia-launcher.desktop
cp ./nostalgia /usr/bin/ cp ./nostalgia /usr/bin/

@ -173,11 +173,21 @@ so please be patient and let us get your system back and running"), true, false,
string isft = crloc1.get_filename() + "/nostalgia.file: empty "; string isft = crloc1.get_filename() + "/nostalgia.file: empty ";
print(isfile); print(isfile);
print(isft); print(isft);
var lbl = new Gtk.TextView();
lbl.set_wrap_mode (Gtk.WrapMode.WORD);
lbl.set_monospace(true);
var lblScroll = new Gtk.ScrolledWindow(null, null);
lblScroll.add(lbl);
lblScroll.set_max_content_height(100);
progresscr.pack_start(lblScroll);
//The length will never be the same if the file is not found //The length will never be the same if the file is not found
if(isfile.char_count() != isft.char_count()){ if(isfile.char_count() != isft.char_count()){
print("\n root backup \n"); print("\n root backup \n");
string testx; string testx;
Process.spawn_command_line_sync("bash command", out testx); //Process.spawn_command_line_sync("bash command", out testx);
progresscr.pack_start(new Gtk.Label(testx)); progresscr.pack_start(new Gtk.Label(testx));
//print(testx); //print(testx);
progresscr.pack_start(new Gtk.Label("This seems to be your first nostalgia backup on this harddrive, so it will take a while"), false, false, 10); progresscr.pack_start(new Gtk.Label("This seems to be your first nostalgia backup on this harddrive, so it will take a while"), false, false, 10);
@ -188,34 +198,34 @@ so please be patient and let us get your system back and running"), true, false,
int otcr; int otcr;
int dum; int dum;
bool lop=true; bool lop=true;
//Process.spawn_async_with_pipes(loc, {"rsync", "-a", "~/debian", "~/test", "--no-i-r"}, spawn_env1, SpawnFlags.SEARCH_PATH | SpawnFlags.DO_NOT_REAP_CHILD, null, out rpid, out dum, out otcr, out dum);
Process.spawn_async_with_pipes(loc, {"bash", "install"}, spawn_env1, SpawnFlags.SEARCH_PATH | SpawnFlags.DO_NOT_REAP_CHILD, null, out rpid, out dum, out otcr, out dum); string[] backup_command = {"/usr/bin/rsync", "-av", "/home/ioachim/Music", "/home/ioachim/Music2", "--no-i-r", "--info=progress2", null};
IOChannel outputcr = new IOChannel.unix_new(otcr);
outputcr.add_watch(IOCondition.IN | IOCondition.HUP, (channel, condition) => { var ChildProcessBackup = new Subprocess.newv(backup_command, SubprocessFlags.STDOUT_PIPE);
return process_line(channel, condition, "stdout", out laoutput, out upol);
}); ChildProcessBackup.wait_check_async.begin(null, (obj, res) => {
bool should_stop = false; try{
var ol = new Gtk.Label(laoutput); ChildProcessBackup.wait_check_async.end(res);
ChildWatch.add(rpid, (pid, status) => { print("\n\n-------SUCCESFULL------\n\n");
Process.close_pid(rpid);
print("hihi"); ssnap = false;
ssnap=false; createstack.set_visible_child(cr1);
createstack.set_visible_child(cr1); Notify.init("Nostalgia");
lop=false; var notification = new Notify.Notification("Nostalgia", "Your snapshot is ready", "deja-dup");
Notify.init("Nostalgia"); notification.set_timeout(0);
var notification = new Notify.Notification("Nostalgia", "Your snapshot is ready", "deja-dup"); notification.show();
notification.set_timeout(0);
notification.show();
should_stop = true; }catch(Error err){
progresscr.remove(ol); print("\n\n------ERROR!!!------\n%s\n\n", err.message);
}); }
progresscr.pack_start(ol, true, true, 10);
show_all();
Timeout.add(750, () => {
ol.set_text(laoutput);
show_all();
return should_stop ? Source.REMOVE : Source.CONTINUE;
}); });
var OutputPipeBackup = ChildProcessBackup.get_stdout_pipe();
update_label_from_istream.begin(OutputPipeBackup, lbl);
} }
} }
}); });
@ -231,6 +241,19 @@ so please be patient and let us get your system back and running"), true, false,
set_resizable(false); set_resizable(false);
show_all(); show_all();
print("Hey, thanks for choosing nostalgia! \n"); print("Hey, thanks for choosing nostalgia! \n");
print("If you're looking at the debug output most probably you're having some trouble with this program, so feel free to email me at konicksdev@gmail.com and I'll see if I can help \n"); print("If you're looking at the debug output most probably you're having some trouble with this program, so feel free to email me at [ioachim.radu@protonmail.com] and I'll see if I can help \n");
} }
} }
async void update_label_from_istream (InputStream istream, Gtk.TextView label) {
try {
var dis = new DataInputStream (istream);
var line = yield dis.read_line_async ();
while (line != null) {
label.buffer.text += line + "\n";
line = yield dis.read_line_async ();
}
} catch (Error err) {}
}

Binary file not shown.
Loading…
Cancel
Save