1 From 63750f1be96ad08c407193b08bf3b9ee74310e2d Mon Sep 17 00:00:00 2001
2 From: "Jan Alexander Steffens (heftig)" <jan.steffens@gmail.com>
3 Date: Tue, 11 Jul 2017 21:52:37 +0200
4 Subject: [PATCH] avahi-python: Use the agnostic DBM interface
6 Also fixes configure failing if Python 3 is the build python and GDBM is
7 enabled, since Py3 only has anydbm under the name of 'dbm'.
9 Not enough to make ServiceTypeDatabase.py compatible with Py3, but it's
12 avahi-python/avahi/Makefile.am | 15 +--------
13 avahi-python/avahi/ServiceTypeDatabase.py.in | 33 ++++++++++++++-----
14 configure.ac | 9 +++--
15 service-type-database/.gitignore | 1 -
16 service-type-database/Makefile.am | 18 +++-------
17 .../{build-db.in => build-db} | 13 +++++---
18 6 files changed, 42 insertions(+), 47 deletions(-)
19 rename service-type-database/{build-db.in => build-db} (87%)
21 diff --git a/avahi-python/avahi/Makefile.am b/avahi-python/avahi/Makefile.am
22 index 3eb67d0d..c906b9bf 100644
23 --- a/avahi-python/avahi/Makefile.am
24 +++ b/avahi-python/avahi/Makefile.am
25 @@ -25,29 +25,16 @@ avahidir = $(pythondir)/avahi
28 nodist_avahi_SCRIPTS = ServiceTypeDatabase.py
30 -ServiceTypeDatabase.py: ServiceTypeDatabase.py.in
31 - $(AM_V_GEN)sed -e 's,@PYTHON\@,$(PYTHON),g' \
32 - -e 's,@DBM\@,gdbm,g' \
33 - -e 's,@FIRST_KEY\@,key = self.db.firstkey(),g' \
34 - -e 's,@CHECK_KEY\@,while key is not None:,g' \
35 - -e 's,@NEXT_KEY\@,key = self.db.nextkey(key),g' \
36 - -e 's,@pkglibdatadir\@,$(pkglibdatadir),g' $< > $@ && \
41 nodist_avahi_SCRIPTS = ServiceTypeDatabase.py
44 ServiceTypeDatabase.py: ServiceTypeDatabase.py.in
45 $(AM_V_GEN)sed -e 's,@PYTHON\@,$(PYTHON),g' \
46 - -e 's,@DBM\@,dbm,g' \
47 - -e 's,@FIRST_KEY\@,keys = self.db.keys(),g' \
48 - -e 's,@CHECK_KEY\@,for key in keys:,g' \
49 - -e 's,@NEXT_KEY\@,,g' \
50 -e 's,@pkglibdatadir\@,$(pkglibdatadir),g' $< > $@ && \
54 avahi_PYTHON = $(avahi_SCRIPTS)
56 diff --git a/avahi-python/avahi/ServiceTypeDatabase.py.in b/avahi-python/avahi/ServiceTypeDatabase.py.in
57 index 4ddd6544..d7f9969b 100644
58 --- a/avahi-python/avahi/ServiceTypeDatabase.py.in
59 +++ b/avahi-python/avahi/ServiceTypeDatabase.py.in
61 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
66 + import anydbm as dbm
73 @@ -28,7 +32,7 @@ class ServiceTypeDatabase:
75 def __init__(self, filename = "@pkglibdatadir@/service-types.db"):
77 - self.db = @DBM@.open(filename, "r")
78 + self.db = dbm.open(filename, "r")
80 l = locale.getlocale(locale.LC_MESSAGES)
82 @@ -90,13 +94,24 @@ class ServiceTypeDatabase:
89 - 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):
94 + if not re.search('_[a-zA-Z0-9-]+\._[a-zA-Z0-9-]+', key):
96 + if re.search('_[a-zA-Z0-9-]+\._[a-zA-Z0-9-]+\[.*\]', key):
101 + key = self.db.firstkey()
102 + except AttributeError:
103 + for key in self.db.keys():
107 + while key is not None:
110 + key = self.db.nextkey(key)
114 diff --git a/configure.ac b/configure.ac
115 index 66789718..fbbf7cf3 100644
118 @@ -824,11 +824,10 @@ if test "x$HAVE_PYTHON" = "xyes" ; then
121 AM_CHECK_PYMOD(socket,,,[AC_MSG_ERROR(Could not find Python module socket)])
122 - if test "x$HAVE_GDBM" = "xyes"; then
123 - AM_CHECK_PYMOD(gdbm,,,[AC_MSG_ERROR(Could not find Python module gdbm)])
125 - if test "x$HAVE_DBM" = "xyes"; then
126 - AM_CHECK_PYMOD(dbm,,,[AC_MSG_ERROR(Could not find Python module dbm)])
127 + if test "x$HAVE_GDBM" = "xyes" || test "x$HAVE_DBM" = "xyes"; then
128 + AM_CHECK_PYMOD(anydbm,,,[
129 + AM_CHECK_PYMOD(dbm,,,[AC_MSG_ERROR(Could not find Python module dbm)])
134 diff --git a/service-type-database/Makefile.am b/service-type-database/Makefile.am
135 index d184fde3..f9fa0825 100644
136 --- a/service-type-database/Makefile.am
137 +++ b/service-type-database/Makefile.am
139 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
142 -EXTRA_DIST=build-db.in service-types
143 +EXTRA_DIST=service-types
145 pkglibdatadir=$(libdir)/avahi
147 @@ -27,16 +27,11 @@ if HAVE_GDBM
148 noinst_SCRIPTS=build-db
149 pkglibdata_DATA+=service-types.db
151 -build-db: build-db.in
152 - $(AM_V_GEN)sed -e 's,@PYTHON\@,$(PYTHON),g' \
153 - -e 's,@DBM\@,gdbm,g' $< > $@ && \
156 -service-types.db: service-types build-db
157 +service-types.db: service-types
158 $(AM_V_GEN)$(PYTHON) build-db $< $@.coming && \
161 -CLEANFILES = service-types.db build-db
162 +CLEANFILES = service-types.db
166 @@ -44,11 +39,6 @@ if HAVE_DBM
167 noinst_SCRIPTS=build-db
168 pkglibdata_DATA+=service-types.db.pag service-types.db.dir
170 -build-db: build-db.in
171 - $(AM_V_GEN)sed -e 's,@PYTHON\@,$(PYTHON),g' \
172 - -e 's,@DBM\@,dbm,g' $< > $@ && \
175 service-types.db.pag: service-types.db
176 $(AM_V_GEN)mv service-types.db.coming.pag service-types.db.pag
177 service-types.db.dir: service-types.db
178 @@ -57,7 +47,7 @@ service-types.db: service-types build-db
179 $(AM_V_GEN)$(PYTHON) build-db $< $@.coming && \
180 if test -f "$@.coming"; then mv $@.coming $@; fi
182 -CLEANFILES = service-types.db* build-db
183 +CLEANFILES = service-types.db*
187 diff --git a/service-type-database/build-db.in b/service-type-database/build-db
189 rename from service-type-database/build-db.in
190 rename to service-type-database/build-db
191 index 4cda4253..78ee892f 100755
192 --- a/service-type-database/build-db.in
193 +++ b/service-type-database/build-db
196 +#!/usr/bin/env python
198 # This file is part of avahi.
201 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
206 + import anydbm as dbm
212 if len(sys.argv) > 1:
214 @@ -29,9 +34,9 @@ if len(sys.argv) > 2:
218 -db = @DBM@.open(outfn, "n")
219 +db = dbm.open(outfn, "n")
221 -for ln in file(infn, "r"):
222 +for ln in open(infn, "r"):
223 ln = ln.strip(" \r\n\t")
225 if ln == "" or ln.startswith("#"):