Blame SOURCES/0001-avahi-python-Use-the-agnostic-DBM-interface.patch

38c882
From be7992f35ab4ed7ed9907319b429dc079c2b7285 Mon Sep 17 00:00:00 2001
38c882
From: "Jan Alexander Steffens (heftig)" <jan.steffens@gmail.com>
38c882
Date: Tue, 11 Jul 2017 21:52:37 +0200
38c882
Subject: [PATCH] avahi-python: Use the agnostic DBM interface
38c882
38c882
Also fixes configure failing if Python 3 is the build python and GDBM is
38c882
enabled, since Py3 only has anydbm under the name of 'dbm'.
38c882
38c882
Not enough to make ServiceTypeDatabase.py compatible with Py3, but it's
38c882
a start.
38c882
38c882
(cherry picked from commit 63750f1be96ad08c407193b08bf3b9ee74310e2d)
38c882
38c882
Related: #1561019
38c882
---
38c882
 avahi-python/avahi/Makefile.am                  | 15 +----------
38c882
 avahi-python/avahi/ServiceTypeDatabase.py.in    | 33 ++++++++++++++++++-------
38c882
 configure.ac                                    |  9 +++----
38c882
 service-type-database/Makefile.am               | 18 +++-----------
38c882
 service-type-database/{build-db.in => build-db} | 13 +++++++---
38c882
 5 files changed, 42 insertions(+), 46 deletions(-)
38c882
 rename service-type-database/{build-db.in => build-db} (87%)
38c882
38c882
diff --git a/avahi-python/avahi/Makefile.am b/avahi-python/avahi/Makefile.am
38c882
index 3eb67d0..c906b9b 100644
38c882
--- a/avahi-python/avahi/Makefile.am
38c882
+++ b/avahi-python/avahi/Makefile.am
38c882
@@ -25,29 +25,16 @@ avahidir = $(pythondir)/avahi
38c882
 
38c882
 if HAVE_GDBM
38c882
 nodist_avahi_SCRIPTS = ServiceTypeDatabase.py
38c882
-
38c882
-ServiceTypeDatabase.py: ServiceTypeDatabase.py.in
38c882
-	$(AM_V_GEN)sed -e 's,@PYTHON\@,$(PYTHON),g' \
38c882
-		-e 's,@DBM\@,gdbm,g' \
38c882
-		-e 's,@FIRST_KEY\@,key = self.db.firstkey(),g' \
38c882
-		-e 's,@CHECK_KEY\@,while key is not None:,g' \
38c882
-		-e 's,@NEXT_KEY\@,key = self.db.nextkey(key),g' \
38c882
-		-e 's,@pkglibdatadir\@,$(pkglibdatadir),g' $< > $@ && \
38c882
-	chmod +x $@
38c882
 endif
38c882
 
38c882
 if HAVE_DBM
38c882
 nodist_avahi_SCRIPTS = ServiceTypeDatabase.py
38c882
+endif
38c882
 
38c882
 ServiceTypeDatabase.py: ServiceTypeDatabase.py.in
38c882
 	$(AM_V_GEN)sed -e 's,@PYTHON\@,$(PYTHON),g' \
38c882
-		-e 's,@DBM\@,dbm,g' \
38c882
-		-e 's,@FIRST_KEY\@,keys = self.db.keys(),g' \
38c882
-		-e 's,@CHECK_KEY\@,for key in keys:,g' \
38c882
-		-e 's,@NEXT_KEY\@,,g' \
38c882
 		-e 's,@pkglibdatadir\@,$(pkglibdatadir),g' $< > $@ && \
38c882
 	chmod +x $@
38c882
-endif
38c882
 
38c882
 avahi_PYTHON = $(avahi_SCRIPTS)
38c882
 
