summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordol-sen <brian.dolbec@gmail.com>2011-10-26 16:17:06 -0700
committerdol-sen <brian.dolbec@gmail.com>2011-10-26 16:17:06 -0700
commit9a74747e60f08a6f303d36d45ad9bb2ba828af42 (patch)
treeaa29a5ecb0fce63462494014d3984f71a4e17403
parent25ae8b28da0632ed33935e32071c9aa683814da2 (diff)
downloadlayman-9a74747e60f08a6f303d36d45ad9bb2ba828af42.tar.gz
layman-9a74747e60f08a6f303d36d45ad9bb2ba828af42.tar.bz2
layman-9a74747e60f08a6f303d36d45ad9bb2ba828af42.zip
add news reporting capability when adding/syncing overlays. Bug 388233
-rwxr-xr-xlayman/api.py36
-rw-r--r--layman/cli.py4
-rw-r--r--layman/config.py2
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 = "Repo ID '%s' " + \
class LaymanAPI(object):
"""class to hold and run a layman instance for use by API consumer apps, guis, etc.
"""
- ## hell, even the current cli should probably be converted to use this one.
- ## It is a near duplicate of the actions classes.
def __init__(self, config=None, report_errors=False, output=None):
"""
@@ -126,12 +124,12 @@ class LaymanAPI(object):
return True
- def add_repos(self, repos):
+ def add_repos(self, repos, update_news=False):
"""installs the seleted repo id
@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 = self._check_repo_type(repos, "add_repo")
@@ -154,6 +152,9 @@ class LaymanAPI(object):
"' : "+str(e))
results.append(success)
self.get_installed(dbreload=True)
+ 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=verbose, width=width)
- def sync(self, repos, output_results=True):
+ def sync(self, repos, output_results=True, update_news=False):
"""syncs the specified repo(s) specified by repos
@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 = %s" % ', '.join(repos), 5)
@@ -387,6 +390,9 @@ class LaymanAPI(object):
self.sync_results = (success, warnings, fatals)
+ if update_news:
+ self.update_news(repos)
+
return fatals == []
@@ -522,6 +528,7 @@ class LaymanAPI(object):
return messages
return []
+
def supported_types(self):
"""returns a dictionary of all repository types,
with boolean values"""
@@ -534,6 +541,25 @@ class LaymanAPI(object):
return supported
+ def update_news(self, repos=None):
+ try:
+ if self.config['news_reporter'] == 'portage':
+ from _emerge.actions import (display_news_notification,
+ load_emerge_config)
+ settings, trees, mtimedb = load_emerge_config()
+ display_news_notification(trees[settings["ROOT"]]["root_config"],
+ {"news_repos": repos})
+ elif self.config['news_reporter'] == 'custom':
+ self.config['custom_news_func'](repos)
+ elif self.config['news_reporter'] == 'pkgcore':
+ return
+ except:
+ self._error("update_news() failed running %s news reporter function"
+ % 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 = self.api.get_available()
self.output.debug('Adding selected overlays', 6)
- result = self.api.add_repos(selection)
+ result = self.api.add_repos(selection, update_news=True)
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 = self.api.get_installed()
self.output.debug('Updating selected overlays', 6)
- result = self.api.sync(selection)
+ result = self.api.sync(selection, update_news=True)
# 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 = None