[Sugar-devel] [PATCH sugar] Control Panel: making about my computer section hardware independent, OLPC #11232

Simon Schampijer simon at schampijer.de
Fri Oct 7 05:13:15 EDT 2011


'/ofw' is not used anymore on the XO, '/proc/device-tree' is used now
instead. Instead of just adjusting for that change we took the
chance to make the section hardware independent. As the firmware
version we display the bios version if available on non XO
hardware. As ethtool has become a depedency of Sugar we can now
display the wireless firmware as well on all hardwares.

The serial number is often only readable by root on non-XO
hardware. If the serial number can not be found on an XO we hide
that part of the section.

The patch has been tested on XO 1, 1.5, 1.75 and on a Thinkpad T61.

Signed-off-by: Simon Schampijer <simon at laptop.org>
---
 extensions/cpsection/aboutcomputer/model.py |   12 +++--
 extensions/cpsection/aboutcomputer/view.py  |   70 +++++++++++++-------------
 2 files changed, 42 insertions(+), 40 deletions(-)

diff --git a/extensions/cpsection/aboutcomputer/model.py b/extensions/cpsection/aboutcomputer/model.py
index a02eee6..5735ad0 100644
--- a/extensions/cpsection/aboutcomputer/model.py
+++ b/extensions/cpsection/aboutcomputer/model.py
@@ -17,7 +17,6 @@
 
 import os
 import logging
-import re
 import subprocess
 from gettext import gettext as _
 import errno
@@ -35,6 +34,7 @@ _NM_DEVICE_TYPE_WIFI = 2
 
 _OFW_TREE = '/ofw'
 _PROC_TREE = '/proc/device-tree'
+_SYS_TREE = '/sys/class/dmi/id'
 _SN = 'serial-number'
 _MODEL = 'openprom/model'
 
@@ -58,6 +58,8 @@ def get_serial_number():
         serial_no = _read_file(os.path.join(_OFW_TREE, _SN))
     elif os.path.exists(os.path.join(_PROC_TREE, _SN)):
         serial_no = _read_file(os.path.join(_PROC_TREE, _SN))
+    else:
+        return None
     if serial_no is None:
         serial_no = _not_available
     return serial_no
@@ -100,14 +102,14 @@ def get_firmware_number():
     firmware_no = None
     if os.path.exists(os.path.join(_OFW_TREE, _MODEL)):
         firmware_no = _read_file(os.path.join(_OFW_TREE, _MODEL))
+        firmware_no = firmware_no[6:13]
     elif os.path.exists(os.path.join(_PROC_TREE, _MODEL)):
         firmware_no = _read_file(os.path.join(_PROC_TREE, _MODEL))
+        firmware_no = firmware_no[6:13]
+    elif os.path.exists(os.path.join(_SYS_TREE, 'bios_version')):
+        firmware_no = _read_file(os.path.join(_SYS_TREE, 'bios_version'))
     if firmware_no is None:
         firmware_no = _not_available
-    else:
-        firmware_no = re.split(' +', firmware_no)
-        if len(firmware_no) == 3:
-            firmware_no = firmware_no[1]
     return firmware_no
 
 
diff --git a/extensions/cpsection/aboutcomputer/view.py b/extensions/cpsection/aboutcomputer/view.py
index e5f2f32..a1af4c1 100644
--- a/extensions/cpsection/aboutcomputer/view.py
+++ b/extensions/cpsection/aboutcomputer/view.py
@@ -16,7 +16,6 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 
-import os
 from gettext import gettext as _
 
 import gtk
@@ -47,13 +46,15 @@ class AboutComputer(SectionView):
         scrollwindow.add_with_viewport(self._vbox)
         self._vbox.show()
 
-        if os.path.exists('/ofw'):
-            self._setup_identity()
+        self._setup_identity()
 
         self._setup_software()
         self._setup_copyright()
 
     def _setup_identity(self):
+        serial_number = self._model.get_serial_number()
+        if serial_number is None:
+            return
         separator_identity = gtk.HSeparator()
         self._vbox.pack_start(separator_identity, expand=False)
         separator_identity.show()
@@ -74,7 +75,7 @@ class AboutComputer(SectionView):
         box_identity.pack_start(label_serial, expand=False)
         self._group.add_widget(label_serial)
         label_serial.show()
