[Sugar-devel] [PATCH sugar] Control Panel: making about my computer section hardware independent, OLPC #11232
Simon Schampijer
simon at schampijer.de
Sun Oct 9 12:01:35 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 any hardware.
The serial number is often only readable by root on non-XO
hardware, that is why we do not read it. If the serial number
can not be found on an XO we display the entry as 'Not available'.
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 | 23 +++++++---
extensions/cpsection/aboutcomputer/view.py | 65 +++++++++++++--------------
2 files changed, 48 insertions(+), 40 deletions(-)
diff --git a/extensions/cpsection/aboutcomputer/model.py b/extensions/cpsection/aboutcomputer/model.py
index a02eee6..503be60 100644
--- a/extensions/cpsection/aboutcomputer/model.py
+++ b/extensions/cpsection/aboutcomputer/model.py
@@ -35,6 +35,7 @@ _NM_DEVICE_TYPE_WIFI = 2
_OFW_TREE = '/ofw'
_PROC_TREE = '/proc/device-tree'
+_DMI_DIRECTORY = '/sys/class/dmi/id'
_SN = 'serial-number'
_MODEL = 'openprom/model'
@@ -96,12 +97,7 @@ def print_build_number():
print get_build_number()
-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))
- elif os.path.exists(os.path.join(_PROC_TREE, _MODEL)):
- firmware_no = _read_file(os.path.join(_PROC_TREE, _MODEL))
+def _parse_olpc_firmware_number(firmware_no):
if firmware_no is None:
firmware_no = _not_available
else:
@@ -111,6 +107,21 @@ def get_firmware_number():
return firmware_no
+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 = _parse_olpc_firmware_number(firmware_no)
+ elif os.path.exists(os.path.join(_PROC_TREE, _MODEL)):
+ firmware_no = _read_file(os.path.join(_PROC_TREE, _MODEL))
+ firmware_no = _parse_olpc_firmware_number(firmware_no)
+ elif os.path.exists(os.path.join(_DMI_DIRECTORY, 'bios_version')):
+ firmware_no = _read_file(os.path.join(_DMI_DIRECTORY, 'bios_version'))
+ if firmware_no is None:
+ firmware_no = _not_available
+ return firmware_no
+
+
def print_firmware_number():
print get_firmware_number()
diff --git a/extensions/cpsection/aboutcomputer/view.py b/extensions/cpsection/aboutcomputer/view.py
index e5f2f32..257e165 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,8 +46,7 @@ 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()
@@ -127,37 +125,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