[PATCH 8/8] Use the fallback data file if we're not installed on a Debian system.
Ben Finney
bignose at debian.org
Sat Jan 14 16:27:07 UTC 2017
---
debian/changelog | 1 +
lib/debian/debian_support.py | 36 ++++++++++++++++++++++++++++++++++--
2 files changed, 35 insertions(+), 2 deletions(-)
diff --git a/debian/changelog b/debian/changelog
index aae87cf1..e3daff7c 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -5,6 +5,7 @@ python-debian (0.1.30) UNRELEASED; urgency=medium
* Include the data for Debian releases in the Python distribution build.
* Use Debian ‘distro_info’ API for Debian versions and release names.
Closes: bug#849058. Thanks to Paul Gevers for the report.
+ * Use the fallback data file if we're not installed on a Debian system.
--
diff --git a/lib/debian/debian_support.py b/lib/debian/debian_support.py
index 200fbfd1..31884efe 100644
--- a/lib/debian/debian_support.py
+++ b/lib/debian/debian_support.py
@@ -24,12 +24,17 @@
from __future__ import absolute_import, print_function
+import csv
import os
import re
import types
+try:
+ import distro_info
+except ImportError:
+ distro_info = NotImplemented
+
from debian.deprecation import function_deprecated_by
-import distro_info
try:
import apt_pkg
@@ -56,6 +61,15 @@ except ImportError:
" implementation because it depends on OpenSSL, which"
" may not be linked with this library due to license"
" incompatibilities")
+try:
+ # Python 3.3 or later.
+ from types import SimpleNamespace
+except ImportError:
+ class SimpleNamespace(object):
+ """ A simple namespace for attributes. """
+
+import pkg_resources
+
class ParseError(Exception):
"""An exception which is used to signal a parse failure.
@@ -418,7 +432,25 @@ class PseudoEnum:
class Release(PseudoEnum): pass
-debian_distro_info = distro_info.DebianDistroInfo()
+if distro_info is NotImplemented:
+ # The `distro_info` package is specific to a Debian release; it is
+ # not available on PyPI. We need to fall back on the installed
+ # data file resource in this Python distribution.
+ _python_distribution = pkg_resources.get_distribution("python-debian")
+ if not pkg_resources.resource_exists('debian', 'releases.csv'):
+ raise RuntimeError("Debian releases data not available on this system")
+ _releases_data_infile = pkg_resources.resource_stream(
+ 'debian', 'releases.csv')
+ debian_distro_info = SimpleNamespace()
+ with _releases_data_infile:
+ _releases_data_reader = csv.DictReader(_releases_data_infile)
+ debian_distro_info.all = [
+ record['codename'].lower() for record in _releases_data_reader]
+ del _releases_data_reader
+ del _releases_data_infile
+ del _python_distribution
+else:
+ debian_distro_info = distro_info.DebianDistroInfo()
def list_releases():
releases = {
--
2.11.0
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.alioth.debian.org/pipermail/pkg-python-debian-maint/attachments/20170115/237ce304/attachment-0001.sig>
More information about the pkg-python-debian-maint
mailing list