@@ -18,39 +18,11 @@ def __init__(self, s3Server, bucketName, accessKey, secretKey):
1818 self .accessKey = accessKey
1919 self .secretKey = secretKey
2020
21- self .connect ()
22-
23- # Add logging Info
24-
25- # Method to connect to s3 server
26- def connect (self ):
27- s3 = boto3 .client ('s3' , endpoint_url = self .s3Server ,
28- aws_access_key_id = self .accessKey ,
29- aws_secret_access_key = self .secretKey )
30-
31- self .s3 = s3
32-
33- # Add logging info
34-
35- # Method to close the client connection
36- def closeConnection (self ):
37- """
38- Closes the connection to the S3 client.
39- """
40- self .s3 .meta .client .close ()
41- logging .info ("Connection closed" )
42-
43- # Create folder structure
44- def createFolderStructure (self , structure = ["odtp" ]):
45- """
46- structure: is a list of paths to create. By default a single "odtp" folder
47- """
48-
49- for path in structure :
50- # Add a trailing slash to make S3 recognize it as a folder
51- self .s3 .put_object (Bucket = self .bucketName , Key = path + '/' )
52-
53- print ("Folder Structure Created" )
21+ self .s3 = boto3 .client (
22+ 's3' , endpoint_url = self .s3Server ,
23+ aws_access_key_id = self .accessKey ,
24+ aws_secret_access_key = self .secretKey
25+ )
5426
5527 # Method to create a specific folder
5628 # The idea is to create paths such as Digital Twin > Execution > Step > Output
@@ -82,60 +54,6 @@ def uploadFile(self, local_path, s3_path):
8254 self .s3 .upload_file (local_path , self .bucketName , s3_path )
8355 logging .info (f"File '{ local_path } ' uploaded to '{ s3_path } '" )
8456
85- # Method to download one file from s3 and place it in a folder
86- # This is needed to make the input/output logic out of barfi
87- def downloadFile (self , s3_path , local_path ):
88- """
89- Downloads a file from a specific path in the S3 bucket and saves it locally.
90-
91- Args:
92- s3_path (str): The S3 path of the file to download.
93- local_path (str): The local path where the file should be saved.
94-
95- Returns:
96- None
97- """
98- self .s3 .download_file (self .bucketName , s3_path , local_path )
99- logging .info (f"File '{ s3_path } ' downloaded to '{ local_path } '" )
100-
101- # Method to list folders in s3
102- def checkObjects (self ):
103-
104- response = self .s3 .list_objects_v2 (Bucket = self .bucketName ,
105- Delimiter = '/' )
106-
107- folders = []
108- if 'CommonPrefixes' in response :
109- for prefix in response ['CommonPrefixes' ]:
110- folders .append (prefix ['Prefix' ])
111-
112- return folders
113-
114- # Method to delete all objects in s3
115- def deleteAll (self ):
116-
117- bucket = self .s3 .Bucket (self .bucketName )
118-
119- # This will delete all objects in the bucket.
120- bucket .objects .all ().delete ()
121-
122- print ("Folder Structure Deleted" )
123-
124- # Method to delete one file in s3
125- def deleteFile (self , s3_path ):
126-
127- """
128- Deletes a file from a specific path in the S3 bucket.
129-
130- Args:
131- s3_path (str): The S3 path of the file to delete.
132-
133- Returns:
134- None
135- """
136- self .s3 .delete_object (Bucket = self .bucketName , Key = s3_path )
137- logging .info (f"File '{ s3_path } ' deleted from S3 bucket" )
138-
13957 def close (self ):
14058 del self .s3
14159 logging .info ("S3 Session deleted" )
0 commit comments