def aggregate_file_tree_metadata(addon_short_name, fileobj_metadata, user):
 disk_usage = fileobj_metadata.get('size')
 if (fileobj_metadata['kind'] == 'file'):
  result = StatResult(target_name=fileobj_metadata['name'], target_id=fileobj_metadata['path'].lstrip('/'), disk_usage=(disk_usage or 0))
  return result
 else:
  return AggregateStatResult(target_id=fileobj_metadata['path'].lstrip('/'), target_name=fileobj_metadata['name'], targets=[aggregate_file_tree_metadata(addon_short_name, child, user) for child in fileobj_metadata.get('children', [])])

def aggregate_file_tree_metadata ( addon_short_name , fileobj_metadata , user ) : disk_usage = fileobj_metadata . get ( 'size' ) if ( fileobj_metadata [ 'kind' ] == 'file' ) : result = StatResult ( target_name = fileobj_metadata [ 'name' ] , target_id = fileobj_metadata [ 'path' ] . lstrip ( '/' ) , disk_usage = ( disk_usage or 0 ) ) return result else : return AggregateStatResult ( target_id = fileobj_metadata [ 'path' ] . lstrip ( '/' ) , target_name = fileobj_metadata [ 'name' ] , targets = [ aggregate_file_tree_metadata ( addon_short_name , child , user ) for child in fileobj_metadata . get ( 'children' , [ ] ) ] )
recursively traverse the addons file tree and collect metadata in aggregatestatresult .