-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
137 lines (106 loc) · 4.44 KB
/
main.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
from tkinter import *;
import os
import json
from tkinter import messagebox
FILE = "properties.json"
APPLICATION_TYPE = ["Reporting", "Framework"]
PROCESS_TYPE = {"DEPLOY": ["Deploy"], "DEPLOY_RESTART": ["Deploy and Restart"], "RESTART": ["Restart"],
"START": ["Start"], "STOP": ["Stop"]}
data = {}
def write_to_file(account, application, source, host, user,password):
if account== "" or application== "":
messagebox.showinfo("Title", "Please fill mandatory fields")
return
def add_customer():
details = Toplevel();
details.wm_title("Add Customer")
account = Label(details, text="Account*").pack()
account_entry = Entry(details)
account_entry.pack()
application = Label(details, text="Application*").pack()
application_entry = Entry(details)
application_entry.pack()
source = Label(details, text="Source").pack()
source_entry = Entry(details)
source_entry.pack()
host = Label(details, text="Host").pack()
host_entry = Entry(details)
host_entry.pack()
user = Label(details, text="User").pack()
user_entry = Entry(details)
user_entry.pack()
password = Label(details, text="Password").pack()
password_entry = Entry(details)
password_entry.pack()
add_button = Button(details, text="Add", command=write_to_file(
account_entry.get(), application_entry.get(), source_entry.get(), host_entry.get(), user_entry.get(),
password_entry.get())).pack()
return
def get_customer_list(file):
with open(file) as data_file:
global data
data = json.load(data_file)
customer_list = []
for i in data["Customers"]:
customer_list.append(str(i))
return customer_list
def get_command(neo, process_type, account, application, user, password, host,
source):
neo_command = neo + " "
neo_command = neo_command + process_type + " "
neo_command = neo_command + "--account " + account + " "
neo_command = neo_command + "--application " + application + " "
if user:
neo_command = neo_command + "--user " + user + " "
elif password:
neo_command = neo_command + "--password " + password + " "
neo_command = neo_command + "--host " + host + " "
if process_type == PROCESS_TYPE["DEPLOY"][0].lower():
neo_command = neo_command + "--source " + source
print(neo_command)
os.system(neo_command);
os.system("notify-send " + process_type + " done.")
return neo_command
def execute(customer, application_type, process_type):
os.system("notify-send 'Process started...'")
global data
customer_data = data["Customers"]
neo = data["neo_command"]
host = data["host"]
customer_app_data = customer_data[customer][application_type];
account = customer_app_data['account']
application = customer_app_data['application'];
user = (customer_app_data['user'] if customer_app_data['user'] != "" else data['user']);
password = (customer_app_data['password'] if customer_app_data['password'] != "" else data['password']);
source = data["reporting_source"] if application_type == "Reporting" else data["framework_source"]
flag = 0;
if process_type == PROCESS_TYPE["DEPLOY_RESTART"][0]:
flag = 1;
process_type = PROCESS_TYPE["DEPLOY"][0];
neo_command = get_command(neo, process_type.lower(), account, application, user, password, host, source);
if flag:
neo_command = get_command(neo, 'restart', account, application, user, password, host, source);
master = Tk();
customer_list = get_customer_list(FILE);
customer = StringVar(master)
customer.set(customer_list[0])
w = OptionMenu(master, customer, *customer_list).pack()
# for second drop down
application_type = StringVar(master)
application_type.set(APPLICATION_TYPE[0])
w = OptionMenu(master, application_type, *APPLICATION_TYPE).pack()
# for third drop down
process_type = StringVar(master)
process_type.set(PROCESS_TYPE["DEPLOY"][0])
process_list = [];
for f in PROCESS_TYPE.values():
process_list.append(f[0]);
w = OptionMenu(master, process_type, *process_list).pack();
b = Button(master, text="Execute",
command=lambda: execute(customer.get(), application_type.get(), process_type.get())).pack();
menu = Menu(master)
menu.add_command(label="Add Customer", command=add_customer)
menu.add_command(label="Create properties.json")
add_customer_button = Button(master, text="Add Customer", command=add_customer).pack();
mainloop();
Comments by Pradeep