aboutsummaryrefslogtreecommitdiffstats
path: root/src/msec/tools.py
diff options
context:
space:
mode:
authorEugeni Dodonov <eugeni@mandriva.org>2010-02-19 14:06:43 +0000
committerEugeni Dodonov <eugeni@mandriva.org>2010-02-19 14:06:43 +0000
commit5f20439d36f097bd7ec0eed93c608ea8615cac54 (patch)
tree9a6628e7652ea45067f494da851508a88c05716f /src/msec/tools.py
parent88d2e96e688e73dc95b31de439416676fa5f3a4d (diff)
downloadmsec-5f20439d36f097bd7ec0eed93c608ea8615cac54.tar
msec-5f20439d36f097bd7ec0eed93c608ea8615cac54.tar.gz
msec-5f20439d36f097bd7ec0eed93c608ea8615cac54.tar.bz2
msec-5f20439d36f097bd7ec0eed93c608ea8615cac54.tar.xz
msec-5f20439d36f097bd7ec0eed93c608ea8615cac54.zip
Added summary screen
Diffstat (limited to 'src/msec/tools.py')
-rw-r--r--src/msec/tools.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/msec/tools.py b/src/msec/tools.py
new file mode 100644
index 0000000..5aa856e
--- /dev/null
+++ b/src/msec/tools.py
@@ -0,0 +1,52 @@
+#!/usr/bin/python
+#
+# msec: helper tools
+#
+
+import os
+import stat
+import sys
+import time
+import locale
+
+# localization
+import gettext
+try:
+ gettext.install("msec")
+except IOError:
+ _ = str
+
+# constants
+FIREWALL_CMD = "drakfirewall"
+UPDATE_CMD = "MandrivaUpdate"
+
+def find_firewall_info(log):
+ """Finds information about firewall"""
+ # read firewall settings
+ firewall_entries = []
+ try:
+ data = os.popen("iptables -S").readlines()
+ for l in data:
+ if l[:3] == "-A ":
+ firewall_entries.append(l.strip())
+ except:
+ log.error(_("Unable to parse firewall configuration: %s") % sys.exc_value)
+ # not find out if the firewall is enabled
+ if len(firewall_entries) == 0:
+ firewall_status = _("Disabled")
+ else:
+ firewall_status = _("Enabled, with %d rules") % len(firewall_entries)
+ return firewall_status
+
+def get_updates_status(log, updatedir="/var/lib/urpmi"):
+ """Get current update status"""
+ # just find out the modification time of /var/lib/urpmi
+ try:
+ ret = os.stat(updatedir)
+ updated = time.localtime(ret[stat.ST_MTIME])
+ updated_s = time.strftime(locale.nl_langinfo(locale.D_T_FMT), updated)
+ status = _("Last updated: %s") % updated_s
+ except:
+ log.error(_("Unable to access %s: %s") % (updatedir, sys.exc_value))
+ status = _("Unable to determine update status")
+ return status