diff options
author | Raphaël Beamonte <raphael.beamonte@gmail.com> | 2013-01-05 12:48:01 -0500 |
---|---|---|
committer | David Sommerseth <davids@redhat.com> | 2013-01-10 20:59:31 +0100 |
commit | 8c0567d58fec552d160ff73c52677f7da939d454 (patch) | |
tree | 05c60472c429b359a8c15bf8961f01fc9c0976cd /rteval | |
parent | 976df9301d06df3ca1be1a44d29f06a4c630b5d3 (diff) | |
download | rteval-8c0567d58fec552d160ff73c52677f7da939d454.tar.gz rteval-8c0567d58fec552d160ff73c52677f7da939d454.tar.xz rteval-8c0567d58fec552d160ff73c52677f7da939d454.zip |
Changes the default_config to allow running rteval from git/extracted directory without options
This commit introduce a new method default_config_search to search, for
each file needed in the configuration, the better default place. This place
can be the rteval file directory, the rteval file directory appended with the
'rteval' directory, the ~/.rteval directory of the user, the /etc/rteval
directory, or the /usr/share/rteval directory.
Signed-off-by: Raphaël Beamonte <raphael.beamonte@gmail.com>
Signed-off-by: David Sommerseth <davids@redhat.com>
Diffstat (limited to 'rteval')
-rw-r--r-- | rteval/__init__.py | 4 | ||||
-rw-r--r-- | rteval/rtevalConfig.py | 33 | ||||
-rw-r--r-- | rteval/sysinfo/dmi.py | 11 |
3 files changed, 35 insertions, 13 deletions
diff --git a/rteval/__init__.py b/rteval/__init__.py index 09c68ad..dbb6d87 100644 --- a/rteval/__init__.py +++ b/rteval/__init__.py @@ -90,10 +90,6 @@ class RtEval(rtevalReport): else: self.__mailer = None - # Prepare XSLT processing, if enabled - if not self.__rtevcfg.xslt_report.startswith(self.__rtevcfg.installdir): - self.__rtevcfg.xslt_report = os.path.join(self.__rtevcfg.installdir, "rteval_text.xsl") - if not os.path.exists(self.__rtevcfg.xslt_report): raise RuntimeError("can't find XSL template (%s)!" % self.__rtevcfg.xslt_report) diff --git a/rteval/rtevalConfig.py b/rteval/rtevalConfig.py index 1bf4a42..530626e 100644 --- a/rteval/rtevalConfig.py +++ b/rteval/rtevalConfig.py @@ -34,6 +34,33 @@ import os import ConfigParser from Log import Log + +def default_config_search(relative_path, verifdef=os.path.isdir): + ConfigDirectories=[ + os.path.join(os.path.expanduser("~" + \ + (os.getenv('SUDO_USER') or os.getenv('USER'))), '.rteval'), + '/etc/rteval', + '/usr/share/rteval' + ] + + if os.path.dirname(os.path.abspath(__file__)) != '/usr/share/rteval': + ConfigDirectories = [ + os.path.dirname(os.path.dirname(os.path.abspath(__file__))), + os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'rteval') + ] + ConfigDirectories + + for path in ConfigDirectories: + if verifdef(os.path.join(path, *relative_path)): + return os.path.join(path, *relative_path) + + return False + + +if os.path.dirname(os.path.abspath(__file__)) != '/usr/local/bin': + installdir = os.path.dirname(os.path.abspath(__file__)) +else: + installdir = '/usr/share/rteval' + default_config = { 'rteval': { 'quiet' : False, @@ -45,10 +72,10 @@ default_config = { 'reportdir' : None, 'reportfile' : None, 'workdir' : os.getcwd(), - 'installdir' : '/usr/share/rteval', - 'srcdir' : '/usr/share/rteval/loadsource', + 'installdir' : installdir, + 'srcdir' : default_config_search(['loadsource']), 'xmlrpc' : None, - 'xslt_report': '/usr/share/rteval/rteval_text.xsl', + 'xslt_report': default_config_search(['rteval_text.xsl'], os.path.isfile), 'report_interval': '600', 'logging' : False, } diff --git a/rteval/sysinfo/dmi.py b/rteval/sysinfo/dmi.py index a7eb46e..7cef10f 100644 --- a/rteval/sysinfo/dmi.py +++ b/rteval/sysinfo/dmi.py @@ -27,6 +27,7 @@ import sys, os import libxml2, libxslt +from rteval import rtevalConfig from rteval.Log import Log try: @@ -64,7 +65,6 @@ class DMIinfo(object): def __init__(self, config, logger): self.__version = '0.4' - self.__sharedir = config.installdir if not dmidecode_loaded: logger.log(Log.DEBUG|Log.WARN, "No dmidecode module found, ignoring DMI tables") @@ -79,13 +79,12 @@ class DMIinfo(object): def __load_xslt(self, fname): - if os.path.exists(fname): + if os.path.isfile(fname): return libxml2.parseFile(fname) - elif os.path.exists(self.__sharedir + '/' + fname): - return libxml2.parseFile(self.__sharedir + '/' + fname) + elif rtevalConfig.default_config_search([fname], os.path.isfile): + return libxml2.parseFile(rtevalConfig.default_config_search([fname], os.path.isfile)) else: - raise RuntimeError, 'Could not locate XSLT template for DMI data (%s/%s)' % \ - (self.__sharedir, fname) + raise RuntimeError('Could not locate XSLT template for DMI data (%s/%s)' % (fname)) def MakeReport(self): |