-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paths3sync.py
36 lines (30 loc) · 1.11 KB
/
s3sync.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
import boto3
from pathlib import Path
def defineContentType(suffix):
contentType = ''
if suffix == ".js":
contentType = "application/javascript"
elif suffix == ".css":
contentType = "text/css"
elif suffix == ".html":
contentType = "text/html"
return contentType
s3 = boto3.client('s3')
staticFolder = Path("staticsite")
pathList = [['staticsite/index.html', 'index.html', 'text/html']]
requiredFolders = ["static/css", "static/images", "static/js"]
for x in staticFolder.iterdir():
if x.is_dir():
if x.name == "static":
for folder in requiredFolders:
subFolder = staticFolder / folder
for y in subFolder.iterdir():
contentType = defineContentType(y.suffix)
pathList.append([y.as_posix(), "{}/{}".format(folder, y.name), contentType])
else:
for y in x.iterdir():
contentType = defineContentType(y.suffix)
pathList.append([y.as_posix(), "{}/{}".format(x.name, y.name), contentType])
for path in pathList:
s3.upload_file(path[0], "chrxr-static-website-bucket", path[1], ExtraArgs={'ContentType': path[2]})
print("Uploaded files to S3")