in scripts/yapl/LogExporter.py [0:0]
def exportLogs(self, logsDirectoryPath):
"""
Export the deployment logs to the S3 bucket of this LogExporter.
Each log will be exported using a path with the keyPrefix at the root
followed by the role and FQDN and ending with the log file name as the
last element of the S3 object key.
"""
methodName = "exportLogs"
if (not os.path.exists(logsDirectoryPath)):
if (TR.isLoggable(Level.FINE)):
TR.fine(methodName, "Logs directory: %s does not exist." % logsDirectoryPath)
#endIf
else:
logFileNames = os.listdir(logsDirectoryPath)
if (not logFileNames):
if (TR.isLoggable(Level.FINE)):
TR.fine(methodName,"No log files in %s" % logsDirectoryPath)
#endIf
else:
for fileName in logFileNames:
bodyPath = os.path.join(logsDirectoryPath,fileName)
if (os.path.isfile(bodyPath)):
s3Key = "%s/%s/%s" % (self.keyPrefix,self.fqdn,fileName)
if (TR.isLoggable(Level.FINE)):
TR.fine(methodName,"Exporting log: %s to S3: %s:%s" % (bodyPath,self.bucket,s3Key))
#endIf
with open(bodyPath, 'r') as bodyFile:
self.s3Helper.put_object(Bucket=self.bucket,Key=s3Key,Body=bodyFile)