38c882
diff --git a/avahi-python/avahi/ServiceTypeDatabase.py.in b/avahi-python/avahi/ServiceTypeDatabase.py.in
38c882
index 4ddd654..d7f9969 100644
38c882
--- a/avahi-python/avahi/ServiceTypeDatabase.py.in
38c882
+++ b/avahi-python/avahi/ServiceTypeDatabase.py.in
38c882
@@ -17,7 +17,11 @@
38c882
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
38c882
 # USA.
38c882
 
38c882
-import @DBM@
38c882
+try:
38c882
+    import anydbm as dbm
38c882
+except ImportError:
38c882
+    import dbm
38c882
+
38c882
 import locale
38c882
 import re
38c882
 
38c882
@@ -28,7 +32,7 @@ class ServiceTypeDatabase:
38c882
 
38c882
     def __init__(self, filename = "@pkglibdatadir@/service-types.db"):
38c882
 
38c882
-        self.db = @DBM@.open(filename, "r")
38c882
+        self.db = dbm.open(filename, "r")
38c882
 
38c882
         l = locale.getlocale(locale.LC_MESSAGES)
38c882
 
38c882
@@ -90,13 +94,24 @@ class ServiceTypeDatabase:
38c882
 
38c882
     def __iter__(self):
38c882
 
38c882
-        @FIRST_KEY@
38c882
-        @CHECK_KEY@
38c882
-
38c882
-            if re.search('_[a-zA-Z0-9-]+\._[a-zA-Z0-9-]+', key) and not re.search('_[a-zA-Z0-9-]+\._[a-zA-Z0-9-]+\[.*\]', key):
38c882
-                yield key
38c882
-
38c882
-            @NEXT_KEY@
38c882
+        def want_key(key):
38c882
+            if not re.search('_[a-zA-Z0-9-]+\._[a-zA-Z0-9-]+', key):
38c882
+                return False
38c882
+            if re.search('_[a-zA-Z0-9-]+\._[a-zA-Z0-9-]+\[.*\]', key):
38c882
+                return False
38c882
+            return True
38c882
+
38c882
+        try:
38c882
+            key = self.db.firstkey()
38c882
+        except AttributeError:
38c882
+            for key in self.db.keys():
38c882
+                if want_key(key):
38c882
+                    yield key
38c882
+        else:
38c882
+            while key is not None:
38c882
+                if want_key(key):
38c882
+                    yield key
38c882
+                key = self.db.nextkey(key)
38c882
 
38c882
     def __len__(self):
38c882
 
38c882
diff --git a/configure.ac b/configure.ac
38c882
index 6678971..fbbf7cf 100644
38c882
--- a/configure.ac
38c882
+++ b/configure.ac
38c882
@@ -824,11 +824,10 @@ if test "x$HAVE_PYTHON" = "xyes" ; then
38c882
         fi
38c882
 
38c882
         AM_CHECK_PYMOD(socket,,,[AC_MSG_ERROR(Could not find Python module socket)])
38c882
-        if test "x$HAVE_GDBM" = "xyes"; then
38c882
-            AM_CHECK_PYMOD(gdbm,,,[AC_MSG_ERROR(Could not find Python module gdbm)])
38c882
-        fi
38c882
-        if test "x$HAVE_DBM" = "xyes"; then
38c882
-            AM_CHECK_PYMOD(dbm,,,[AC_MSG_ERROR(Could not find Python module dbm)])
38c882
+        if test "x$HAVE_GDBM" = "xyes" || test "x$HAVE_DBM" = "xyes"; then
38c882
+            AM_CHECK_PYMOD(anydbm,,,[
38c882
+                AM_CHECK_PYMOD(dbm,,,[AC_MSG_ERROR(Could not find Python module dbm)])
38c882
+            ])
38c882
         fi
38c882
     fi
38c882
 fi
38c882
diff --git a/service-type-database/Makefile.am b/service-type-database/Makefile.am
38c882
index d184fde..f9fa082 100644
38c882
--- a/service-type-database/Makefile.am
38c882
+++ b/service-type-database/Makefile.am
38c882
@@ -15,7 +15,7 @@
38c882
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
38c882
 # USA.
