From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1RJCkv-0004w7-Ne for garchives@archives.gentoo.org; Wed, 26 Oct 2011 23:19:33 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id AEF4721C091; Wed, 26 Oct 2011 23:19:21 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 6709821C03F for ; Wed, 26 Oct 2011 23:19:21 +0000 (UTC) Received: from pelican.gentoo.org (unknown [66.219.59.40]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 8C9071B4021 for ; Wed, 26 Oct 2011 23:19:20 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id A2BD180042 for ; Wed, 26 Oct 2011 23:19:19 +0000 (UTC) From: "Brian Dolbec" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Brian Dolbec" Message-ID: <9a74747e60f08a6f303d36d45ad9bb2ba828af42.dol-sen@gentoo> Subject: [gentoo-commits] proj/layman:master commit in: layman/ X-VCS-Repository: proj/layman X-VCS-Files: layman/api.py layman/cli.py layman/config.py X-VCS-Directories: layman/ X-VCS-Committer: dol-sen X-VCS-Committer-Name: Brian Dolbec X-VCS-Revision: 9a74747e60f08a6f303d36d45ad9bb2ba828af42 Date: Wed, 26 Oct 2011 23:19:19 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: X-Archives-Hash: c17da9323107b9d33bd9f3eef06a3668 commit: 9a74747e60f08a6f303d36d45ad9bb2ba828af42 Author: dol-sen gmail com> AuthorDate: Wed Oct 26 23:17:06 2011 +0000 Commit: Brian Dolbec gmail com> CommitDate: Wed Oct 26 23:17:06 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/layman.git;a=3D= commit;h=3D9a74747e add news reporting capability when adding/syncing overlays. Bug 388233 --- layman/api.py | 36 +++++++++++++++++++++++++++++++----- layman/cli.py | 4 ++-- layman/config.py | 2 ++ 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/layman/api.py b/layman/api.py index 3005c3f..cbf70e6 100755 --- a/layman/api.py +++ b/layman/api.py @@ -32,8 +32,6 @@ UNKNOWN_REPO_ID =3D "Repo ID '%s' " + \ class LaymanAPI(object): """class to hold and run a layman instance for use by API consumer a= pps, guis, etc. """ - ## hell, even the current cli should probably be converted to use th= is one. - ## It is a near duplicate of the actions classes. =20 def __init__(self, config=3DNone, report_errors=3DFalse, output=3DNo= ne): """ @@ -126,12 +124,12 @@ class LaymanAPI(object): return True =20 =20 - def add_repos(self, repos): + def add_repos(self, repos, update_news=3DFalse): """installs the seleted repo id =20 @type repos: list of strings or string @param repos: ['repo-id', ...] or 'repo-id' - @param output: method to handle output if desired + @param update_news: bool, defaults to False @rtype dict """ repos =3D self._check_repo_type(repos, "add_repo") @@ -154,6 +152,9 @@ class LaymanAPI(object): "' : "+str(e)) results.append(success) self.get_installed(dbreload=3DTrue) + if (True in results) and update_news: + self.update_news(repos) + if False in results: return False return True @@ -287,11 +288,13 @@ class LaymanAPI(object): return self._get_remote_db().list(verbose=3Dverbose, width=3D= width) =20 =20 - def sync(self, repos, output_results=3DTrue): + def sync(self, repos, output_results=3DTrue, update_news=3DFalse): """syncs the specified repo(s) specified by repos =20 @type repos: list of strings or string @param repos: ['repo-id1', ...] or 'repo-id' + @param output_results: bool, defaults to True + @param update_news: bool, defaults to False @rtype bool or {'repo-id': bool,...} """ self.output.debug("API.sync(); repos to sync =3D %s" % ', '.join= (repos), 5) @@ -387,6 +390,9 @@ class LaymanAPI(object): =20 self.sync_results =3D (success, warnings, fatals) =20 + if update_news: + self.update_news(repos) + return fatals =3D=3D [] =20 =20 @@ -522,6 +528,7 @@ class LaymanAPI(object): return messages return [] =20 + def supported_types(self): """returns a dictionary of all repository types, with boolean values""" @@ -534,6 +541,25 @@ class LaymanAPI(object): return supported =20 =20 + def update_news(self, repos=3DNone): + try: + if self.config['news_reporter'] =3D=3D 'portage': + from _emerge.actions import (display_news_notification, + load_emerge_config) + settings, trees, mtimedb =3D load_emerge_config() + display_news_notification(trees[settings["ROOT"]]["root_= config"], + {"news_repos": repos}) + elif self.config['news_reporter'] =3D=3D 'custom': + self.config['custom_news_func'](repos) + elif self.config['news_reporter'] =3D=3D 'pkgcore': + return + except: + self._error("update_news() failed running %s news reporter f= unction" + % self.config['news_reporter']) + return + + + def create_fd(): """creates file descriptor pairs an opens them ready for use in place of stdin, stdout, stderr. diff --git a/layman/cli.py b/layman/cli.py index 95ec858..b716ea0 100644 --- a/layman/cli.py +++ b/layman/cli.py @@ -230,7 +230,7 @@ class Main(object): if 'ALL' in selection: selection =3D self.api.get_available() self.output.debug('Adding selected overlays', 6) - result =3D self.api.add_repos(selection) + result =3D self.api.add_repos(selection, update_news=3DTrue) if result: self.output.info('Successfully added overlay(s) '+\ ', '.join(selection) +'.', 2) @@ -249,7 +249,7 @@ class Main(object): if self.config['sync_all'] or 'ALL' in selection: selection =3D self.api.get_installed() self.output.debug('Updating selected overlays', 6) - result =3D self.api.sync(selection) + result =3D self.api.sync(selection, update_news=3DTrue) # blank newline -- no " *" self.output.notice('') return result diff --git a/layman/config.py b/layman/config.py index 2af4069..c245853 100644 --- a/layman/config.py +++ b/layman/config.py @@ -95,6 +95,7 @@ class BareConfig(object): 'nocheck' : 'yes', 'proxy' : '', 'umask' : '0022', + 'news_reporter': 'portage', 'overlays' : 'http://www.gentoo.org/proj/en/overlays/repositories= .xml', 'overlay_defs': '%(configdir)s/overlays', @@ -144,6 +145,7 @@ class BareConfig(object): 'width': width, 'verbose': verbose, 'quiet': quiet, + 'custom_news_func': None, } self._set_quietness(quietness) self.config =3D None