@@ -65,14 +65,15 @@ def __init__(self, gitref, dlpath):
65
65
if not dry_run :
66
66
os .makedirs (self .dlpath , 0o755 )
67
67
68
- def collect_single_s3 (self , path ):
68
+ def collect_single_s3 (self , path , p_match = None ):
69
69
""" Collect single S3 artifact
70
70
:param: path string: S3 path
71
+ :param: p_match string: Optional p (project) tag to match
71
72
"""
72
73
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 ]
76
77
77
78
rinfo = re .findall (r'(?P<tag>[^-]+)-(?P<val>.*?)__' , folder )
78
79
if rinfo is None or len (rinfo ) == 0 :
@@ -81,6 +82,10 @@ def collect_single_s3(self, path):
81
82
82
83
info = dict (rinfo )
83
84
85
+ # Match project
86
+ if p_match is not None and info .get ('p' , '' ) != p_match :
87
+ return None
88
+
84
89
# Ignore AppVeyor Debug builds
85
90
if info .get ('bldtype' , '' ).lower () == 'debug' :
86
91
print ('Ignoring debug artifact %s' % folder )
@@ -101,14 +106,33 @@ def collect_single_s3(self, path):
101
106
102
107
return None
103
108
104
- def collect_s3 (self ):
109
+ def collect_s3 (self , s3_prefix , p_match = None ):
105
110
""" 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 ))
107
112
self .s3 = boto3 .resource ('s3' )
108
113
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 )
112
136
113
137
for a in self .artifacts :
114
138
a .download (self .dlpath )
@@ -142,7 +166,7 @@ def collect_local(self, path):
142
166
arts = Artifacts (gitref , args .directory )
143
167
144
168
if not args .no_s3 :
145
- arts .collect_s3 ()
169
+ arts .collect_s3 ('confluent-kafka-python/' , 'confluent-kafka-python' )
146
170
else :
147
171
arts .collect_local (arts .dlpath )
148
172
0 commit comments