summaryrefslogtreecommitdiffstats
path: root/layman
diff options
context:
space:
mode:
authordol-sen <brian.dolbec@gmail.com>2011-08-06 11:28:53 -0700
committerdol-sen <brian.dolbec@gmail.com>2011-08-06 11:28:53 -0700
commit341f69005710839bc984e414a823238c9329bd08 (patch)
tree257524244d6346eff71418cdd058996f1f1681a9 /layman
parentb99c5c5c78a8d2e1313ae91e25d3938c01aab9bc (diff)
downloadlayman-341f69005710839bc984e414a823238c9329bd08.tar.gz
layman-341f69005710839bc984e414a823238c9329bd08.tar.bz2
layman-341f69005710839bc984e414a823238c9329bd08.zip
add debug messages, fix error reporting in the api, refactor action & error processing/tracking.
Diffstat (limited to 'layman')
-rwxr-xr-xlayman/api.py45
-rw-r--r--layman/cli.py68
2 files changed, 77 insertions, 36 deletions
diff --git a/layman/api.py b/layman/api.py
index 869d882..a5045aa 100755
--- a/layman/api.py
+++ b/layman/api.py
@@ -112,7 +112,7 @@ class LaymanAPI(object):
results = []
for ovl in repos:
if not self.is_installed(ovl):
- self._error("Repository '"+ovl+"' was not installed")
+ self.output.error("Repository '"+ovl+"' was not installed")
results.append(False)
continue
success = False
@@ -142,11 +142,11 @@ class LaymanAPI(object):
results = []
for ovl in repos:
if self.is_installed(ovl):
- self._error("Repository '"+ovl+"' was already installed")
+ self.output.error("Repository '"+ovl+"' was already installed")
results.append(False)
continue
if not self.is_repo(ovl):
- self._error(UnknownOverlayMessage(ovl))
+ self.output.error(UnknownOverlayMessage(ovl))
results.append(False)
continue
success = False
@@ -199,7 +199,7 @@ class LaymanAPI(object):
for ovl in repos:
if not self.is_repo(ovl):
- self._error(UnknownOverlayMessage(ovl))
+ self.output.error(UnknownOverlayMessage(ovl))
result[ovl] = ('', False, False)
continue
try:
@@ -251,7 +251,7 @@ class LaymanAPI(object):
for ovl in repos:
if not self.is_repo(ovl):
- self._error(UnknownOverlayMessage(ovl))
+ self.output.error(UnknownOverlayMessage(ovl))
result[ovl] = ('', False, False)
continue
try:
@@ -298,26 +298,39 @@ class LaymanAPI(object):
@param repos: ['repo-id1', ...] or 'repo-id'
@rtype bool or {'repo-id': bool,...}
"""
+ self.output.debug("API.sync(); repos to sync = %s" % ', '.join(repos), 5)
fatals = []
warnings = []
success = []
repos = self._check_repo_type(repos, "sync")
db = self._get_installed_db()
+ self.output.debug("API.sync(); starting ovl loop", 5)
for ovl in repos:
+ self.output.debug("API.sync(); starting ovl = %s" %ovl, 5)
try:
+ self.output.debug("API.sync(); selecting %s, db = %s" % (ovl, str(db)), 5)
odb = db.select(ovl)
+ self.output.debug("API.sync(); %s now selected" %ovl, 5)
except UnknownOverlayException as error:
- self._error(UnknownOverlayException(error))
+ self.output.debug("API.sync(); UnknownOverlayException selecting %s" %ovl, 5)
+ self._error(str(error))
+ fatals.append((ovl,
+ 'Failed to select overlay "' + ovl + '".\nError was: '
+ + str(error)))
+ self.output.debug("API.sync(); UnknownOverlayException "
+ "selecting %s. continuing to next ovl..." %ovl, 5)
continue
try:
+ self.output.debug("API.sync(); try: self._get_remote_db().select(ovl)", 5)
ordb = self._get_remote_db().select(ovl)
except UnknownOverlayException:
message = 'Overlay "%s" could not be found in the remote lists.\n' \
'Please check if it has been renamed and re-add if necessary.' % ovl
warnings.append((ovl, message))
else:
+ self.output.debug("API.sync(); else: self._get_remote_db().select(ovl)", 5)
current_src = odb.sources[0].src
available_srcs = set(e.src for e in ordb.sources)
if ordb and odb and not current_src in available_srcs:
@@ -348,6 +361,7 @@ class LaymanAPI(object):
}))
try:
+ self.output.debug("API.sync(); starting db.sync(ovl)", 5)
db.sync(ovl, self.config['quiet'])
success.append((ovl,'Successfully synchronized overlay "' + ovl + '".'))
except Exception as error:
@@ -357,19 +371,22 @@ class LaymanAPI(object):
if output_results:
if success:
- self.output.info('\nSucceeded:\n------\n', 3)
+ message = '\nSucceeded:\n------\n'
for ovl, result in success:
- self.output.info(result, 3)
+ message += result + '\n'
+ self.output.info(message, 3)
if warnings:
- self.output.warn('\nWarnings:\n------\n', 2)
+ message = '\nWarnings:\n------\n'
for ovl, result in warnings:
- self.output.warn(result + '\n', 2)
+ message += result + '\n'
+ self.output.warn(message, 2)
if fatals:
- self.output.error('\nErrors:\n------\n')
+ message = '\nErrors:\n------\n'
for ovl, result in fatals:
- self.output.error(result + '\n')
+ message += result + '\n'
+ self.output.error(message)
self.sync_results = (success, warnings, fatals)
@@ -434,7 +451,7 @@ class LaymanAPI(object):
'LaymanAPI.fetch_remote_list(); cache updated = %s'
% str(dbreload),8)
except Exception as error:
- self._error('Failed to fetch overlay list!\n Original Error was: '
+ self.output.error('Failed to fetch overlay list!\n Original Error was: '
+ str(error))
return False
self.get_available(dbreload)
@@ -483,6 +500,7 @@ class LaymanAPI(object):
due to code taken from the packagekit backend.
"""
self._error_messages.append(message)
+ self.output.debug("API._error(); _error_messages = %s" % str(self._error_messages), 4)
if self.report_errors:
print(message, file=self.config['stderr'])
@@ -494,6 +512,7 @@ class LaymanAPI(object):
@rtype: list
@return: list of error strings
"""
+ self.output.debug("API.get_errors(); _error_messages = %s" % str(self._error_messages), 4)
if len(self._error_messages):
messages = self._error_messages[:]
self._error_messages = []
diff --git a/layman/cli.py b/layman/cli.py
index 5618d49..f545b0e 100644
--- a/layman/cli.py
+++ b/layman/cli.py
@@ -135,7 +135,7 @@ class Main(object):
#print("config.keys()", config.keys())
self.output = config['output']
self.api = LaymanAPI(config,
- report_errors=True,
+ report_errors=False,
output=config.output)
# Given in order of precedence
self.actions = [('fetch', 'Fetch'),
@@ -148,6 +148,8 @@ class Main(object):
('list_local', 'ListLocal'),]
def __call__(self):
+ self.output.debug("CLI.__call__(): self.config.keys()"
+ " %s" % str(self.config.keys()), 6)
# Make fetching the overlay list a default action
if not 'nofetch' in self.config.keys():
# Actions that implicitely call the fetch operation before
@@ -169,23 +171,41 @@ class Main(object):
self.output.die('Failed setting to umask "' + umask +
'"!\nError was: ' + str(error))
+ action_errors = []
+ results = []
+ act=set([x[0] for x in self.actions])
+ k=set([x for x in self.config.keys()])
+ a=act.intersection(k)
+ self.output.debug('Actions = %s' % str(a), 4)
for action in self.actions:
- self.output.debug('Checking for action', 7)
+ self.output.debug('Checking for action %s' % action[0], 4)
if action[0] in self.config.keys():
- try:
- result += getattr(self, action[1])()
- except Exception as error:
- for _error in self.api.get_errors():
- self.output.error(_error)
+ result += getattr(self, action[1])()
+ _errors = self.api.get_errors()
+ if _errors:
+ self.output.debug("CLI: found errors performing "
+ "action %s" % action[0], 2)
+ action_errors.append((action[0], _errors))
result = -1 # So it cannot remain 0, i.e. success
- break
+ results.append(result)
+ self.output.debug('Completed action %s, result %s'
+ % (action[0], result==0), 4)
+
+ self.output.debug('Checking for action errors', 4)
+ if action_errors:
+ for action, _errors in action_errors:
+ self.output.notice("\n")
+ self.output.warn("CLI: Errors occured processing action"
+ " %s" % action)
+ for _error in _errors:
+ self.output.error(_error)
# Reset umask
os.umask(old_umask)
- if not result:
+ if -1 in results:
sys.exit(FAILURE)
else:
sys.exit(SUCCEED)
@@ -194,20 +214,21 @@ class Main(object):
def Fetch(self):
''' Fetches the overlay listing.
'''
- self.output.info("Fetching remote list,...", 2)
+ self.output.info("\nFetching remote list,...", 2)
result = self.api.fetch_remote_list()
if result:
self.output.info('Fetch Ok', 2)
- else:
- errors = self.api.get_errors()
- self.output.warn('Download failed.\nError was: '
- + str('\n'.join(errors)), 2)
+ #else:
+ # errors = self.api.get_errors()
+ # self.output.warn('Download failed.\nError was: '
+ # + str('\n'.join(errors)), 2)
return result
def Add(self):
''' Adds the selected overlays.
'''
+ self.output.info("\nAdding overlay,...", 2)
selection = decode_selection(self.config['add'])
if 'ALL' in selection:
selection = self.api.get_available()
@@ -216,10 +237,10 @@ class Main(object):
if result:
self.output.info('Successfully added overlay(s) '+\
', '.join(selection) +'.', 2)
- else:
- errors = self.api.get_errors()
- self.output.warn('Failed to add overlay(s).\nError was: '
- + str('\n'.join(errors)), 2)
+ #else:
+ # errors = self.api.get_errors()
+ # self.output.warn('Failed to add overlay(s).\nError was: '
+ # + str('\n'.join(errors)), 2)
return result
@@ -227,6 +248,7 @@ class Main(object):
def Sync(self):
''' Syncs the selected overlays.
'''
+ self.output.info("\nSyncing selected overlays,...", 2)
# Note api.sync() defaults to printing results
selection = decode_selection(self.config['sync'])
if self.config['sync_all'] or 'ALL' in selection:
@@ -238,18 +260,18 @@ class Main(object):
def Delete(self):
''' Deletes the selected overlays.
'''
+ self.output.info('\nDeleting selected overlays,...', 2)
selection = decode_selection(self.config['delete'])
if 'ALL' in selection:
selection = self.api.get_installed()
- self.output.debug('Deleting selected overlays', 6)
result = self.api.delete_repos(selection)
if result:
self.output.info('Successfully deleted overlay(s) ' +\
', '.join(selection) + '.', 2)
- else:
- errors = self.api.get_errors()
- self.output.warn('Failed to delete overlay(s).\nError was: '
- + str('\n'.join(errors)), 2)
+ #else:
+ # errors = self.api.get_errors()
+ # self.output.warn('Failed to delete overlay(s).\nError was: '
+ # + str('\n'.join(errors)), 2)
return result