layerindex/tools/import_layer.py: Avoid failing if there is any layer to add

Subdirectories are scanned when adding layers.  If any of the
subdirectories or root directory layers already exist in the database,
then the addition fails.  This changes that behaviour to report the
failure as a warning and remove it from the list.  That way, if a repo
has a new layer added it can be rescanned without issue.  Layers being
rescanned are checked against the vcs_url to ensure there is not a name
collision.  A name collision without the same vcs_url will still produce
a hard failure.

Note that multiple layers with the same vcs_url are supported in the
error reporting even though this should never happen.

Signed-off-by: Liam R. Howlett <Liam.Howlett@WindRiver.com>
This commit is contained in:
Liam R. Howlett 2016-08-31 12:52:43 -04:00 committed by Paul Eggleton
parent 4bbc210d34
commit 752e0152c2

View File

@ -334,8 +334,20 @@ def main():
else:
subdir = ''
if LayerItem.objects.filter(name=layer.name).exists():
logger.error('A layer named "%s" already exists in the database' % layer_name)
sys.exit(1)
if LayerItem.objects.filter(name=layer.name).exclude(vcs_url=layer.vcs_url).exists():
conflict_list = LayerItem.objects.filter(name=layer.name).exclude(vcs_url=layer.vcs_url)
conflict_list_urls = []
for conflict in conflict_list:
conflict_list_urls.append(conflict.vcs_url)
cln = ', '.join(conflict_list_urls)
logger.error('A layer named "%s" already exists in the database. Possible name collision with %s.vcs_url = %s' % (layer.name, layer.name, cln))
sys.exit(1)
else:
logger.info('The layer named "%s" already exists in the database. Skipping this layer with same vcs_url' % layer.name)
layer_paths = [x for x in layer_paths if x != layerdir]
continue
logger.info('Creating layer %s' % layer.name)
# Guess layer type
@ -411,6 +423,10 @@ def main():
layer.save()
if not layer_paths:
logger.error('No layers added.')
sys.exit(1);
if options.dryrun:
raise DryRunRollbackException()
except DryRunRollbackException: