[Dextrose] [PATCH] AboutComputer: show latest updates check in days

Martin Abente martin.abente.lahaye at gmail.com
Tue Apr 26 19:39:59 EDT 2011


Paraguay layer-1 technicians asked for easy method to
help teachers and kids to determine when their laptop
successfully ran dextrose-updater script.

Implements #2713

README: it requires latest dextrose-updater script.
---
 extensions/cpsection/aboutcomputer/model.py |   22 +++++++++++++++++++++-
 extensions/cpsection/aboutcomputer/view.py  |   15 +++++++++++++++
 2 files changed, 36 insertions(+), 1 deletions(-)

diff --git a/extensions/cpsection/aboutcomputer/model.py b/extensions/cpsection/aboutcomputer/model.py
index 59e370a..792dc10 100644
--- a/extensions/cpsection/aboutcomputer/model.py
+++ b/extensions/cpsection/aboutcomputer/model.py
@@ -21,12 +21,13 @@ import re
 import subprocess
 from gettext import gettext as _
 import errno
-from datetime import datetime
+from datetime import datetime, date
 
 from jarabe import config
 
 _XO_1_0_LEASE_PATH = '/security/lease.sig'
 _XO_1_5_LEASE_PATH = '/bootpart/boot/security/lease.sig'
+_SYS_UPDATE_STAMP_PATH = '/var/lib/dextrose-updater'
 
 _logger = logging.getLogger('ControlPanel - AboutComputer')
 _not_available = _('Not available')
@@ -61,6 +62,25 @@ def get_lease_days():
     str_days_remaining = str(days_remaining) + ' days remaining'
     return str_days_remaining
 
+def _get_system_update_days():
+    if not os.path.exists(_SYS_UPDATE_STAMP_PATH):
+        return None
+    update_mtime = os.path.getmtime(_SYS_UPDATE_STAMP_PATH)
+    update_date = date.fromtimestamp(update_mtime)
+    delta_date = abs(date.today() - update_date)
+    return delta_date.days
+
+def get_system_updated():
+    update = _get_system_update_days()
+    if update is None:
+        return _('Information not available!')
+    elif update == 0:
+        return _('Today')
+    elif update == 1:
+        return _('Yesterday')
+    else:
+        return _('%d days ago') % update
+
 def get_serial_number():
     serial_no = _read_file('/ofw/serial-number')
     if serial_no is None:
diff --git a/extensions/cpsection/aboutcomputer/view.py b/extensions/cpsection/aboutcomputer/view.py
index cfddfd4..ff77a03 100644
--- a/extensions/cpsection/aboutcomputer/view.py
+++ b/extensions/cpsection/aboutcomputer/view.py
@@ -95,6 +95,21 @@ class AboutComputer(SectionView):
         vbox_identity.pack_start(box_lease, expand=False)
         box_lease.show()
 
+        box_update = gtk.HBox(spacing=style.DEFAULT_SPACING)
+        label_update = gtk.Label(_('Latest updates check:'))
+        label_update.set_alignment(1, 0)
+        label_update.modify_fg(gtk.STATE_NORMAL, 
+                               style.COLOR_SELECTION_GREY.get_gdk_color())
+        box_update.pack_start(label_update, expand=False)
+        self._group.add_widget(label_update)
+        label_update.show()
+        label_updated = gtk.Label(self._model.get_system_updated())
+        label_updated.set_alignment(0, 0)
+        box_update.pack_start(label_updated, expand=False)
+        label_updated.show()
+        vbox_identity.pack_start(box_update, expand=False)
+        box_update.show()
+
         self._vbox.pack_start(vbox_identity, expand=False)
         vbox_identity.show()
 
-- 
1.7.4.4



More information about the Dextrose mailing list