[Secure-testing-commits] r16584 - lib/python
Florian Weimer
fw at alioth.debian.org
Sun Apr 24 16:57:55 UTC 2011
Author: fw
Date: 2011-04-24 16:57:54 +0000 (Sun, 24 Apr 2011)
New Revision: 16584
Modified:
lib/python/debian_support.py
Log:
debian_support.findresource(): new function
Modified: lib/python/debian_support.py
===================================================================
--- lib/python/debian_support.py 2011-04-24 16:14:39 UTC (rev 16583)
+++ lib/python/debian_support.py 2011-04-24 16:57:54 UTC (rev 16584)
@@ -499,22 +499,26 @@
def __repr__(self):
return "BinaryPackage(" + repr(self.astuple()) + ")"
+def findresource(*pathseq):
+ """Finds the file refered to PATHSEQ, relative to the installation
+ based directory."""
+ for path in sys.path:
+ path = os.path.realpath(path)
+ path = os.path.dirname(path)
+ path = os.path.dirname(path)
+ path = os.path.join(path, *pathseq)
+ if os.path.exists(path):
+ return path
+ raise IOError("not found: " + repr(os.path.join(*pathseq)))
+
_config = None
def getconfig():
"""Returns the configuration in data/config.json."""
global _config
if _config is not None:
return _config
- # Configuration file is in ../../data/config.json.
- for path in sys.path:
- path = os.path.realpath(path)
- path = os.path.dirname(path)
- path = os.path.dirname(path)
- path = os.path.join(path, "data", "config.json")
- if os.path.exists(path):
- _config = json.load(file(path))
- return _config
- raise IOError("data/config.json not found")
+ _config = json.load(file(findresource("data", "config.json")))
+ return _config
def test():
# Version
More information about the Secure-testing-commits
mailing list