Skip to content

Commit ba874b4

Browse files
committed
download-s3: only match confluent-kafka-python builds
And update S3 collector to handle more than 1000 objects in listing.
1 parent b5ca5d3 commit ba874b4

File tree

1 file changed

+34
-10
lines changed

1 file changed

+34
-10
lines changed

tools/download-s3.py

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,15 @@ def __init__(self, gitref, dlpath):
6565
if not dry_run:
6666
os.makedirs(self.dlpath, 0o755)
6767

68-
def collect_single_s3(self, path):
68+
def collect_single_s3(self, path, p_match=None):
6969
""" Collect single S3 artifact
7070
:param: path string: S3 path
71+
:param: p_match string: Optional p (project) tag to match
7172
"""
7273

73-
# The S3 folder contains the tokens needed to perform
74-
# matching of project, gitref, etc.
75-
folder = os.path.dirname(path)
74+
# The S3 folder (confluent-kafka-python/p-...__bld-../..) contains
75+
# the tokens needed to perform matching of project, gitref, etc.
76+
folder = path.split('/')[1]
7677

7778
rinfo = re.findall(r'(?P<tag>[^-]+)-(?P<val>.*?)__', folder)
7879
if rinfo is None or len(rinfo) == 0:
@@ -81,6 +82,10 @@ def collect_single_s3(self, path):
8182

8283
info = dict(rinfo)
8384

85+
# Match project
86+
if p_match is not None and info.get('p', '') != p_match:
87+
return None
88+
8489
# Ignore AppVeyor Debug builds
8590
if info.get('bldtype', '').lower() == 'debug':
8691
print('Ignoring debug artifact %s' % folder)
@@ -101,14 +106,33 @@ def collect_single_s3(self, path):
101106

102107
return None
103108

104-
def collect_s3(self):
109+
def collect_s3(self, s3_prefix, p_match=None):
105110
""" Collect and download build-artifacts from S3 based on git reference """
106-
print('Collecting artifacts matching tag/sha %s from S3 bucket %s' % (self.gitref, s3_bucket))
111+
print('Collecting artifacts matching %s from S3 bucket %s' % (self.gitref, s3_bucket))
107112
self.s3 = boto3.resource('s3')
108113
self.s3_bucket = self.s3.Bucket(s3_bucket)
109-
self.s3.meta.client.head_bucket(Bucket=s3_bucket)
110-
for key in self.s3_bucket.objects.all():
111-
self.collect_single_s3(key.key)
114+
self.s3_client = boto3.client('s3')
115+
116+
# note: list_objects will return at most 1000 objects per call,
117+
# use continuation token to read full list.
118+
cont_token = None
119+
more = True
120+
while more:
121+
if cont_token is not None:
122+
res = self.s3_client.list_objects_v2(Bucket=s3_bucket,
123+
Prefix=s3_prefix,
124+
ContinuationToken=cont_token)
125+
else:
126+
res = self.s3_client.list_objects_v2(Bucket=s3_bucket,
127+
Prefix=s3_prefix)
128+
129+
if res.get('IsTruncated') is True:
130+
cont_token = res.get('NextContinuationToken')
131+
else:
132+
more = False
133+
134+
for item in res.get('Contents'):
135+
self.collect_single_s3(item.get('Key'), p_match=p_match)
112136

113137
for a in self.artifacts:
114138
a.download(self.dlpath)
@@ -142,7 +166,7 @@ def collect_local(self, path):
142166
arts = Artifacts(gitref, args.directory)
143167

144168
if not args.no_s3:
145-
arts.collect_s3()
169+
arts.collect_s3('confluent-kafka-python/', 'confluent-kafka-python')
146170
else:
147171
arts.collect_local(arts.dlpath)
148172

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy