Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/rpms/sugar/0073-sl-2713-Add-last-updated-on-field-to-CP-About-my-com.patch
blob: 619dfedb2c360d4278d7f585116019209e00e5fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
From a69b1c66bfb8adaa80dd98f8e3023a4516dd284e Mon Sep 17 00:00:00 2001
From: Anish Mangal <anish@sugarlabs.org>
Date: Tue, 8 Nov 2011 22:49:50 +0000
Subject: [PATCH sugar 73/74] sl#2713: Add last updated on field to CP/About
 my computer

Signed-off-by: Anish Mangal <anish@sugarlabs.org>
---
 extensions/cpsection/aboutcomputer/model.py |   60 ++++++++++++++++++++++++++-
 extensions/cpsection/aboutcomputer/view.py  |   22 ++++++++++
 2 files changed, 81 insertions(+), 1 deletions(-)

diff --git a/extensions/cpsection/aboutcomputer/model.py b/extensions/cpsection/aboutcomputer/model.py
index 52a1094..753055d 100644
--- a/extensions/cpsection/aboutcomputer/model.py
+++ b/extensions/cpsection/aboutcomputer/model.py
@@ -27,7 +27,6 @@
 
 from jarabe import config
 
-
 _NM_SERVICE = 'org.freedesktop.NetworkManager'
 _NM_PATH = '/org/freedesktop/NetworkManager'
 _NM_IFACE = 'org.freedesktop.NetworkManager'
@@ -254,3 +253,62 @@ def get_license():
     except IOError:
         license_text = _not_available
     return license_text
+
+def get_last_updated_on_field():
+
+    # Get the number of UNIX seconds of the last update date.
+    last_update_unix_seconds = {}
+    try:
+        SERVICE_NAME      = 'org.sugarlabs.client.System'
+        SERVICE_PATH      = '/org/sugarlabs/client/System'
+        SERVICE_INTERFACE = 'org.sugarlabs.client.System'
+
+        bus_class    = dbus.SystemBus()
+        system_obj   = bus_class.get_object(SERVICE_NAME, SERVICE_PATH)
+        system_iface = dbus.Interface(system_obj, SERVICE_INTERFACE)
+        system_props = dbus.Interface(system_iface,
+                                      dbus.PROPERTIES_IFACE)
+        last_update_unix_seconds = system_props.Get(SERVICE_INTERFACE,
+                                                   'LastUpdate')
+    except:
+        msg_str = ('There was some error fetching the last-update-time'
+                   '\nfrom sugar-server. Please contact Support.')
+        _logger.exception(msg_str)
+        return _(msg_str)
+
+    # Check once agin that 'last_update_unix_seconds' is not empty.
+    # You never know !
+    if not last_update_unix_seconds:
+        return _('No update yet!')
+
+    # If we reached here, we have the last-update-time, but it's in
+    # timestamp format.
+    # Using python-subprocess-module (no shell involved), to convert
+    # it into readable date-format; the hack being used (after
+    # removing '-u' option) is the first one mentioned at :
+    # http://www.commandlinefu.com/commands/view/3719/convert-unix-timestamp-to-date
+    environment = os.environ.copy()
+    environment['PATH'] = '%s:/usr/sbin' % (environment['PATH'], )
+
+    last_update_readable_format = {}
+    try:
+        last_update_readable_format = \
+                 subprocess.Popen(['date', '-d',
+                                   '1970-01-01 + ' +
+                                   str(last_update_unix_seconds) +
+                                   ' seconds'],
+                                   stdout=subprocess.PIPE,
+                                   env=environment).stdout.readlines()[0]
+    except:
+        msg_str = ('There was some error in the processing of'
+                  '\nlast-update-time. Please contact Support.')
+        _logger.exception(msg_str)
+        return _(msg_str)
+
+    if not last_update_readable_format:
+        return _('There was some error in the processing of\n'
+                 'last-update-time. Please contact Support.')
+
+    # Everything should be fine (hopefully :-) )
+    return last_update_readable_format
+
diff --git a/extensions/cpsection/aboutcomputer/view.py b/extensions/cpsection/aboutcomputer/view.py
index d719372..dd2f200 100644
--- a/extensions/cpsection/aboutcomputer/view.py
+++ b/extensions/cpsection/aboutcomputer/view.py
@@ -171,6 +171,28 @@ def _setup_software(self):
         box_software.pack_start(box_wireless_fw, expand=False)
         box_wireless_fw.show()
 
+        # Try to fetch "Last Updated On" field from the model.
+        # If the field is not empty, display it.
+        # At present, the field is returned empty, only if "root-access"
+        #    is disabled on the target-machine.
+        last_updated_on_field = self._model.get_last_updated_on_field()
+        if last_updated_on_field:
+            box_last_updated_on = gtk.HBox(spacing=style.DEFAULT_SPACING)
+            label_last_updated_on  = gtk.Label(_('Last Updated On:'))
+            label_last_updated_on.set_alignment(1, 0)
+            label_last_updated_on.modify_fg(gtk.STATE_NORMAL,
+                                   style.COLOR_SELECTION_GREY.get_gdk_color())
+            box_last_updated_on.pack_start(label_last_updated_on, expand=False)
+            self._group.add_widget(label_last_updated_on)
+            label_last_updated_on.show()
+            label_last_updated_on_field = \
+                                   gtk.Label(last_updated_on_field)
+            label_last_updated_on_field.set_alignment(0, 0)
+            box_last_updated_on.pack_start(label_last_updated_on_field, expand=False)
+            label_last_updated_on_field.show()
+            box_software.pack_start(box_last_updated_on, expand=False)
+            box_last_updated_on.show()
+
         self._vbox.pack_start(box_software, expand=False)
         box_software.show()
 
-- 
1.7.6