diff options
author | Sebastian Pipping <sebastian@pipping.org> | 2010-01-28 00:47:32 +0100 |
---|---|---|
committer | Sebastian Pipping <sebastian@pipping.org> | 2010-01-28 00:47:32 +0100 |
commit | c654e79fd18adb0e9f1cae6b783f8c81b39dda61 (patch) | |
tree | d2f5ac9626de063a10e546a7a4132cbddd9cfa26 /layman | |
parent | a223dc2c467cc05932aa5e42bdd905dd6aa83037 (diff) | |
download | layman-c654e79fd18adb0e9f1cae6b783f8c81b39dda61.tar.gz layman-c654e79fd18adb0e9f1cae6b783f8c81b39dda61.tar.bz2 layman-c654e79fd18adb0e9f1cae6b783f8c81b39dda61.zip |
Fix handling of non-existing overlays
Diffstat (limited to 'layman')
-rw-r--r-- | layman/action.py | 53 | ||||
-rw-r--r-- | layman/db.py | 16 | ||||
-rw-r--r-- | layman/overlay.py | 14 |
3 files changed, 47 insertions, 36 deletions
diff --git a/layman/action.py b/layman/action.py index d058e9c..0cd55f6 100644 --- a/layman/action.py +++ b/layman/action.py @@ -26,7 +26,7 @@ __version__ = "$Id: action.py 312 2007-04-09 19:45:49Z wrobel $" import os, sys -from layman.db import DB, RemoteDB +from layman.db import DB, RemoteDB, UnknownOverlayException from layman.debug import OUT @@ -113,13 +113,18 @@ class Sync: success = [] for i in self.selection: try: + odb = self.db.select(i) + except UnknownOverlayException, error: + fatals.append(str(error)) + continue + + try: ordb = self.rdb.select(i) - except: + except UnknownOverlayException: warnings.append(\ 'Overlay "%s" could not be found in the remote lists.\n' 'Please check if it has been renamed and re-add if necessary.' % i) else: - odb = self.db.select(i) 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: @@ -210,11 +215,13 @@ class Add: result = 0 for i in self.selection: - overlay = self.rdb.select(i) - - OUT.debug('Selected overlay', 7) - - if overlay: + try: + overlay = self.rdb.select(i) + except UnknownOverlayException, error: + OUT.warn(str(error), 2) + result = 1 + else: + OUT.debug('Selected overlay', 7) try: self.db.add(overlay, self.quiet) OUT.info('Successfully added overlay "' + i + '".', 2) @@ -222,9 +229,6 @@ class Add: OUT.warn('Failed to add overlay "' + i + '".\nError was: ' + str(error), 2) result = 1 - else: - OUT.warn('Overlay "' + i + '" does not exist!', 2) - result = 1 return result @@ -258,11 +262,13 @@ class Delete: result = 0 for i in self.selection: - overlay = self.db.select(i) - - OUT.debug('Selected overlay', 7) - - if overlay: + try: + overlay = self.db.select(i) + except UnknownOverlayException, error: + OUT.warn(str(error), 2) + result = 1 + else: + OUT.debug('Selected overlay', 7) try: self.db.delete(overlay) OUT.info('Successfully deleted overlay "' + i + '".', 2) @@ -270,9 +276,6 @@ class Delete: OUT.warn('Failed to delete overlay "' + i + '".\nError was: ' + str(error), 2) result = 1 - else: - OUT.warn('Overlay "' + i + '" does not exist!', 2) - result = 1 return result @@ -337,9 +340,12 @@ class Info: result = 0 for i in self.selection: - overlay = self.rdb.select(i) - - if overlay: + try: + overlay = self.rdb.select(i) + except UnknownOverlayException, error: + OUT.warn(str(error), 2) + result = 1 + else: # Is the overlay supported? OUT.info(overlay.__str__(), 1) if not overlay.is_official(): @@ -347,9 +353,6 @@ class Info: if not overlay.is_supported(): OUT.error('*** You are lacking the necessary tools to install t' 'his overlay ***\n') - else: - OUT.warn('Overlay "' + i + '" does not exist!', 2) - result = 1 return result diff --git a/layman/db.py b/layman/db.py index 3fde214..252e81a 100644 --- a/layman/db.py +++ b/layman/db.py @@ -27,7 +27,7 @@ __version__ = "$Id: db.py 309 2007-04-09 16:23:38Z wrobel $" import os, codecs, os.path, urllib2, re, hashlib from layman.utils import path -from layman.overlay import Overlays +from layman.overlay import Overlays, UnknownOverlayException from layman.debug import OUT @@ -189,15 +189,11 @@ class DB(Overlays): def sync(self, overlay_name, quiet = False): '''Synchronize the given overlay.''' - overlay = self.select(overlay_name) - - if overlay: - result = overlay.sync(self.config['storage'], quiet) - if result: - raise Exception('Syncing overlay "' + overlay_name + - '" returned status ' + str(result) + '!') - else: - raise Exception('No such overlay ("' + overlay_name + '")!') + overlay = self.select(overlay_name) # UnknownOverlayException + result = overlay.sync(self.config['storage'], quiet) + if result: + raise Exception('Syncing overlay "' + overlay_name + + '" returned status ' + str(result) + '!') #=============================================================================== # diff --git a/layman/overlay.py b/layman/overlay.py index 1058723..21bbc70 100644 --- a/layman/overlay.py +++ b/layman/overlay.py @@ -37,6 +37,18 @@ from layman.overlays.overlay import Overlay #=============================================================================== # +# Class UnknownOverlayException +# +#------------------------------------------------------------------------------- + +class UnknownOverlayException(Exception): + def __init__(self, repo_name): + message = 'Overlay "%s" does not exist.' % repo_name + super(UnknownOverlayException, self).__init__(message) + + +#=============================================================================== +# # Class Overlays # #------------------------------------------------------------------------------- @@ -150,7 +162,7 @@ class Overlays: [u'rsync://gunnarwrobel.de/wrobel-stable'] ''' if not overlay in self.overlays.keys(): - raise Exception('No overlay "%s" in database' % overlay) + raise UnknownOverlayException(overlay) return self.overlays[overlay] def list(self, verbose = False, width = 0): |