Gentoo Archives: gentoo-portage-dev

From: Zac Medico <zmedico@g.o>
To: gentoo-portage-dev@l.g.o
Cc: Zac Medico <zmedico@g.o>
Subject: [gentoo-portage-dev] [PATCH] emirrordist: support bsddb3 module (bug 570798)
Date: Tue, 05 Jan 2016 16:09:52
Message-Id: 1452010162-22735-1-git-send-email-zmedico@gentoo.org
1 If shelve.open raises ImportError for bsddb, then use bsddb3 instead.
2
3 X-Gentoo-Bug: 570798
4 X-Gentoo-Bug-url: https://bugs.gentoo.org/show_bug.cgi?id=570798
5 ---
6 pym/portage/_emirrordist/Config.py | 10 +++++++++-
7 1 file changed, 9 insertions(+), 1 deletion(-)
8
9 diff --git a/pym/portage/_emirrordist/Config.py b/pym/portage/_emirrordist/Config.py
10 index f884a49..574a835 100644
11 --- a/pym/portage/_emirrordist/Config.py
12 +++ b/pym/portage/_emirrordist/Config.py
13 @@ -109,7 +109,15 @@ class Config(object):
14 if self.options.dry_run and not os.path.exists(db_file):
15 db = {}
16 else:
17 - db = shelve.open(db_file, flag=open_flag)
18 + try:
19 + db = shelve.open(db_file, flag=open_flag)
20 + except ImportError as e:
21 + # ImportError has different attributes for python2 vs. python3
22 + if (getattr(e, 'name', None) == 'bsddb' or
23 + getattr(e, 'message', None) == 'No module named bsddb'):
24 + from bsddb3 import dbshelve
25 + db = dbshelve.open(db_file, flags=open_flag)
26 +
27 if sys.hexversion < 0x3000000:
28 db = ShelveUnicodeWrapper(db)
29
30 --
31 2.4.10

Replies