diff options
author | Brian Dolbec <brian.dolbec@gmail.com> | 2011-02-06 15:40:15 -0800 |
---|---|---|
committer | Brian Dolbec <brian.dolbec@gmail.com> | 2011-02-12 19:55:47 -0800 |
commit | 429281392d97880cb075456d85e878dc077e7d51 (patch) | |
tree | e77fc8646a5120796634aa1dfa3f8d4caeb8aa6c | |
parent | 43d5d08711fb4170b85505e3ec7edffc64cbf8e6 (diff) | |
download | layman-429281392d97880cb075456d85e878dc077e7d51.tar.gz layman-429281392d97880cb075456d85e878dc077e7d51.tar.bz2 layman-429281392d97880cb075456d85e878dc077e7d51.zip |
use the new message class and fix the error recording and output
-rw-r--r-- | layman/api.py | 43 | ||||
-rw-r--r-- | layman/cli.py | 3 | ||||
-rw-r--r-- | layman/config.py | 5 | ||||
-rw-r--r-- | layman/output.py (renamed from overlord/output.py) | 0 |
4 files changed, 27 insertions, 24 deletions
diff --git a/layman/api.py b/layman/api.py index 77e95d8..f3d68b6 100644 --- a/layman/api.py +++ b/layman/api.py @@ -19,10 +19,11 @@ import os from layman.config import BareConfig #from layman.action import Sync -from layman.dbbase import UnknownOverlayException +from layman.dbbase import UnknownOverlayException, UnknownOverlayMessage from layman.db import DB, RemoteDB #from layman.utils import path, delete_empty_directory -from layman.debug import OUT +#from layman.debug import OUT +from layman.output import OUT # give them some values for now, these are from the packagekit backend # TODO establish some proper errors for the api. @@ -114,11 +115,7 @@ class LaymanAPI(object): for ovl in repos: if not self.is_installed(ovl): results.append(True) - break - if not self.is_repo(ovl): - self._error(1, UNKNOWN_REPO_ID %ovl) - results.append(False) - break + continue try: self._get_installed_db().delete(self._get_installed_db().select(ovl)) results.append(True) @@ -145,11 +142,11 @@ class LaymanAPI(object): for ovl in repos: if self.is_installed(ovl): results.append(True) - break + continue if not self.is_repo(ovl): - self._error(1, UNKNOWN_REPO_ID %ovl) + self._error(UnknownOverlayMessage(ovl)) results.append(False) - break + continue try: self._get_installed_db().add(self._get_remote_db().select(ovl), quiet=True) results.append(True) @@ -199,12 +196,13 @@ class LaymanAPI(object): for ovl in repos: if not self.is_repo(ovl): - self._error(1, UNKNOWN_REPO_ID %ovl) + self._error(UnknownOverlayMessage(ovl)) result[ovl] = ('', False, False) + continue try: overlay = db.select(ovl) except UnknownOverlayException, error: - self._error(2, "Error: %s" %str(error)) + self._error(error) result[ovl] = ('', False, False) else: result[ovl] = { @@ -247,20 +245,21 @@ class LaymanAPI(object): for ovl in repos: if not self.is_repo(ovl): - self._error(1, UNKNOWN_REPO_ID % ovl) + self._error(UnknownOverlayMessage(ovl)) result[ovl] = ('', False, False) + continue try: overlay = db.select(ovl) #print "overlay = ", ovl - #print overlay + #print "!!!", overlay except UnknownOverlayException, error: #print "ERRORS", str(error) - self._error(2, "Error: %s" %str(error)) + self._error(error) result[ovl] = ('', False, False) else: # Is the overlay supported? if verbose: - info = overlay.__str__() + info = overlay.get_infostr() else: info = overlay.short_list(width) official = overlay.is_official() @@ -271,7 +270,7 @@ class LaymanAPI(object): def get_info_list(self, local=True, verbose=False, width=0): """retrieves the string representation of the recorded information - about the repo(s) specified by ovl + about the repo(s) @param local: bool (defaults to True) @param verbose: bool(defaults to False) @@ -303,7 +302,7 @@ class LaymanAPI(object): try: odb = db.select(ovl) except UnknownOverlayException, error: - self._error(1,"Sync(), failed to select %s overlay. Original error was: %s" %(ovl, str(error))) + self._error(UnknownOverlayException(error)) continue try: @@ -376,7 +375,7 @@ class LaymanAPI(object): try: self._get_remote_db().cache() except Exception, error: - self._error(-1,'Failed to fetch overlay list!\n Original Error was: ' + self._error('Failed to fetch overlay list!\n Original Error was: ' + str(error)) return False self.get_available(reload=True) @@ -417,13 +416,13 @@ class LaymanAPI(object): result = self.get_installed(reload=True) - def _error(self, num, message): + def _error(self, message): """outputs the error to the pre-determined output defaults to stderr. This method may be removed, is here for now due to code taken from the packagekit backend. """ - msg = "Error: %d," % num, message - self._error_messages.append(msg) + #msg = "Error: %d," % num, message + self._error_messages.append(message) if self.report_errors: print >>stderr, msg diff --git a/layman/cli.py b/layman/cli.py index dca6bb6..3277c1b 100644 --- a/layman/cli.py +++ b/layman/cli.py @@ -171,7 +171,8 @@ class Main(object): try: result += getattr(self, action[1])() except Exception, error: - self.output.error(self.api.get_errors()) + for _error in self.api.get_errors(): + self.output.error(_error) result = -1 # So it cannot remain 0, i.e. success break diff --git a/layman/config.py b/layman/config.py index 33951e7..e515155 100644 --- a/layman/config.py +++ b/layman/config.py @@ -31,7 +31,10 @@ import sys, ConfigParser import os from optparse import OptionParser, OptionGroup -from layman.debug import OUT + +#from layman.debug import OUT +from layman.output import OUT + from layman.version import VERSION #=============================================================================== diff --git a/overlord/output.py b/layman/output.py index 49ebb34..49ebb34 100644 --- a/overlord/output.py +++ b/layman/output.py |