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

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