38c882
 
38c882
-EXTRA_DIST=build-db.in service-types
38c882
+EXTRA_DIST=service-types
38c882
 
38c882
 pkglibdatadir=$(libdir)/avahi
38c882
 
38c882
@@ -27,16 +27,11 @@ if HAVE_GDBM
38c882
 noinst_SCRIPTS=build-db
38c882
 pkglibdata_DATA+=service-types.db
38c882
 
38c882
-build-db: build-db.in
38c882
-	$(AM_V_GEN)sed -e 's,@PYTHON\@,$(PYTHON),g' \
38c882
-	    -e 's,@DBM\@,gdbm,g' $< > $@ && \
38c882
-	chmod +x $@
38c882
-
38c882
-service-types.db: service-types build-db
38c882
+service-types.db: service-types
38c882
 	$(AM_V_GEN)$(PYTHON) build-db $< $@.coming && \
38c882
 	mv $@.coming $@
38c882
 
38c882
-CLEANFILES = service-types.db build-db
38c882
+CLEANFILES = service-types.db
38c882
 
38c882
 endif
38c882
 if HAVE_DBM
38c882
@@ -44,11 +39,6 @@ if HAVE_DBM
38c882
 noinst_SCRIPTS=build-db
38c882
 pkglibdata_DATA+=service-types.db.pag service-types.db.dir
38c882
 
38c882
-build-db: build-db.in
38c882
-	$(AM_V_GEN)sed -e 's,@PYTHON\@,$(PYTHON),g' \
38c882
-	    -e 's,@DBM\@,dbm,g' $< > $@ && \
38c882
-	chmod +x $@
38c882
-
38c882
 service-types.db.pag: service-types.db
38c882
 	$(AM_V_GEN)mv service-types.db.coming.pag service-types.db.pag
38c882
 service-types.db.dir: service-types.db
38c882
@@ -57,7 +47,7 @@ service-types.db: service-types build-db
38c882
 	$(AM_V_GEN)$(PYTHON) build-db $< $@.coming && \
38c882
 	if test -f "$@.coming"; then mv $@.coming $@; fi
38c882
 
38c882
-CLEANFILES = service-types.db* build-db
38c882
+CLEANFILES = service-types.db*
38c882
 
38c882
 endif
38c882
 endif
38c882
diff --git a/service-type-database/build-db.in b/service-type-database/build-db
38c882
similarity index 87%
38c882
rename from service-type-database/build-db.in
38c882
rename to service-type-database/build-db
38c882
index 4cda425..78ee892 100755
38c882
--- a/service-type-database/build-db.in
38c882
+++ b/service-type-database/build-db
38c882
@@ -1,4 +1,4 @@
38c882
-#!@PYTHON@
38c882
+#!/usr/bin/env python
38c882
 # -*-python-*-
38c882
 # This file is part of avahi.
38c882
 #
38c882
@@ -17,7 +17,12 @@
38c882
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
38c882
 # USA.
38c882
 
38c882
-import @DBM@, sys
38c882
+try:
38c882
+    import anydbm as dbm
38c882
+except ImportError:
38c882
+    import dbm
38c882
+
38c882
+import sys
38c882
 
38c882
 if len(sys.argv) > 1:
38c882
     infn = sys.argv[1]
38c882
@@ -29,9 +34,9 @@ if len(sys.argv) > 2:
38c882
 else:
38c882
     outfn = infn + ".db"
38c882
 
38c882
-db = @DBM@.open(outfn, "n")
38c882
+db = dbm.open(outfn, "n")
38c882
 
38c882
-for ln in file(infn, "r"):
38c882
+for ln in open(infn, "r"):
38c882
     ln = ln.strip(" \r\n\t")
38c882
     
38c882
     if ln == "" or ln.startswith("#"):
38c882
-- 
38c882
2.14.3
38c882