import_layers: show basic progress

Show an info message with a counter when importing layers.

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
This commit is contained in:
Paul Eggleton 2019-08-06 11:54:24 +12:00
parent 54e51c26ac
commit 7953e7a853

View File

@ -129,7 +129,7 @@ def main():
try: try:
with transaction.atomic(): with transaction.atomic():
# Get layers # Get layers
logger.debug('Importing layers') logger.info('Importing layers')
rq = urllib.request.Request(layers_url) rq = urllib.request.Request(layers_url)
data = urllib.request.urlopen(rq).read() data = urllib.request.urlopen(rq).read()
jsdata = json.loads(data.decode('utf-8'), object_hook=datetime_hook) jsdata = json.loads(data.decode('utf-8'), object_hook=datetime_hook)
@ -287,7 +287,8 @@ def main():
existing_layerbranches = list(LayerBranch.objects.filter(branch__in=branch_idmap.values()).values_list('id', flat=True)) existing_layerbranches = list(LayerBranch.objects.filter(branch__in=branch_idmap.values()).values_list('id', flat=True))
exclude_fields = ['id', 'layer', 'branch', 'yp_compatible_version', 'updated'] exclude_fields = ['id', 'layer', 'branch', 'yp_compatible_version', 'updated']
for layerbranchjs in jsdata: layercount = len(jsdata)
for i, layerbranchjs in enumerate(jsdata):
branch = branch_idmap.get(layerbranchjs['branch'], None) branch = branch_idmap.get(layerbranchjs['branch'], None)
if not branch: if not branch:
# We don't have this branch, skip it # We don't have this branch, skip it
@ -308,11 +309,14 @@ def main():
logger.debug('Skipping layerbranch %s, already up-to-date' % layerbranchjs['id']) logger.debug('Skipping layerbranch %s, already up-to-date' % layerbranchjs['id'])
layerbranch_idmap[layerbranchjs['id']] = layerbranch layerbranch_idmap[layerbranchjs['id']] = layerbranch
continue continue
logger.info('Updating %s (%d/%d)' % (layerbranch, i+1, layercount))
else: else:
logger.info('Importing %s (%d/%d)' % (layerbranch, i+1, layercount))
layerbranch = LayerBranch() layerbranch = LayerBranch()
layerbranch.branch = branch layerbranch.branch = branch
layerbranch.layer = layer layerbranch.layer = layer
for key, value in layerbranchjs.items(): for key, value in layerbranchjs.items():
if key in exclude_fields: if key in exclude_fields:
continue continue
@ -380,7 +384,7 @@ def main():
layerbranch.delete() layerbranch.delete()
# Get layer dependencies # Get layer dependencies
logger.debug('Importing layer dependencies') logger.info('Importing layer dependencies')
rq = urllib.request.Request(layerdeps_url) rq = urllib.request.Request(layerdeps_url)
data = urllib.request.urlopen(rq).read() data = urllib.request.urlopen(rq).read()
jsdata = json.loads(data.decode('utf-8')) jsdata = json.loads(data.decode('utf-8'))