diff options
author | Lars Wirzenius <liw@liw.fi> | 2014-02-15 22:00:02 +0000 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2014-02-15 22:00:02 +0000 |
commit | e1a114905ac49967c99cc26124cd7f37241b86a3 (patch) | |
tree | ba08b5b7420d31bc84b108caf12b8b2321081b3d /obnamlib/plugins/show_plugin.py | |
parent | eb1a40cc8e27964fb6531a3f960213a56cf7a5df (diff) | |
download | obnam-e1a114905ac49967c99cc26124cd7f37241b86a3.tar.gz |
Convert show_plugin.py to StructuredError
Diffstat (limited to 'obnamlib/plugins/show_plugin.py')
-rw-r--r-- | obnamlib/plugins/show_plugin.py | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/obnamlib/plugins/show_plugin.py b/obnamlib/plugins/show_plugin.py index 0a7f4b42..00f3886b 100644 --- a/obnamlib/plugins/show_plugin.py +++ b/obnamlib/plugins/show_plugin.py @@ -23,6 +23,21 @@ import time import obnamlib +class ClientDoesNotExistError(obnamlib.ObnamError): + + msg = 'Client {client} does not exist in repository {repo}' + + +class WrongNumberOfGenerationsForDiffError(obnamlib.ObnamError): + + msg = 'Need one or two generations' + + +class ShowFirstGenerationError(obnamlib.ObnamError): + + msg = "Can't show first generation. Use 'obnam ls' instead" + + class ShowPlugin(obnamlib.ObnamPlugin): '''Show information about data in the backup repository. @@ -73,9 +88,8 @@ class ShowPlugin(obnamlib.ObnamPlugin): client = self.app.settings['client-name'] clients = self.repo.get_client_names() if client not in clients: - raise obnamlib.Error( - 'Client %s does not exist in repository %s' % - (client, self.app.settings['repository'])) + raise ClientDoesNotExistError( + client=client, repo=self.app.settings['repository']) def clients(self, args): '''List clients using the repository.''' @@ -296,7 +310,7 @@ class ShowPlugin(obnamlib.ObnamPlugin): '''Show difference between two generations.''' if len(args) not in (1, 2): - raise obnamlib.Error('Need one or two generations') + raise WrongNumberOfGenerationsForDiffError() self.open_repository() client_name = self.app.settings['client-name'] @@ -307,8 +321,7 @@ class ShowPlugin(obnamlib.ObnamPlugin): genids = self.repo.get_client_generation_ids(client_name) index = genids.index(gen_id2) if index == 0: - raise obnamlib.Error( - 'Can\'t show first generation. Use \'ls\' instead') + raise ShowFirstGenerationError() gen_id1 = genids[index - 1] else: gen_id1 = self.repo.interpret_generation_spec( |