diff options
author | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2014-12-01 12:42:10 +0000 |
---|---|---|
committer | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2014-12-01 12:48:33 +0000 |
commit | a91acad94c602ff8a4fbfbd609856100f7e1e1ee (patch) | |
tree | 98f7d5ee32920f148f98223e8d968b77bba13b18 /baserockimport/lorryset.py | |
parent | ba2e3783917ca1768b0ef0e5b4c03c2ea4151385 (diff) | |
download | import-a91acad94c602ff8a4fbfbd609856100f7e1e1ee.tar.gz |
Give better errors when one .lorry duplicates another one
Now the tool gives the filenames of both files involved in the conflict.
The most likely reason for seeing this error is that, at least in
the lorries.git on git.baserock.org[1], the toplevel directory contains
some 'disabled' subdirectories, so the user needs to point --lorries-dir
to the correct subdirectory so that duplicate disabled lorries aren't
loaded.
This isn't really the final word on that problem, because having the
tool load disabled lorries is quite bad and if there are no conflicts
the user won't notice that it's happening and other confusing stuff
might occur. But hopefully it's good enough for now.
1. http://git.baserock.org/cgi-bin/cgit.cgi/baserock/local-config/lorries.git/tree/
Diffstat (limited to 'baserockimport/lorryset.py')
-rw-r--r-- | baserockimport/lorryset.py | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/baserockimport/lorryset.py b/baserockimport/lorryset.py index c3d109b..8cc73af 100644 --- a/baserockimport/lorryset.py +++ b/baserockimport/lorryset.py @@ -14,6 +14,7 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +import cliapp import morphlib import six @@ -22,10 +23,18 @@ import logging import os -class LorrySetError(Exception): +class LorrySetError(cliapp.AppException): pass +class DuplicateLorryError(LorrySetError): + def __init__(self, filename, existing_lorry_name, existing_lorry_file): + message = "%s: duplicates existing lorry '%s' from file %s" % ( + os.path.relpath(filename), existing_lorry_name, + os.path.relpath(existing_lorry_file)) + super(DuplicateLorryError, self).__init__(message) + + class LorrySet(object): '''Manages a set of .lorry files. @@ -64,6 +73,12 @@ class LorrySet(object): def _parse_all_lorries(self): lorry_set = {} + + # We keep track of which entry came from which file, but only while + # loading everything into memory (to allow us to give more helpful + # errors). + filenames = {} + for lorry_file in self.all_lorry_files(): lorry = self._parse_lorry(lorry_file) @@ -71,8 +86,9 @@ class LorrySet(object): for key, value in lorry_items: if key in lorry_set: - raise LorrySetError( - '%s: duplicates existing lorry %s' % (lorry_file, key)) + raise DuplicateLorryError(lorry_file, key, filenames[key]) + + filenames[key] = lorry_file lorry_set.update(lorry_items) |