prelude-notify/master: Improved configuration and themes management
[email protected] Fri, 12 Feb 2010 16:33:45 +0100 (CET)
| Newsgroups | gmane.comp.security.ids.prelude.cvs |
|---|---|
| Message-ID | <[email protected]> |
commit a2851a3149743f6cf1ccb0a24f64701d7d7ce23f Author: Alexandre De Dommelin <[email protected]> Date: Fri Feb 12 15:21:13 2010 +0100 Improved configuration and themes management Configuration now relies by default on a system-wide config file. Added a full themes support to easily customize prelude-notify Signed-off-by: Yoann Vandoorselaere <[email protected]> ======================================== AUTHORS | 2 +- PreludeNotify/notifyaction.py | 2 +- PreludeNotify/pnconfig.py | 43 ++++++++++++++++++++++++++--------- PreludeNotify/pnstatusicon.py | 11 +++++---- pixmaps/themes/tray/notify-bad.png | Bin 0 -> 1077 bytes pixmaps/themes/tray/notify-ok.png | Bin 0 -> 1166 bytes pixmaps/tray/notify-bad.png | Bin 1077 -> 0 bytes pixmaps/tray/notify-ok.png | Bin 1166 -> 0 bytes prelude-notify.conf | 17 ++++++++++++++ setup.py | 12 ++++++---- 10 files changed, 64 insertions(+), 23 deletions(-) ======================================== diff --git a/AUTHORS b/AUTHORS index 668c949..f82c80a 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,3 +1,3 @@ Sebastien Tricaud <stricaud inl.fr> Yoann Vandoorselaere <yoann.v prelude-ids.com> - +Alexandre De Dommelin <adedommelin tuxz.net> diff --git a/PreludeNotify/notifyaction.py b/PreludeNotify/notifyaction.py index cec3544..e72869d 100644 --- a/PreludeNotify/notifyaction.py +++ b/PreludeNotify/notifyaction.py @@ -61,7 +61,7 @@ class NotifyNow: def _severity_map(self, severity): urgency = None imageuri = None - baseuri = "file://" + pnconfig.themespath + self._env.config.get("ui", "theme") + "/" + baseuri = "file://" + self._env.config.getThemePath() + "/" for i in (("high", pynotify.URGENCY_CRITICAL), ("medium", pynotify.URGENCY_NORMAL), diff --git a/PreludeNotify/pnconfig.py b/PreludeNotify/pnconfig.py index 72e9bd8..1d43974 100644 --- a/PreludeNotify/pnconfig.py +++ b/PreludeNotify/pnconfig.py @@ -1,5 +1,6 @@ # Copyright (C) 2008 PreludeIDS Technologies. All Rights Reserved. # Author: Sebastien Tricaud <[email protected]> +# Alexandre De Dommelin <[email protected]> # # This file is part of the Prewikka program. # @@ -24,24 +25,24 @@ from ManagerConnection import Session from PreludeNotify import siteconfig from ConfigParser import SafeConfigParser -iconok = siteconfig.prefix + "/share/prelude-notify/tray/notify-ok.png" -iconbad = siteconfig.prefix + "/share/prelude-notify/tray/notify-bad.png" -themespath = siteconfig.prefix + "/share/prelude-notify/themes/" +userconfigpath = "%s/.prelude-notify" % (os.getenv("HOME")) +globalthemespath = siteconfig.prefix + "/share/prelude-notify/themes" +userthemespath = userconfigpath + "/themes" class PnConfig(SafeConfigParser): - _configname = "%s/.prelude-notifyrc" % (os.getenv("HOME")) + _globalconfigfile = siteconfig.conf_dir + "/prelude-notify.conf" + _userconfigfile = userconfigpath + "/prelude-notifyrc" def __init__(self, env): SafeConfigParser.__init__(self) self._updated = {} self.env = env - if os.path.exists(self._configname): - self.read(self._configname) + if os.path.exists(self._userconfigfile): + self.read(self._userconfigfile) + elif os.path.exists(self._globalconfigfile): + self.read(self._globalconfigfile) else: - for section in "general", "idmef", "manager", "prewikka", "ui": - self.add_section(section) - SafeConfigParser.set(self, "general", "threshold_timeout", "5") SafeConfigParser.set(self, "general", "x11_idle_timeout", "5") SafeConfigParser.set(self, "idmef", "profile", "prelude-notify") @@ -51,7 +52,25 @@ class PnConfig(SafeConfigParser): SafeConfigParser.set(self, "ui", "theme", "default") SafeConfigParser.set(self, "ui", "browser", "auto") - self.write(open(self._configname, "w")) + + + _configtheme = SafeConfigParser.get(self,"ui","theme") + + if os.path.isdir( userthemespath + "/" + _configtheme ): + self.theme = userthemespath + "/" + _configtheme + elif os.path.isdir( globalthemespath + "/" + _configtheme ): + self.theme = globalthemespath + "/" + _configtheme + else: + self.theme = globalthemespath + "/" + "default" + + def getIconOk(self): + return self.theme + "/tray/notify-ok.png" + + def getIconBad(self): + return self.theme + "/tray/notify-bad.png" + + def getThemePath(self): + return self.theme def set(self, section, key, value): old = SafeConfigParser.get(self, section, key) @@ -89,5 +108,7 @@ class PnConfig(SafeConfigParser): except: self._updated = {} return + if not os.path.isdir( userconfigpath ): + os.mkdir( userconfigpath ) - self.write(open(self._configname, "w")) + self.write(open(self._userconfigfile, "w")) diff --git a/PreludeNotify/pnstatusicon.py b/PreludeNotify/pnstatusicon.py index 7e85ca5..e1a39a4 100644 --- a/PreludeNotify/pnstatusicon.py +++ b/PreludeNotify/pnstatusicon.py @@ -1,5 +1,6 @@ # Copyright (C) 2008 PreludeIDS Technologies. All Rights Reserved. # Author: Sebastien Tricaud <[email protected]> +# Alexandre De Dommelin <[email protected]> # # This file is part of the Prelude-Notify program. # @@ -26,16 +27,16 @@ import pnconfig class PreludeStatusIcon: def __init__(self, gloop, config): - self.icon = gtk.status_icon_new_from_file(pnconfig.iconok) - self.icon.connect('popup-menu', self.menu) self.config = config self.gloop = gloop + self.icon = gtk.status_icon_new_from_file(self.config.getIconOk()) + self.icon.connect('popup-menu', self.menu) def MissedAlerts(self): - self.icon.set_from_file(pnconfig.iconbad) + self.icon.set_from_file(self.config.getIconBad()) def SeenAlerts(self): - self.icon.set_from_file(pnconfig.iconok) + self.icon.set_from_file(self.config.getIconOk()) def menu(self, icon, event_button, event_time): m = gtk.Menu() @@ -143,7 +144,7 @@ class PreludeStatusIcon: except AttributeError: print "Cannot add the dialog program name" try: - dialog.set_copyright("Sebastien Tricaud (c) 2008") + dialog.set_copyright("Sebastien Tricaud, Alexandre De Dommelin (c) 2010") except AttributeError: print "Cannot add the dialog copyright" try: diff --git a/pixmaps/themes/tray/notify-bad.png b/pixmaps/themes/tray/notify-bad.png new file mode 100644 index 0000000..62ae4d8 Binary files /dev/null and b/pixmaps/themes/tray/notify-bad.png differ diff --git a/pixmaps/themes/tray/notify-ok.png b/pixmaps/themes/tray/notify-ok.png new file mode 100644 index 0000000..2f983a6 Binary files /dev/null and b/pixmaps/themes/tray/notify-ok.png differ diff --git a/pixmaps/tray/notify-bad.png b/pixmaps/tray/notify-bad.png deleted file mode 100644 index 62ae4d8..0000000 Binary files a/pixmaps/tray/notify-bad.png and /dev/null differ diff --git a/pixmaps/tray/notify-ok.png b/pixmaps/tray/notify-ok.png deleted file mode 100644 index 2f983a6..0000000 Binary files a/pixmaps/tray/notify-ok.png and /dev/null differ diff --git a/prelude-notify.conf b/prelude-notify.conf new file mode 100644 index 0000000..29c3b83 --- /dev/null +++ b/prelude-notify.conf @@ -0,0 +1,17 @@ +[idmef] +profile = prelude-notify +filter = + +[manager] +addresses = 127.0.0.1 + +[ui] +theme = default +browser = auto + +[prewikka] +url = http://localhost:8000 + +[general] +threshold_timeout = 5 +x11_idle_timeout = 5 diff --git a/setup.py b/setup.py index b57bcf6..8e78774 100644 --- a/setup.py +++ b/setup.py @@ -4,12 +4,13 @@ import os, glob from distutils.core import setup from distutils.command.install import install -_VERSION="0.9.0-svn" +_VERSION="0.9.1" class my_install(install): def init_siteconfig(self): config = open("PreludeNotify/siteconfig.py", "w") print >> config, "prefix = '%s'" % os.path.abspath(self.prefix) + print >> config, "conf_dir = '/etc/prelude-notify'" print >> config, "version = '%s'" % _VERSION config.close() @@ -22,12 +23,13 @@ class my_install(install): setup(name="prelude-notify", version=_VERSION, - maintainer = "Sebastien Tricaud", - maintainer_email = "[email protected]", + maintainer = "Alexandre De Dommelin", + maintainer_email = "[email protected]", url = "http://www.prelude-ids.com", packages=[ 'PreludeNotify' ], data_files=[ ("share/prelude-notify/themes/default", glob.glob("pixmaps/themes/default/*")), - ("share/prelude-notify/tray", glob.glob("pixmaps/tray/*")), - ("share/applications", ["prelude-notify.desktop"]) ], + ("share/prelude-notify/themes/default/tray", glob.glob("pixmaps/themes/tray/*")), + ("share/applications", ["prelude-notify.desktop"]), + ("/etc/prelude-notify", ["prelude-notify.conf"]) ], scripts=[ "prelude-notify" ], cmdclass={ 'install': my_install } ) _______________________________________________ Prelude-cvslog site list [email protected] http://lists.prelude-technologies.com/mailman/listinfo/prelude-cvslog