create_trees: ensure trees is _trees_dict type
authorZac Medico <zmedico@gentoo.org>
Fri, 28 Oct 2011 00:53:51 +0000 (17:53 -0700)
committerZac Medico <zmedico@gentoo.org>
Fri, 28 Oct 2011 00:53:51 +0000 (17:53 -0700)
pym/portage/__init__.py

index 03ec2866581b5afc576028bdf34c918cc2bbfb57..e4abab371f3d39c28f3c992fa91ac0f13aeb7039 100644 (file)
@@ -480,15 +480,13 @@ def portageexit():
                close_portdbapi_caches()
 
 class _trees_dict(dict):
-       def __init__(self):
-               super(dict, self).__init__()
+       def __init__(self, *pargs, **kargs):
+               dict.__init__(self, *pargs, **kargs)
                self._running_eroot = None
                self._target_eroot = None
 
 def create_trees(config_root=None, target_root=None, trees=None, env=None):
-       if trees is None:
-               trees = _trees_dict()
-       else:
+       if trees is not None:
                # clean up any existing portdbapi instances
                for myroot in trees:
                        portdb = trees[myroot]["porttree"].dbapi
@@ -496,6 +494,13 @@ def create_trees(config_root=None, target_root=None, trees=None, env=None):
                        portdbapi.portdbapi_instances.remove(portdb)
                        del trees[myroot]["porttree"], myroot, portdb
 
+       if trees is None:
+               trees = _trees_dict()
+       elif not isinstance(trees, _trees_dict):
+               # caller passed a normal dict or something,
+               # but we need a _trees_dict instance
+               trees = _trees_dict(trees)
+
        if env is None:
                env = os.environ
        eprefix = env.get("__PORTAGE_TEST_EPREFIX")