-        label_serial_no = gtk.Label(self._model.get_serial_number())
+        label_serial_no = gtk.Label(serial_number)
         label_serial_no.set_alignment(0, 0)
         box_identity.pack_start(label_serial_no, expand=False)
         label_serial_no.show()
@@ -127,37 +128,36 @@ class AboutComputer(SectionView):
         box_software.pack_start(box_sugar, expand=False)
         box_sugar.show()
 
-        if os.path.exists('/ofw'):
-            box_firmware = gtk.HBox(spacing=style.DEFAULT_SPACING)
-            label_firmware = gtk.Label(_('Firmware:'))
-            label_firmware.set_alignment(1, 0)
-            label_firmware.modify_fg(gtk.STATE_NORMAL,
-                                  style.COLOR_SELECTION_GREY.get_gdk_color())
-            box_firmware.pack_start(label_firmware, expand=False)
-            self._group.add_widget(label_firmware)
-            label_firmware.show()
-            label_firmware_no = gtk.Label(self._model.get_firmware_number())
-            label_firmware_no.set_alignment(0, 0)
-            box_firmware.pack_start(label_firmware_no, expand=False)
-            label_firmware_no.show()
-            box_software.pack_start(box_firmware, expand=False)
-            box_firmware.show()
-
-            box_wireless_fw = gtk.HBox(spacing=style.DEFAULT_SPACING)
-            label_wireless_fw = gtk.Label(_('Wireless Firmware:'))
-            label_wireless_fw.set_alignment(1, 0)
-            label_wireless_fw.modify_fg(gtk.STATE_NORMAL,
-                                  style.COLOR_SELECTION_GREY.get_gdk_color())
-            box_wireless_fw.pack_start(label_wireless_fw, expand=False)
-            self._group.add_widget(label_wireless_fw)
-            label_wireless_fw.show()
-            wireless_fw_no = self._model.get_wireless_firmware()
-            label_wireless_fw_no = gtk.Label(wireless_fw_no)
-            label_wireless_fw_no.set_alignment(0, 0)
-            box_wireless_fw.pack_start(label_wireless_fw_no, expand=False)
-            label_wireless_fw_no.show()
-            box_software.pack_start(box_wireless_fw, expand=False)
-            box_wireless_fw.show()
+        box_firmware = gtk.HBox(spacing=style.DEFAULT_SPACING)
+        label_firmware = gtk.Label(_('Firmware:'))
+        label_firmware.set_alignment(1, 0)
+        label_firmware.modify_fg(gtk.STATE_NORMAL,
+                                 style.COLOR_SELECTION_GREY.get_gdk_color())
+        box_firmware.pack_start(label_firmware, expand=False)
+        self._group.add_widget(label_firmware)
+        label_firmware.show()
+        label_firmware_no = gtk.Label(self._model.get_firmware_number())
+        label_firmware_no.set_alignment(0, 0)
+        box_firmware.pack_start(label_firmware_no, expand=False)
+        label_firmware_no.show()
+        box_software.pack_start(box_firmware, expand=False)
+        box_firmware.show()
+
+        box_wireless_fw = gtk.HBox(spacing=style.DEFAULT_SPACING)
+        label_wireless_fw = gtk.Label(_('Wireless Firmware:'))
+        label_wireless_fw.set_alignment(1, 0)
+        label_wireless_fw.modify_fg(gtk.STATE_NORMAL,
+                                    style.COLOR_SELECTION_GREY.get_gdk_color())
+        box_wireless_fw.pack_start(label_wireless_fw, expand=False)
+        self._group.add_widget(label_wireless_fw)
+        label_wireless_fw.show()
+        wireless_fw_no = self._model.get_wireless_firmware()
+        label_wireless_fw_no = gtk.Label(wireless_fw_no)
+        label_wireless_fw_no.set_alignment(0, 0)
+        box_wireless_fw.pack_start(label_wireless_fw_no, expand=False)
+        label_wireless_fw_no.show()
+        box_software.pack_start(box_wireless_fw, expand=False)
+        box_wireless_fw.show()
 
         self._vbox.pack_start(box_software, expand=False)
         box_software.show()
-- 
1.7.4.4



More information about the Sugar-devel mailing list