[Dextrose] [PATCH][Dx2][dx-platform] Lease expiration reminder
Martin Abente
martin.abente.lahaye at gmail.com
Fri Apr 29 20:32:54 EDT 2011
Emit a signal to remind users about the
procedure required to re-activate their laptop
at school.
The signal will fire a notification once each day,
_DAYS_UNTIL_WARNING days prior to the lease
expiration date.
Implements #2658
---
etc/cron.daily/remind | 66 +++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 66 insertions(+), 0 deletions(-)
create mode 100644 etc/cron.daily/remind
diff --git a/etc/cron.daily/remind b/etc/cron.daily/remind
new file mode 100644
index 0000000..0bed88a
--- /dev/null
+++ b/etc/cron.daily/remind
@@ -0,0 +1,66 @@
+#!/usr/bin/env python
+# Copyright (C) 2011, Martin Abente
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# 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
+import sys
+import dbus
+import dbus.service
+from datetime import datetime
+
+_DBUS_SYSTEM_IFACE = 'org.sugarlabs.system'
+_DBUS_SYSTEM_PATH = '/org/sugarlabs/system'
+_DBUS_SYSTEM_NAME = 'Remind'
+_XO_1_0_LEASE_PATH = '/security/lease.sig'
+_XO_1_5_LEASE_PATH = '/bootpart/boot/security/lease.sig'
+_DATE_FORMAT = '%Y%m%dT%H%M%SZ'
+_DAYS_UNTIL_WARNING = 2
+
+def _emit_reminder_signal():
+ signal = dbus.lowlevel.SignalMessage(_DBUS_SYSTEM_PATH,
+ _DBUS_SYSTEM_IFACE,
+ _DBUS_SYSTEM_NAME)
+ sys = dbus.SystemBus()
+ sys.send_message(signal)
+
+def _get_lease_path():
+ if os.path.exists(_XO_1_0_LEASE_PATH):
+ return _XO_1_0_LEASE_PATH
+ elif os.path.exists(_XO_1_5_LEASE_PATH):
+ return _XO_1_5_LEASE_PATH
+ else:
+ print 'Can\'t find lease file'
+ sys.exit(-1)
+
+def _get_remaining_days():
+ lease_path = _get_lease_path()
+
+ with open(lease_path) as lease_file:
+ lease_data = lease_file.read()
+
+ encoded_date = lease_data.split()[3]
+ expiration_date = datetime.strptime(encoded_date, _DATE_FORMAT)
+ current_date = datetime.today()
+ delta_date = abs(expiration_date - current_date)
+ return delta_date.days
+
+def check_expiration_date():
+ remaining_days = _get_remaining_days()
+ if remaining_days <= _DAYS_UNTIL_WARNING:
+ _emit_reminder_signal()
+
+
+check_expiration_date()
--
1.7.4.4
More information about the Dextrose
mailing list