From a91acad94c602ff8a4fbfbd609856100f7e1e1ee Mon Sep 17 00:00:00 2001 From: Sam Thursfield Date: Mon, 1 Dec 2014 12:42:10 +0000 Subject: 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/ --- baserockimport/lorryset.py | 22 +++++++++++++++++++--- 1 file 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) -- cgit v1.2.1