import_layers: allow filtering layers

Add an option to import only certain layers - mostly for debugging
(can make testing a lot quicker).

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
This commit is contained in:
Paul Eggleton 2019-08-06 09:40:16 +12:00
parent 8501a6da40
commit 0d62b19a38

View File

@ -12,7 +12,6 @@ import sys
import os import os
import argparse import argparse
import re import re
import glob
import logging import logging
import subprocess import subprocess
import urllib.request import urllib.request
@ -44,6 +43,7 @@ def main():
parser = argparse.ArgumentParser(description="Layer index import utility. Imports layer information from another layer index instance using the REST API. WARNING: this will overwrite data in your database, use with caution!") parser = argparse.ArgumentParser(description="Layer index import utility. Imports layer information from another layer index instance using the REST API. WARNING: this will overwrite data in your database, use with caution!")
parser.add_argument('url', help='Layer index URL to fetch from') parser.add_argument('url', help='Layer index URL to fetch from')
parser.add_argument('-b', '--branch', action='store', help='Restrict to import a specific branch only (separate multiple branches with commas)') parser.add_argument('-b', '--branch', action='store', help='Restrict to import a specific branch only (separate multiple branches with commas)')
parser.add_argument('-l', '--layer', action='store', help='Restrict to import a specific layer only (regular expressions allowed)')
parser.add_argument('-n', '--dry-run', action='store_true', help="Don't write any data back to the database") parser.add_argument('-n', '--dry-run', action='store_true', help="Don't write any data back to the database")
parser.add_argument('-d', '--debug', action='store_true', help='Enable debug output') parser.add_argument('-d', '--debug', action='store_true', help='Enable debug output')
parser.add_argument('-q', '--quiet', action='store_true', help='Hide all output except error messages') parser.add_argument('-q', '--quiet', action='store_true', help='Hide all output except error messages')
@ -120,6 +120,11 @@ def main():
else: else:
logger.debug('Skipping branch %s, not in database' % branchjs['name']) logger.debug('Skipping branch %s, not in database' % branchjs['name'])
if args.layer:
layer_re = re.compile('^' + args.layer + '$')
else:
layer_re = None
try: try:
with transaction.atomic(): with transaction.atomic():
# Get layers # Get layers
@ -131,6 +136,10 @@ def main():
layer_idmap = {} layer_idmap = {}
exclude_fields = ['id', 'updated'] exclude_fields = ['id', 'updated']
for layerjs in jsdata: for layerjs in jsdata:
if layer_re and not layer_re.match(layerjs['name']):
logger.debug('Skipping layer %s, does not match layer restriction' % layerjs['name'])
continue
layeritem = LayerItem.objects.filter(name=layerjs['name']).first() layeritem = LayerItem.objects.filter(name=layerjs['name']).first()
if layeritem: if layeritem:
# Already have this layer # Already have this layer