From e8bf3d6e80cf3f29f7a07536eab68c32dcaf7f4b Mon Sep 17 00:00:00 2001 From: Richard Ipsum Date: Thu, 8 Jan 2015 14:23:10 +0000 Subject: Add package name comparison callback This lets the importer specify how package names will be compared, to do this the importer optionally supplies a callback, if no callback is supplied then the tool will default to == for string comparison. --- baserockimport/lorryset.py | 5 +++-- baserockimport/mainloop.py | 9 ++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/baserockimport/lorryset.py b/baserockimport/lorryset.py index 8cc73af..f252b9f 100644 --- a/baserockimport/lorryset.py +++ b/baserockimport/lorryset.py @@ -107,7 +107,7 @@ class LorrySet(object): '''Return the lorry entry for the named project.''' return {name: self.data[name]} - def find_lorry_for_package(self, kind, package_name): + def find_lorry_for_package(self, kind, package_name, comp): '''Find the lorry entry for a given foreign package, or return None. This makes use of an extension to the .lorry format made by the @@ -116,11 +116,12 @@ class LorrySet(object): named $KIND. ''' + key = 'x-products-%s' % kind for name, lorry in self.data.iteritems(): products = lorry.get(key, []) for entry in products: - if entry == package_name: + if comp(entry, package_name): return {name: lorry} return None diff --git a/baserockimport/mainloop.py b/baserockimport/mainloop.py index 057ab98..b9f1b9b 100644 --- a/baserockimport/mainloop.py +++ b/baserockimport/mainloop.py @@ -293,7 +293,14 @@ class ImportLoop(object): # files are named for project name rather than package name. In this # case we will generate the lorry, and try to add it to the set, at # which point LorrySet will notice the existing one and merge the two. - lorry = self.lorry_set.find_lorry_for_package(kind, name) + comp = None + + if 'package_comp_callback' in self.importers[kind]['kwargs']: + comp = self.importers[kind]['kwargs']['package_comp_callback'] + else: + comp = lambda x, y: x == y + + lorry = self.lorry_set.find_lorry_for_package(kind, name, comp) if lorry is None: lorry = self._generate_lorry_for_package(kind, name) -- cgit v1.2.1