-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup.py
107 lines (80 loc) · 2.98 KB
/
setup.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import subprocess
import sys
def install(package):
subprocess.check_call([sys.executable, "-m", "pip", "install", package, "--quiet"])
install("PyYAML")
install("pytz")
install("datetime")
import time
import yaml
import pytz
import datetime
bashCommand = "docker network create --driver bridge provider_network --subnet=172.22.0.0/16 --ip-range=172.22.0.0/24 --gateway=172.22.0.1"
try:
subprocess.check_call(bashCommand.split())
except Exception as e:
print(e)
pass
def get_potentials(continent):
local_names = []
if time.daylight:
local_offset = time.altzone
localtz = time.tzname[1]
else:
local_offset = time.timezone
localtz = time.tzname[0]
local_offset = datetime.timedelta(seconds=-local_offset)
for name in pytz.all_timezones:
timezone = pytz.timezone(name)
if not hasattr(timezone, '_tzinfos'):
continue
for (utcoffset, daylight, tzname), _ in timezone._tzinfos.items():
if utcoffset == local_offset and tzname == localtz:
local_names.append(name)
potentials = []
for item in local_names:
if continent in item:
potentials.append(item)
return potentials
def confirm_tz(potentials):
print("Choose your time zone from the following list:")
for item in potential:
print(item)
time_zone = input("Your time zone is: ")
final_zone = ''
for item in potentials:
if item.lower() == time_zone.lower().strip():
final_zone = item
return final_zone
user = input("Enter the Host Machine Name: ")
print("To set up your time zone, please enter your location as a part of the world,")
print("Enter one of the following: Africa, America, Arctic, Asia, Australia, Atlantic, Europe, Pacific")
continent = input("I am somewhere in: ")
potential = get_potentials(continent)
final_tz = confirm_tz(potential)
correct = False
count = 0
while not correct:
if final_tz == '':
print("Check your spelling and enter the time zone again: ")
final_tz = confirm_tz(potential)
count += 1
elif final_tz == '' and count == 3:
print("Wrong Time zone")
break
if final_tz != '':
correct = True
break
with open('docker-compose.yml') as file:
compose = yaml.load(file, Loader=yaml.FullLoader)
compose['services']['kafka']['environment']['KAFKA_ADVERTISED_LISTENERS'] = 'INTERNAL://kafka:9092,EXTERNAL://' + user+ ':9094'
compose['services']['kafka']['environment']['TZ'] = final_tz
compose['services']['mongo_db']['environment']['TZ'] = final_tz
compose['services']['spark-master']['environment']['TZ'] = final_tz
compose['services']['provider']['environment']['TZ'] = final_tz
compose['services']['sql_db']['environment']['TZ'] = final_tz
compose['services']['worker1']['environment']['TZ'] = final_tz
compose['services']['zookeeper']['environment']['TZ'] = final_tz
with open('docker-compose.yml', 'w') as file1:
documents = yaml.dump(compose, file1)
print("Done!")