-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworkload.py
67 lines (49 loc) · 1.51 KB
/
workload.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from boto3 import client as boto3_client
import os
input_bucket = "cse546proj3-input"
output_bucket = "cse546proj3-output"
test_cases = "test_cases/"
def clear_input_bucket():
global input_bucket
s3 = boto3_client('s3')
list_obj = s3.list_objects_v2(Bucket=input_bucket)
try:
for item in list_obj["Contents"]:
key = item["Key"]
s3.delete_object(Bucket=input_bucket, Key=key)
except:
print("Nothing to clear in input bucket")
def clear_output_bucket():
global output_bucket
s3 = boto3_client('s3')
list_obj = s3.list_objects_v2(Bucket=output_bucket)
try:
for item in list_obj["Contents"]:
key = item["Key"]
s3.delete_object(Bucket=output_bucket, Key=key)
except:
print("Nothing to clear in output bucket")
def upload_to_input_bucket_s3(path, name):
global input_bucket
s3 = boto3_client('s3')
s3.upload_file(path + name, input_bucket, name)
def upload_files(test_case):
global input_bucket
global output_bucket
global test_cases
# Directory of test case
test_dir = test_cases + test_case + "/"
# Iterate over each video
# Upload to S3 input bucket
for filename in os.listdir(test_dir):
if filename.endswith(".mp4") or filename.endswith(".MP4"):
print("Uploading to input bucket.. name: " + str(filename))
upload_to_input_bucket_s3(test_dir, filename)
def workload_generator():
print("Running Test Case 1")
upload_files("test_case_1")
print("Running Test Case 2")
upload_files("test_case_2")
# clear_input_bucket()
clear_output_bucket()
workload_generator()