MCPcopy Index your code
hub / github.com/diffgram/diffgram / __count_objects

Method __count_objects

shared/connection/s3_connector.py:445–466  ·  view source on GitHub ↗
(self, opts)

Source from the content-addressed store, hash-verified

443 @with_connection
444 @with_s3_exception_handler
445 def __count_objects(self, opts):
446 spec_list = [{'bucket_name': str, 'path': str}]
447 log = regular_log.default()
448 log, input = regular_input.input_check_many(untrusted_input = opts,
449 spec_list = spec_list,
450 log = log)
451 if len(log["error"].keys()) >= 1:
452 return {'log': log}
453 count = 0
454 kwargs = {'Bucket': opts['bucket_name'], 'Prefix': opts['path']}
455 while True:
456 resp = self.connection_client.list_objects_v2(**kwargs)
457 all_objs = resp.get('Contents', [])
458 only_files = list(filter(lambda x: not x.get('Key', '/').endswith('/'), all_objs))
459 count += len(only_files)
460 if count >= 10000:
461 return {'result': '10,000+'}
462 try:
463 kwargs['ContinuationToken'] = resp['NextContinuationToken']
464 except KeyError:
465 break
466 return {'result': count}
467
468 @with_connection
469 @with_s3_exception_handler

Callers 1

fetch_dataMethod · 0.95

Calls 1

getMethod · 0.45

Tested by

no test coverage detected