add/delete custom service file to node

This commit is contained in:
Huy Pham 2020-02-26 08:31:28 -08:00
parent 41bb951531
commit 696fda00ea
2 changed files with 41 additions and 33 deletions

View file

@ -935,6 +935,7 @@ class CoreClient:
config_proto = core_pb2.ServiceConfig( config_proto = core_pb2.ServiceConfig(
node_id=node_id, node_id=node_id,
service=name, service=name,
files=config.configs,
startup=config.startup, startup=config.startup,
validate=config.validate, validate=config.validate,
shutdown=config.shutdown, shutdown=config.shutdown,

View file

@ -49,8 +49,8 @@ class ServiceConfigDialog(Dialog):
self.validation_mode = None self.validation_mode = None
self.validation_time = None self.validation_time = None
self.validation_period = None self.validation_period = None
self.documentnew_img = Images.get(ImageEnum.DOCUMENTNEW, 16) self.documentnew_img = Images.get(ImageEnum.DOCUMENTNEW, 16 * app.app_scale)
self.editdelete_img = Images.get(ImageEnum.EDITDELETE, 16) self.editdelete_img = Images.get(ImageEnum.EDITDELETE, 16 * app.app_scale)
self.notebook = None self.notebook = None
self.metadata_entry = None self.metadata_entry = None
@ -103,7 +103,7 @@ class ServiceConfigDialog(Dialog):
x: self.app.core.get_node_service_file( x: self.app.core.get_node_service_file(
self.node_id, self.service_name, x self.node_id, self.service_name, x
) )
for x in self.filenames for x in default_config.configs
} }
self.temp_service_files = dict(self.original_service_files) self.temp_service_files = dict(self.original_service_files)
file_configs = self.file_configs file_configs = self.file_configs
@ -164,10 +164,11 @@ class ServiceConfigDialog(Dialog):
button = ttk.Button( button = ttk.Button(
frame, image=self.documentnew_img, command=self.add_filename frame, image=self.documentnew_img, command=self.add_filename
) )
# button.bind("<Button-1>", self.add_filename)
button.grid(row=0, column=2, padx=PADX) button.grid(row=0, column=2, padx=PADX)
button = ttk.Button(frame, image=self.editdelete_img, state="disabled") button = ttk.Button(
button.bind("<Button-1>", self.delete_filename) frame, image=self.editdelete_img, command=self.delete_filename
)
# button.bind("<Button-1>", self.delete_filename)
button.grid(row=0, column=3) button.grid(row=0, column=3)
frame = ttk.Frame(tab) frame = ttk.Frame(tab)
@ -370,17 +371,19 @@ class ServiceConfigDialog(Dialog):
else: else:
logging.debug("file already existed") logging.debug("file already existed")
def delete_filename(self, event: tk.Event): def delete_filename(self):
# not worry about it for now cbb = self.filename_combobox
return filename = cbb.get()
frame_comntains_button = event.widget.master if filename in cbb["values"]:
combobox = frame_comntains_button.grid_slaves(row=0, column=1)[0] cbb["values"] = tuple([x for x in cbb["values"] if x != filename])
filename = combobox.get() cbb.set("")
if filename in combobox["values"]: self.service_file_data.text.delete(1.0, "end")
combobox["values"] = tuple([x for x in combobox["values"] if x != filename]) self.temp_service_files.pop(filename, None)
combobox.set("") if filename in self.modified_files:
self.modified_files.remove(filename)
def add_command(self, event: tk.Event): @classmethod
def add_command(cls, event: tk.Event):
frame_contains_button = event.widget.master frame_contains_button = event.widget.master
listbox = frame_contains_button.master.grid_slaves(row=1, column=0)[0].listbox listbox = frame_contains_button.master.grid_slaves(row=1, column=0)[0].listbox
command_to_add = frame_contains_button.grid_slaves(row=0, column=0)[0].get() command_to_add = frame_contains_button.grid_slaves(row=0, column=0)[0].get()
@ -391,7 +394,8 @@ class ServiceConfigDialog(Dialog):
return return
listbox.insert(tk.END, command_to_add) listbox.insert(tk.END, command_to_add)
def update_entry(self, event: tk.Event): @classmethod
def update_entry(cls, event: tk.Event):
listbox = event.widget listbox = event.widget
current_selection = listbox.curselection() current_selection = listbox.curselection()
if len(current_selection) > 0: if len(current_selection) > 0:
@ -402,7 +406,8 @@ class ServiceConfigDialog(Dialog):
entry.delete(0, "end") entry.delete(0, "end")
entry.insert(0, cmd) entry.insert(0, cmd)
def delete_command(self, event: tk.Event): @classmethod
def delete_command(cls, event: tk.Event):
button = event.widget button = event.widget
frame_contains_button = button.master frame_contains_button = button.master
listbox = frame_contains_button.master.grid_slaves(row=1, column=0)[0].listbox listbox = frame_contains_button.master.grid_slaves(row=1, column=0)[0].listbox
@ -415,7 +420,7 @@ class ServiceConfigDialog(Dialog):
def click_apply(self): def click_apply(self):
current_listbox = self.master.current.listbox current_listbox = self.master.current.listbox
if ( if (
not self.is_custom_service_config() not self.is_custom_command()
and not self.is_custom_service_file() and not self.is_custom_service_file()
and not self.has_new_files() and not self.has_new_files()
): ):
@ -426,17 +431,15 @@ class ServiceConfigDialog(Dialog):
return return
try: try:
if self.is_custom_service_config() or self.has_new_files(): if self.is_custom_command() or self.has_new_files():
startup_commands = self.startup_commands_listbox.get(0, "end") startup, validate, shutdown = self.get_commands()
shutdown_commands = self.shutdown_commands_listbox.get(0, "end")
validate_commands = self.validate_commands_listbox.get(0, "end")
config = self.core.set_node_service( config = self.core.set_node_service(
self.node_id, self.node_id,
self.service_name, self.service_name,
files=list(self.filename_combobox["values"]), files=list(self.filename_combobox["values"]),
startups=startup_commands, startups=startup,
validations=validate_commands, validations=validate,
shutdowns=shutdown_commands, shutdowns=shutdown,
) )
if self.node_id not in self.service_configs: if self.node_id not in self.service_configs:
self.service_configs[self.node_id] = {} self.service_configs[self.node_id] = {}
@ -475,14 +478,12 @@ class ServiceConfigDialog(Dialog):
else: else:
self.modified_files.discard(filename) self.modified_files.discard(filename)
def is_custom_service_config(self): def is_custom_command(self):
startup_commands = self.startup_commands_listbox.get(0, "end") startup, validate, shutdown = self.get_commands()
shutdown_commands = self.shutdown_commands_listbox.get(0, "end")
validate_commands = self.validate_commands_listbox.get(0, "end")
return ( return (
set(self.default_startup) != set(startup_commands) set(self.default_startup) != set(startup)
or set(self.default_validate) != set(validate_commands) or set(self.default_validate) != set(validate)
or set(self.default_shutdown) != set(shutdown_commands) or set(self.default_shutdown) != set(shutdown)
) )
def has_new_files(self): def has_new_files(self):
@ -520,3 +521,9 @@ class ServiceConfigDialog(Dialog):
for cmd in to_add: for cmd in to_add:
commands.append(cmd) commands.append(cmd)
listbox.insert(tk.END, cmd) listbox.insert(tk.END, cmd)
def get_commands(self):
startup = self.startup_commands_listbox.get(0, "end")
shutdown = self.shutdown_commands_listbox.get(0, "end")
validate = self.validate_commands_listbox.get(0, "end")
return startup, validate, shutdown