Pass existing portdbapi and vardbapi instances into the NewsManager constructor.
authorZac Medico <zmedico@gentoo.org>
Wed, 13 Jun 2007 23:35:14 +0000 (23:35 -0000)
committerZac Medico <zmedico@gentoo.org>
Wed, 13 Jun 2007 23:35:14 +0000 (23:35 -0000)
svn path=/main/trunk/; revision=6841

pym/emerge/__init__.py
pym/portage/news.py

index 06759d70be4b249267321082ed77cf308b748730..4aabe97c30bc4c6282aec7a7e1cdf5d039218b55 100644 (file)
@@ -3793,13 +3793,15 @@ def display_news_notification(trees):
                if len(trees) > 1 and target_root != "/":
                        break
        settings = trees[target_root]["vartree"].settings
-       porttree = trees[target_root]["porttree"].dbapi
+       portdb = trees[target_root]["porttree"].dbapi
+       vardb = trees[target_root]["vartree"].dbapi
        NEWS_PATH = os.path.join("metadata", "news")
        UNREAD_PATH = os.path.join(target_root, NEWS_LIB_PATH, "news")
        newsReaderDisplay = False
 
-       for repo in porttree.getRepositories():
-               unreadItems = checkUpdatedNewsItems(target_root, NEWS_PATH, UNREAD_PATH, repo)
+       for repo in portdb.getRepositories():
+               unreadItems = checkUpdatedNewsItems(
+                       portdb, vardb, NEWS_PATH, UNREAD_PATH, repo)
                if unreadItems:
                        if not newsReaderDisplay:
                                newsReaderDisplay = True
@@ -3910,13 +3912,15 @@ def chk_updated_cfg_files(target_root, config_protect):
                        #print " "+yellow("*")+" Type "+green("emerge --help config")+" to learn how to update config files."
                        print " "+yellow("*")+" Type "+green("emerge --help config")+" to learn how to update config files."
 
-def checkUpdatedNewsItems( root, NEWS_PATH, UNREAD_PATH, repo_id ):
+def checkUpdatedNewsItems(portdb, vardb, NEWS_PATH, UNREAD_PATH, repo_id):
        """
        Examines news items in repodir + '/' + NEWS_PATH and attempts to find unread items
        Returns the number of unread (yet relevent) items.
        
-       @param root:
-       @type root:
+       @param portdb: a portage tree database
+       @type portdb: pordbapi
+       @param vardb: an installed package database
+       @type vardb: vardbapi
        @param NEWS_PATH:
        @type NEWS_PATH:
        @param UNREAD_PATH:
@@ -3929,7 +3933,7 @@ def checkUpdatedNewsItems( root, NEWS_PATH, UNREAD_PATH, repo_id ):
        
        """
        from portage.news import NewsManager
-       manager = NewsManager( root, NEWS_PATH, UNREAD_PATH )
+       manager = NewsManager(portdb, vardb, NEWS_PATH, UNREAD_PATH)
        return manager.getUnreadItems( repo_id, update=True )
 
 def is_valid_package_atom(x):
index 3cfb5de12b966cf82d4f6da478d358637cf3be99..0288058760c68758d0442678cd1b9bc7250b9cc7 100644 (file)
@@ -4,7 +4,6 @@
 # $Id$
 
 from portage.const import INCREMENTALS, PROFILE_PATH, NEWS_LIB_PATH
-from portage import config, vartree, vardbapi, portdbapi
 from portage.util import ensure_dirs, apply_permissions
 from portage.data import portage_gid
 from portage.locks import lockfile, unlockfile, lockdir, unlockdir
@@ -26,17 +25,16 @@ class NewsManager(object):
 
        TIMESTAMP_FILE = "news-timestamp"
 
-       def __init__(self, root, NEWS_PATH, UNREAD_PATH, LANGUAGE_ID='en'):
+       def __init__(self, portdb, vardb, NEWS_PATH, UNREAD_PATH, LANGUAGE_ID='en'):
                self.NEWS_PATH = NEWS_PATH
                self.UNREAD_PATH = UNREAD_PATH
-               self.TIMESTAMP_PATH = os.path.join(root, NEWS_LIB_PATH, NewsManager.TIMESTAMP_FILE)
-               self.target_root = root
+               self.TIMESTAMP_PATH = os.path.join(vardb.root,
+                       NEWS_LIB_PATH, NewsManager.TIMESTAMP_FILE)
+               self.target_root = vardb.root
                self.LANGUAGE_ID = LANGUAGE_ID
-               self.config = config(config_root = os.environ.get("PORTAGE_CONFIGROOT", "/"),
-                               target_root = root, config_incrementals = INCREMENTALS)
-               self.vdb = vardbapi(settings = self.config, root = root,
-                       vartree = vartree(root = root, settings = self.config))
-               self.portdb = portdbapi(porttree_root = self.config["PORTDIR"], mysettings = self.config)
+               self.config = vardb.settings
+               self.vdb = vardb
+               self.portdb = portdb
 
                # Ensure that the unread path exists and is writable.
                dirmode  = 02070