diff options
author | Ajay Garg <ajay@activitycentral.com> | 2012-10-16 11:44:11 (GMT) |
---|---|---|
committer | Ajay Garg <ajay@activitycentral.com> | 2012-10-16 11:48:18 (GMT) |
commit | cc614c2e69ad92a1ac00cb4911523a0e29240f2e (patch) | |
tree | 589d4b941ddb6df7240f64cf4121f0ed284934d1 | |
parent | b0ca46a2c5ce87ed5bc3e3db116ed8830b2a49e8 (diff) |
Last-Updated field in "My Settings" -> "About My Computer"
Signed-off-by: Ajay Garg <ajay@activitycentral.com>
-rw-r--r-- | extensions/cpsection/aboutcomputer/model.py | 54 | ||||
-rw-r--r-- | extensions/cpsection/aboutcomputer/view.py | 5 |
2 files changed, 59 insertions, 0 deletions
diff --git a/extensions/cpsection/aboutcomputer/model.py b/extensions/cpsection/aboutcomputer/model.py index 86d2e3f..d0a9c9c 100644 --- a/extensions/cpsection/aboutcomputer/model.py +++ b/extensions/cpsection/aboutcomputer/model.py @@ -226,3 +226,57 @@ 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: + last_update_unix_seconds = int(os.stat('/var/lib/rpm/Packages').st_mtime) + except: + msg_str = _('Information not available.') + _logger.exception(msg_str) + return msg_str + + + NO_UPDATE_MESSAGE = _('No update yet!') + + + # Check once again that 'last_update_unix_seconds' is not empty. + # You never know ! + if not last_update_unix_seconds: + return NO_UPDATE_MESSAGE + + if int(last_update_unix_seconds) == 1194004800: + return NO_UPDATE_MESSAGE + + + # 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 = _('Information not available.') + _logger.exception(msg_str) + return msg_str + + if not last_update_readable_format: + return _('Information not available.') + + # 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 e320077..0560963 100644 --- a/extensions/cpsection/aboutcomputer/view.py +++ b/extensions/cpsection/aboutcomputer/view.py @@ -128,6 +128,11 @@ class AboutComputer(SectionView): self._model.get_wireless_firmware(), box_software) + self._setup_component_if_applicable(None, + _('Last Updated On:'), + self._model.get_last_updated_on_field(), + box_software) + self._vbox.pack_start(box_software, False, True, 0) box_software.show() |