Merge lp:~teemperor/switchboard-plug-about/storage-dmesg-change into lp:~elementary-apps/switchboard-plug-about/trunk

Proposed by Raphael Isemann
Status: Rejected
Rejected by: kay van der Zander
Proposed branch: lp:~teemperor/switchboard-plug-about/storage-dmesg-change
Merge into: lp:~elementary-apps/switchboard-plug-about/trunk
Diff against target: 82 lines (+20/-19)
1 file modified
src/about-plug.vala (+20/-19)
To merge this branch: bzr merge lp:~teemperor/switchboard-plug-about/storage-dmesg-change
Reviewer Review Type Date Requested Status
Cody Garver (community) Needs Fixing
Review via email: mp+165822@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Raphael Isemann (teemperor) wrote :

Forgot to add a description:

dmesg to get the available storage without su-rights. Also i renamed the hdd_* variables to storage_* variables to fit the translation change we had lately.

Revision history for this message
Pim Vullers (pimvullers) wrote :

Looks good, this should fix part of bug #1182396. Cannot test it due to not reaching that point in code (fails when getting graphics details):
** (about:9990): CRITICAL **: file /tmp/portage/pantheon-base/switchboard-plug-about-9999/work/switchboard-plug-about-9999_build/src/about-plug.c: line 731: uncaught error: Failed to execute child process "lspci" (No such file or directory) (g-exec-error-quark, 8)

Revision history for this message
Cody Garver (codygarver) wrote :

Only solves half of the bug.

review: Needs Fixing

Unmerged revisions

99. By Raphael Isemann

Replace df for storage size with a workaround via dmesg

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/about-plug.vala'
2--- src/about-plug.vala 2013-05-18 10:48:46 +0000
3+++ src/about-plug.vala 2013-05-27 06:55:33 +0000
4@@ -27,7 +27,7 @@
5 private string processor;
6 private string memory;
7 private string graphics;
8- private string hdd;
9+ private string storage;
10
11 public AboutPlug () {
12 setup_info ();
13@@ -156,18 +156,19 @@
14 }
15
16 // Hard Drive
17- Process.spawn_command_line_sync ("df", out hdd);
18- Regex hdd_size_regex = /^\S+\s+(\d+)\s+\d+/;
19- uint64 hdd_size = 0;
20- foreach (string partition in hdd.split ("\n")) {
21- if (partition.has_prefix ("/dev/")) {
22- MatchInfo match_info;
23- if (hdd_size_regex.match (partition, 0, out match_info)) {
24- hdd_size += match_info.fetch (1).to_uint64 ();
25- }
26+ Process.spawn_command_line_sync ("dmesg", out storage);
27+ Regex storage_size_regex = new Regex ("""sd \d+:\d+:\d+:\d+:+ \[sd[a-z]"""
28+ + """[a-z]?\] (\d+) (\d+)-byte logical blocks""");
29+ uint64 storage_size = 0;
30+ foreach (string line in storage.split ("\n")) {
31+ MatchInfo match_info;
32+ if (storage_size_regex.match (line, 0, out match_info)) {
33+ //we multiply the block count with the size for the actual size
34+ storage_size += uint64.parse (match_info.fetch (1))
35+ * uint64.parse (match_info.fetch (2));
36 }
37 }
38- hdd = GLib.format_size (hdd_size * 1024, FormatSizeFlags.IEC_UNITS);
39+ storage = GLib.format_size (storage_size);
40 }
41
42 private string get_graphics_from_string(string graphics) {
43@@ -240,8 +241,8 @@
44 var graphics_label = new Gtk.Label (_("Graphics:"));
45 graphics_label.set_alignment (1, 0);
46
47- var hdd_label = new Gtk.Label (_("Storage:"));
48- hdd_label.set_alignment (1, 0);
49+ var storage_label = new Gtk.Label (_("Storage:"));
50+ storage_label.set_alignment (1, 0);
51
52 // Hardware info
53 var processor_info = new Gtk.Label (processor);
54@@ -261,10 +262,10 @@
55 graphics_info.set_selectable (true);
56 graphics_info.set_line_wrap (false);
57
58- var hdd_info = new Gtk.Label (hdd);
59- hdd_info.set_alignment (0, 0);
60- hdd_info.set_margin_left (6);
61- hdd_info.set_selectable (true);
62+ var storage_info = new Gtk.Label (storage);
63+ storage_info.set_alignment (0, 0);
64+ storage_info.set_margin_left (6);
65+ storage_info.set_selectable (true);
66
67 // Hardware grid
68 var hardware_grid = new Gtk.Grid ();
69@@ -273,11 +274,11 @@
70 hardware_grid.attach (processor_label, 0, 40, 100, 25);
71 hardware_grid.attach (memory_label, 0, 80, 100, 25);
72 hardware_grid.attach (graphics_label, 0, 120, 100, 25);
73- hardware_grid.attach (hdd_label, 0, 160, 100, 25);
74+ hardware_grid.attach (storage_label, 0, 160, 100, 25);
75 hardware_grid.attach (processor_info, 100, 40, 100, 25);
76 hardware_grid.attach (memory_info, 100, 80, 100, 25);
77 hardware_grid.attach (graphics_info, 100, 120, 100, 25);
78- hardware_grid.attach (hdd_info, 100, 160, 100, 25);
79+ hardware_grid.attach (storage_info, 100, 160, 100, 25);
80
81 // Help button
82 const string HELP_BUTTON_STYLESHEET = """

Subscribers

People subscribed via source and target branches

to all changes: