def display_news_notification(root_config, myopts): if "news" not in root_config.settings.features: return portdb = root_config.trees["porttree"].dbapi vardb = root_config.trees["vartree"].dbapi news_counts = count_unread_news(portdb, vardb) display_news_notifications(news_counts)
def display_news_notification(root_config, myopts): if "news" not in root_config.settings.features: return False portdb = root_config.trees["porttree"].dbapi vardb = root_config.trees["vartree"].dbapi news_counts = count_unread_news(portdb, vardb) if all(v == 0 for v in news_counts.values()): return False display_news_notifications(news_counts) return True
def update_news(self, repos=None): try: if self.config['news_reporter'] == 'portage': try: from portage import db, root from portage.news import count_unread_news, \ display_news_notifications portdb = db[root]["porttree"].dbapi vardb = db[root]["vartree"].dbapi # get the actual repo_name from portage # because it may be different than layman's name for it repo_names = [] for repo in repos: if isinstance(repo, bytes): repo = repo.decode('UTF-8') ovl = self._get_installed_db().select(repo) ovl_path = os.path.join(ovl.config['storage'], repo) name = portdb.getRepositoryName(ovl_path) if name: repo_names.append(name) self.output.debug( "LaymanAPI: update_news(); repo_names = " + str(repo_names), 4) news_counts = count_unread_news(portdb, vardb, repo_names) display_news_notifications(news_counts) except ImportError: # deprecated funtionality, remove when the above method # is available in all portage versions self.output.info( "New portage news functionality not " "available, using fallback method", 5) from _emerge.actions import (display_news_notification, load_emerge_config) settings, trees, mtimedb = load_emerge_config() display_news_notification( trees[settings["ROOT"]]["root_config"], {}) elif self.config['news_reporter'] == 'custom': if self.config['custom_news_func'] is None: _temp = __import__('custom_news_pkg', globals(), locals(), ['layman_news_func'], -1) self.config['custom_news_func'] = _temp.custom_news_func self.config['custom_news_func'](repos) elif self.config['news_reporter'] == 'pkgcore': # pkgcore is not yet capable return except Exception as err: msg = "update_news() failed running %s news reporter function\n" +\ "Error was; %s" self._error(msg % (self.config['news_reporter'], err)) return
def update_news(self, repos=None): try: if self.config['news_reporter'] == 'portage': try: from portage import db, root from portage.news import count_unread_news, \ display_news_notifications portdb = db[root]["porttree"].dbapi vardb = db[root]["vartree"].dbapi # get the actual repo_name from portage # because it may be different than layman's name for it repo_names = [] for repo in repos: if isinstance(repo, bytes): repo = repo.decode('UTF-8') ovl = self._get_installed_db().select(repo) ovl_path = os.path.join(ovl.config['storage'], repo) name = portdb.getRepositoryName(ovl_path) if name: repo_names.append(name) self.output.debug("LaymanAPI: update_news(); repo_names = " + str(repo_names), 4) news_counts = count_unread_news(portdb, vardb, repo_names) display_news_notifications(news_counts) except ImportError: # deprecated funtionality, remove when the above method # is available in all portage versions self.output.info("New portage news functionality not " "available, using fallback method", 5) from _emerge.actions import (display_news_notification, load_emerge_config) settings, trees, mtimedb = load_emerge_config() display_news_notification( trees[settings["ROOT"]]["root_config"], {}) elif self.config['news_reporter'] == 'custom': if self.config['custom_news_func'] is None: _temp = __import__( 'custom_news_pkg', globals(), locals(), ['layman_news_func'], -1) self.config['custom_news_func'] = _temp.custom_news_func self.config['custom_news_func'](repos) elif self.config['news_reporter'] == 'pkgcore': # pkgcore is not yet capable return except Exception as err: msg = "update_news() failed running %s news reporter function\n" +\ "Error was; %s" self._error(msg % (self.config['news_reporter'], err)) return