[Secure-testing-commits] r16582 - lib/python

Florian Weimer fw at alioth.debian.org
Sun Apr 24 16:11:48 UTC 2011


Author: fw
Date: 2011-04-24 16:11:46 +0000 (Sun, 24 Apr 2011)
New Revision: 16582

Modified:
   lib/python/debian_support.py
Log:
debian_support.getconfig(): new function


Modified: lib/python/debian_support.py
===================================================================
--- lib/python/debian_support.py	2011-04-24 15:35:27 UTC (rev 16581)
+++ lib/python/debian_support.py	2011-04-24 16:11:46 UTC (rev 16582)
@@ -18,11 +18,11 @@
 """This module implements facilities to deal with Debian-specific metadata."""
 
 import types
-import os
+import json
+import os.path
 import re
-import subprocess
+import sys
 import tempfile
-from cStringIO import StringIO
 
 try:
     from hashlib import sha1
@@ -420,8 +420,6 @@
 
 class BinaryPackage(object):
     __slots__ = ("name", "version", "arch", "source", "source_version")
-    re_source = re.compile\
-        (r'^([a-zA-Z0-9.+-]+)(?:\s+\(([a-zA-Z0-9.+:~-]+)\))?$')
 
     def __init__(self, data=None):
         if data is not None:
@@ -501,6 +499,23 @@
     def __repr__(self):
         return "BinaryPackage(" + repr(self.astuple()) + ")"
 
+_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")
+
 def test():
     # Version
     assert Version('0') < Version('a')




More information about the Secure-testing-commits mailing list