@@ -24,19 +24,20 @@ def __init__(
24
24
)
25
25
with pip_find_lock :
26
26
try :
27
- from boto . s3 . connection import S3Connection
27
+ import boto3
28
28
except Exception :
29
- shared_utils .pip_install ("boto" , version = "2.49.0" )
30
- from boto .s3 .connection import S3Connection
31
- self .conn = S3Connection (selenium_access_key , selenium_secret_key )
32
- self .bucket = self .conn .get_bucket (log_bucket )
29
+ shared_utils .pip_install ("boto3" )
30
+ import boto3
31
+ self .conn = boto3 .Session (
32
+ aws_access_key_id = selenium_access_key ,
33
+ aws_secret_access_key = selenium_secret_key ,
34
+ )
35
+ self .bucket = log_bucket
33
36
self .bucket_url = bucket_url
34
37
35
38
def get_key (self , file_name ):
36
- """Create a new Key instance with the given name."""
37
- from boto .s3 .key import Key
38
-
39
- return Key (bucket = self .bucket , name = file_name )
39
+ """Create a new S3 connection instance with the given name."""
40
+ return self .conn .resource ("s3" ).Object (self .bucket , file_name )
40
41
41
42
def get_bucket (self ):
42
43
"""Return the bucket being used."""
@@ -53,18 +54,19 @@ def upload_file(self, file_name, file_path):
53
54
content_type = "image/jpeg"
54
55
elif file_name .endswith (".png" ):
55
56
content_type = "image/png"
56
- upload_key .set_contents_from_filename (
57
- file_path , headers = {"Content-Type" : content_type }
57
+ upload_key .Bucket ().upload_file (
58
+ file_path ,
59
+ file_name ,
60
+ ExtraArgs = {"ACL" : "public-read" , "ContentType" : content_type },
58
61
)
59
- upload_key .url = upload_key .generate_url (expires_in = 3600 ).split ("?" )[0 ]
60
- try :
61
- upload_key .make_public ()
62
- except Exception :
63
- pass
64
62
65
- def upload_index_file (self , test_address , timestamp ):
63
+ def upload_index_file (
64
+ self , test_address , timestamp , data_path , save_data_to_logs
65
+ ):
66
66
"""Create an index.html file with links to all the log files
67
67
that were just uploaded."""
68
+ import os
69
+
68
70
global already_uploaded_files
69
71
already_uploaded_files = list (set (already_uploaded_files ))
70
72
already_uploaded_files .sort ()
@@ -76,15 +78,19 @@ def upload_index_file(self, test_address, timestamp):
76
78
"<a href='" + self .bucket_url + ""
77
79
"%s'>%s</a>" % (completed_file , completed_file )
78
80
)
79
- index .set_contents_from_string (
80
- "<br>" .join (index_str ), headers = {"Content-Type" : "text/html" }
81
+ index_page = str ("<br>" .join (index_str ))
82
+ save_data_to_logs (index_page , "index.html" )
83
+ file_path = os .path .join (data_path , "index.html" )
84
+ index .Bucket ().upload_file (
85
+ file_path ,
86
+ file_name ,
87
+ ExtraArgs = {"ACL" : "public-read" , "ContentType" : "text/html" },
81
88
)
82
- index .make_public ()
83
89
return "%s%s" % (self .bucket_url , file_name )
84
90
85
91
def save_uploaded_file_names (self , files ):
86
- """Keep a record of all file names that have been uploaded. Upload log
87
- files related to each test after its execution. Once done, use
88
- already_uploaded_files to create an index file."""
92
+ """Keep a record of all file names that have been uploaded.
93
+ Upload log files related to each test after its execution.
94
+ Once done, use already_uploaded_files to create an index file."""
89
95
global already_uploaded_files
90
96
already_uploaded_files .extend (files )
0 commit comments