forked from lpalbou/aws-js-s3-explorer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
s3_add_index.py
54 lines (39 loc) · 1.2 KB
/
s3_add_index.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
import os, sys, getopt, boto3
from botocore.exceptions import NoCredentialsError
from s3_add_file import copy_file
def rewrite_index(in_file, out_file, bucket_name):
file = open(in_file, "r")
line = file.readline()
lines = []
while line:
if "s3exp_config.Bucket = " in line:
line = line[0:line.index("\"")] + "\"" + bucket_name + "\"\n"
lines.append(line)
line = file.readline()
file.close()
custom_index = "".join(lines)
file = open(out_file, "w")
file.write(custom_index)
file.close()
def print_help():
print('\nUsage: python s3-add-custom-index.py -o <s3:bucket_name>\n')
def main(argv):
s3_bucket = ''
if len(argv) < 2:
print_help()
sys.exit(2)
try:
opts, argv = getopt.getopt(argv,"o:", ["output="])
except getopt.GetoptError:
print_help()
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print_help()
sys.exit()
elif opt in ("-o", "--output"):
s3_bucket = arg
rewrite_index("index.html", "index.html", s3_bucket)
copy_file("index.html", s3_bucket)
if __name__ == "__main__":
main(sys.argv[1:])