From d4e6a6f66b7b3c797a1446816b8512d82c92278f Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sun, 16 May 2010 18:02:41 +0200 Subject: [PATCH] systemadm: show dependencies in the UI --- systemadm.vala | 138 ++++++++++++++++++++++++++++++++++------ systemd-interfaces.vala | 16 ++++- 2 files changed, 131 insertions(+), 23 deletions(-) diff --git a/systemadm.vala b/systemadm.vala index c5c90b34a..de2fa3ae9 100644 --- a/systemadm.vala +++ b/systemadm.vala @@ -47,6 +47,13 @@ public class RightLabel : Label { else set_text(text); } + + public void set_markup_or_na(string? text = null) { + if (text == null || text == "") + set_markup("n/a"); + else + set_markup(text); + } } public class MainWindow : Window { @@ -77,6 +84,7 @@ public class MainWindow : Window { private RightLabel unit_id_label; private RightLabel unit_aliases_label; + private RightLabel unit_dependency_label; private RightLabel unit_description_label; private RightLabel unit_load_state_label; private RightLabel unit_active_state_label; @@ -189,6 +197,7 @@ public class MainWindow : Window { unit_id_label = new RightLabel(); unit_aliases_label = new RightLabel(); + unit_dependency_label = new RightLabel(); unit_description_label = new RightLabel(); unit_load_state_label = new RightLabel(); unit_active_state_label = new RightLabel(); @@ -204,6 +213,10 @@ public class MainWindow : Window { job_state_label = new RightLabel(); job_type_label = new RightLabel(); + unit_dependency_label.set_track_visited_links(false); + unit_dependency_label.set_selectable(false); + unit_dependency_label.activate_link += on_activate_link; + Table unit_table = new Table(8, 6, false); unit_table.set_row_spacings(6); unit_table.set_border_width(0); @@ -220,27 +233,29 @@ public class MainWindow : Window { unit_table.attach(unit_aliases_label, 1, 6, 1, 2, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0); unit_table.attach(new LeftLabel("Description:"), 0, 1, 2, 3, AttachOptions.FILL, AttachOptions.FILL, 0, 0); unit_table.attach(unit_description_label, 1, 6, 2, 3, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0); - unit_table.attach(new LeftLabel("Fragment Path:"), 0, 1, 3, 4, AttachOptions.FILL, AttachOptions.FILL, 0, 0); - unit_table.attach(unit_fragment_path_label, 1, 6, 3, 4, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0); - unit_table.attach(new LeftLabel("Control Group:"), 0, 1, 4, 5, AttachOptions.FILL, AttachOptions.FILL, 0, 0); - unit_table.attach(unit_cgroup_label, 1, 6, 4, 5, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0); - - unit_table.attach(new LeftLabel("Load State:"), 0, 1, 5, 6, AttachOptions.FILL, AttachOptions.FILL, 0, 0); - unit_table.attach(unit_load_state_label, 1, 2, 5, 6, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0); - unit_table.attach(new LeftLabel("Active State:"), 0, 1, 6, 7, AttachOptions.FILL, AttachOptions.FILL, 0, 0); - unit_table.attach(unit_active_state_label, 1, 2, 6, 7, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0); - unit_table.attach(new LeftLabel("Unit State:"), 0, 1, 7, 8, AttachOptions.FILL, AttachOptions.FILL, 0, 0); - unit_table.attach(unit_sub_state_label, 1, 2, 7, 8, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0); - - unit_table.attach(new LeftLabel("Active Enter Timestamp:"), 2, 3, 6, 7, AttachOptions.FILL, AttachOptions.FILL, 0, 0); - unit_table.attach(unit_active_enter_timestamp_label, 3, 4, 6, 7, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0); - unit_table.attach(new LeftLabel("Active Exit Timestamp:"), 2, 3, 7, 8, AttachOptions.FILL, AttachOptions.FILL, 0, 0); - unit_table.attach(unit_active_exit_timestamp_label, 3, 4, 7, 8, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0); - - unit_table.attach(new LeftLabel("Can Start/Stop:"), 4, 5, 6, 7, AttachOptions.FILL, AttachOptions.FILL, 0, 0); - unit_table.attach(unit_can_start_label, 5, 6, 6, 7, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0); - unit_table.attach(new LeftLabel("Can Reload:"), 4, 5, 7, 8, AttachOptions.FILL, AttachOptions.FILL, 0, 0); - unit_table.attach(unit_can_reload_label, 5, 6, 7, 8, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0); + unit_table.attach(new LeftLabel("Dependencies:"), 0, 1, 3, 4, AttachOptions.FILL, AttachOptions.FILL, 0, 0); + unit_table.attach(unit_dependency_label, 1, 6, 3, 4, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0); + unit_table.attach(new LeftLabel("Fragment Path:"), 0, 1, 4, 5, AttachOptions.FILL, AttachOptions.FILL, 0, 0); + unit_table.attach(unit_fragment_path_label, 1, 6, 4, 5, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0); + unit_table.attach(new LeftLabel("Control Group:"), 0, 1, 5, 6, AttachOptions.FILL, AttachOptions.FILL, 0, 0); + unit_table.attach(unit_cgroup_label, 1, 6, 5, 6, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0); + + unit_table.attach(new LeftLabel("Load State:"), 0, 1, 6, 7, AttachOptions.FILL, AttachOptions.FILL, 0, 0); + unit_table.attach(unit_load_state_label, 1, 2, 6, 7, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0); + unit_table.attach(new LeftLabel("Active State:"), 0, 1, 7, 8, AttachOptions.FILL, AttachOptions.FILL, 0, 0); + unit_table.attach(unit_active_state_label, 1, 2, 7, 8, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0); + unit_table.attach(new LeftLabel("Unit State:"), 0, 1, 8, 9, AttachOptions.FILL, AttachOptions.FILL, 0, 0); + unit_table.attach(unit_sub_state_label, 1, 2, 8, 9, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0); + + unit_table.attach(new LeftLabel("Active Enter Timestamp:"), 2, 3, 7, 8, AttachOptions.FILL, AttachOptions.FILL, 0, 0); + unit_table.attach(unit_active_enter_timestamp_label, 3, 4, 7, 8, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0); + unit_table.attach(new LeftLabel("Active Exit Timestamp:"), 2, 3, 8, 9, AttachOptions.FILL, AttachOptions.FILL, 0, 0); + unit_table.attach(unit_active_exit_timestamp_label, 3, 4, 8, 9, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0); + + unit_table.attach(new LeftLabel("Can Start/Stop:"), 4, 5, 7, 8, AttachOptions.FILL, AttachOptions.FILL, 0, 0); + unit_table.attach(unit_can_start_label, 5, 6, 7, 8, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0); + unit_table.attach(new LeftLabel("Can Reload:"), 4, 5, 8, 9, AttachOptions.FILL, AttachOptions.FILL, 0, 0); + unit_table.attach(unit_can_reload_label, 5, 6, 8, 9, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0); job_table.attach(new LeftLabel("Id:"), 0, 1, 0, 1, AttachOptions.FILL, AttachOptions.FILL, 0, 0); job_table.attach(job_id_label, 1, 2, 0, 1, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0); @@ -390,6 +405,7 @@ public class MainWindow : Window { unit_id_label.set_text_or_na(); unit_aliases_label.set_text_or_na(); unit_description_label.set_text_or_na(); + unit_description_label.set_text_or_na(); unit_load_state_label.set_text_or_na(); unit_active_state_label.set_text_or_na(); unit_sub_state_label.set_text_or_na(); @@ -401,6 +417,30 @@ public class MainWindow : Window { unit_cgroup_label.set_text_or_na(); } + public string make_dependency_string(string? prefix, string word, string[] dependencies) { + bool first = true; + string r; + + if (prefix == null) + r = ""; + else + r = prefix; + + foreach (string i in dependencies) { + if (r != "") + r += first ? "\n" : ","; + + if (first) { + r += word; + first = false; + } + + r += " " + i + ""; + } + + return r; + } + public void show_unit(Unit unit) { current_unit_id = unit.id; @@ -418,6 +458,44 @@ public class MainWindow : Window { } unit_aliases_label.set_text_or_na(a); + + string[] + requires = unit.requires, + requires_overridable = unit.requires_overridable, + requisite = unit.requisite, + requisite_overridable = unit.requisite_overridable, + wants = unit.wants, + required_by = unit.required_by, + required_by_overridable = unit.required_by_overridable, + wanted_by = unit.wanted_by, + conflicts = unit.conflicts, + before = unit.before, + after = unit.after; + + unit_dependency_label.set_markup_or_na( + make_dependency_string( + make_dependency_string( + make_dependency_string( + make_dependency_string( + make_dependency_string( + make_dependency_string( + make_dependency_string( + make_dependency_string( + make_dependency_string( + make_dependency_string( + make_dependency_string(null, + "requires", requires), + "overridable requires", requires_overridable), + "requisite", requisite), + "overridable requisite", requisite_overridable), + "wants", wants), + "conflicts", conflicts), + "required by", required_by), + "overridable required by", required_by_overridable), + "wanted by", wanted_by), + "after", after), + "before", before)); + unit_description_label.set_text_or_na(unit.description); unit_load_state_label.set_text_or_na(unit.load_state); unit_active_state_label.set_text_or_na(unit.active_state); @@ -816,6 +894,24 @@ public class MainWindow : Window { unit_load_button.set_sensitive(unit_load_entry.get_text() != ""); } + public bool on_activate_link(string uri) { + + try { + string path = manager.get_unit(uri); + + Unit u = bus.get_object( + "org.freedesktop.systemd1", + path, + "org.freedesktop.systemd1.Unit") as Unit; + + show_unit(u); + } catch (DBus.Error e) { + show_error(e.message); + } + + return true; + } + public void show_error(string e) { var m = new MessageDialog(this, DialogFlags.DESTROY_WITH_PARENT, diff --git a/systemd-interfaces.vala b/systemd-interfaces.vala index 72655d635..7282bf3dd 100644 --- a/systemd-interfaces.vala +++ b/systemd-interfaces.vala @@ -83,6 +83,17 @@ public interface Unit : DBus.Object { public abstract string id { owned get; } public abstract string[] names { owned get; } + public abstract string[] requires { owned get; } + public abstract string[] requires_overridable { owned get; } + public abstract string[] requisite { owned get; } + public abstract string[] requisite_overridable { owned get; } + public abstract string[] wants { owned get; } + public abstract string[] required_by { owned get; } + public abstract string[] required_by_overridable { owned get; } + public abstract string[] wanted_by { owned get; } + public abstract string[] conflicts { owned get; } + public abstract string[] before { owned get; } + public abstract string[] after { owned get; } public abstract string description { owned get; } public abstract string load_state { owned get; } public abstract string active_state { owned get; } @@ -94,10 +105,11 @@ public interface Unit : DBus.Object { public abstract uint64 inactive_enter_timestamp { owned get; } public abstract bool can_start { owned get; } public abstract bool can_reload { owned get; } - public abstract JobLink job { owned get; /* FIXME: this setter is a temporary fix to make valac not segfault */ set; } + public abstract JobLink job { owned get; } public abstract bool recursive_stop { owned get; } public abstract bool stop_when_unneeded { owned get; } public abstract string default_control_group { owned get; } + public abstract string[] control_groups { owned get; } public abstract ObjectPath start(string mode) throws DBus.Error; public abstract ObjectPath stop(string mode) throws DBus.Error; @@ -117,7 +129,7 @@ public interface Job : DBus.Object { public abstract uint32 id { owned get; } public abstract string state { owned get; } public abstract string job_type { owned get; } - public abstract UnitLink unit { owned get; /* FIXME: this setter is a temporary fix to make valac not segfault */ set; } + public abstract UnitLink unit { owned get; } public abstract void cancel() throws DBus.Error; -- 2.30.2