diff options
author | Richard Ipsum <richard.ipsum@codethink.co.uk> | 2015-01-08 14:23:10 +0000 |
---|---|---|
committer | Richard Ipsum <richard.ipsum@codethink.co.uk> | 2015-01-12 11:57:46 +0000 |
commit | e8bf3d6e80cf3f29f7a07536eab68c32dcaf7f4b (patch) | |
tree | 97fcb2764b56cba432eff76ba4cb9ef1abecbcf4 /baserockimport | |
parent | 827e9904332dbd17341648be81bcf2388d241ad4 (diff) | |
download | import-e8bf3d6e80cf3f29f7a07536eab68c32dcaf7f4b.tar.gz |
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.
Diffstat (limited to 'baserockimport')
-rw-r--r-- | baserockimport/lorryset.py | 5 | ||||
-rw-r--r-- | 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) |