From c3f8dd2d6d2f8066c546001eb1e5e2f5b9b78b04 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Piotr=20O=C5=BCarowski?= <piotr@debian.org>
Date: Sun, 13 Feb 2011 21:21:14 +0100
Subject: [PATCH] dh_python2 and pycompile: read
 /usr/share/python/debian_defaults to get default Python version and a List of
 supported Python versions

---
 debian/changelog     |  2 ++
 debpython/version.py | 25 ++++++++++++++++++++++++-
 dh_python2.rst       |  2 +-
 3 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 0abde32..8a96a5e 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,5 +1,7 @@
 python-defaults (2.6.6-11) UNRELEASED; urgency=low
 
+  * dh_python2 and pycompile: read /usr/share/python/debian_defaults to get
+    default Python version and a List of supported Python versions
   * dh_python2:
     - fix parsing .pyinstall files (a space between file name and
       module name is now required)
diff --git a/debpython/version.py b/debpython/version.py
index cf032f9..7a858cb 100644
--- a/debpython/version.py
+++ b/debpython/version.py
@@ -19,15 +19,38 @@
 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 # THE SOFTWARE.
 
+import logging
 import re
-from os.path import exists
+from ConfigParser import SafeConfigParser
+from os.path import exists, dirname, join
 from types import GeneratorType
 
+# will be overriden via debian_defaults file few lines later
 SUPPORTED = [(2, 5), (2, 6), (2, 7)]
 DEFAULT = (2, 6)
+
 RANGE_PATTERN = r'(-)?(\d\.\d+)(?:(-)(\d\.\d+)?)?'
 RANGE_RE = re.compile(RANGE_PATTERN)
 
+log = logging.getLogger(__name__)
+
+# try to read debian_defaults and get a list of supported Python versions and
+# the default one from there
+_config = SafeConfigParser()
+_config.read(['/usr/share/python/debian_defaults',
+             join(dirname(__file__), '..', 'debian', 'debian_defaults')])
+try:
+    DEFAULT = tuple(int(i) for i in _config.get('DEFAULT',
+                    'default-version')[6:].split('.'))
+except:
+    log.exception('cannot read debian_defaults')
+try:
+    SUPPORTED = tuple(tuple(int(j) for j in i.strip()[6:].split('.'))\
+                            for i in _config.get('DEFAULT',
+                                'supported-versions').split(','))
+except:
+    log.exception('cannot read debian_defaults')
+
 
 def get_requested_versions(vrange=None, available=None):
     """Return a set of requested and supported Python versions.
diff --git a/dh_python2.rst b/dh_python2.rst
index 624e8aa..05b4dd6 100644
--- a/dh_python2.rst
+++ b/dh_python2.rst
@@ -38,7 +38,7 @@ NOTES
 In order to support more than one Python version in the same binary package,
 dh_python2 (unlike dh_pycentral and dh_pysupport) creates symlinks to all
 supported Python versions at build time. It means binNMU (or sourceful upload
-in case of architecture independent packages) are required once a list of
+in case of architecture independent packages) is required once a list of
 supported Python version is changed. It's faster and more robust than its
 competitors, though.
 
-- 
GitLab