env_update: add more vardbapi fallback code
authorZac Medico <zmedico@gentoo.org>
Sun, 18 Sep 2011 23:45:20 +0000 (16:45 -0700)
committerZac Medico <zmedico@gentoo.org>
Sun, 18 Sep 2011 23:45:20 +0000 (16:45 -0700)
For API consumers that call this function without the vardbapi
parameter, it whould continue to work correctly in all the cases
that worked before the vardbapi was added.

pym/portage/util/env_update.py

index 78bef82fabd930f4105d4eed1ebe329316482f77..65ed2dbe1860ab9552fa0723f271651efda5f2c3 100644 (file)
@@ -47,7 +47,15 @@ def env_update(makelinks=1, target_root=None, prev_mtimes=None, contents=None,
                else:
                        if target_root is None:
                                target_root = portage.settings["ROOT"]
-                       vardbapi = portage.db[target_root]["vartree"].dbapi
+                       if hasattr(portage, "db") and target_root in portage.db:
+                               vardbapi = portage.db[target_root]["vartree"].dbapi
+                       else:
+                               settings = config(config_root=target_root,
+                                       target_root=target_root)
+                               target_root = settings["ROOT"]
+                               if env is None:
+                                       env = settings
+                               vardbapi = vartree(settings=settings).dbapi
 
        # Lock the config memory file to prevent symlink creation
        # in merge_contents from overlapping with env-update.