fixed wrong variable used for configuring service in grpcutils, add/delete directories for node's service configuration, clean up some old code

This commit is contained in:
Huy Pham 2020-02-26 15:43:31 -08:00
parent 764a61e89e
commit c36f060d44
3 changed files with 32 additions and 30 deletions

View file

@ -379,7 +379,7 @@ def service_configuration(session: Session, config: core_pb2.ServiceConfig) -> N
if config.files: if config.files:
service.configs = tuple(config.files) service.configs = tuple(config.files)
if config.directories: if config.directories:
service.directories = tuple(config.directories) service.dirs = tuple(config.directories)
if config.startup: if config.startup:
service.startup = tuple(config.startup) service.startup = tuple(config.startup)
if config.validate: if config.validate:

View file

@ -500,7 +500,6 @@ class CoreClient:
emane_config = {x: self.emane_config[x].value for x in self.emane_config} emane_config = {x: self.emane_config[x].value for x in self.emane_config}
else: else:
emane_config = None emane_config = None
response = core_pb2.StartSessionResponse(result=False) response = core_pb2.StartSessionResponse(result=False)
try: try:
response = self.client.start_session( response = self.client.start_session(
@ -619,6 +618,7 @@ class CoreClient:
self, self,
node_id: int, node_id: int,
service_name: str, service_name: str,
dirs: List[str],
files: List[str], files: List[str],
startups: List[str], startups: List[str],
validations: List[str], validations: List[str],
@ -628,6 +628,7 @@ class CoreClient:
self.session_id, self.session_id,
node_id, node_id,
service_name, service_name,
directories=dirs,
files=files, files=files,
startup=startups, startup=startups,
validate=validations, validate=validations,
@ -935,6 +936,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,
directories=config.dirs,
files=config.configs, files=config.configs,
startup=config.startup, startup=config.startup,
validate=config.validate, validate=config.validate,

View file

@ -1,6 +1,3 @@
"""
Service configuration dialog
"""
import logging import logging
import os import os
import tkinter as tk import tkinter as tk
@ -79,7 +76,7 @@ class ServiceConfigDialog(Dialog):
if not self.has_error: if not self.has_error:
self.draw() self.draw()
def load(self) -> bool: def load(self):
try: try:
self.app.core.create_nodes_and_links() self.app.core.create_nodes_and_links()
default_config = self.app.core.get_node_service( default_config = self.app.core.get_node_service(
@ -89,15 +86,12 @@ class ServiceConfigDialog(Dialog):
self.default_validate = default_config.validate[:] self.default_validate = default_config.validate[:]
self.default_shutdown = default_config.shutdown[:] self.default_shutdown = default_config.shutdown[:]
self.default_directories = default_config.dirs[:] self.default_directories = default_config.dirs[:]
custom_configs = self.service_configs custom_service_config = self.service_configs.get(self.node_id, {}).get(
if ( self.service_name, None
self.node_id in custom_configs )
and self.service_name in custom_configs[self.node_id] service_config = (
): custom_service_config if custom_service_config else default_config
service_config = custom_configs[self.node_id][self.service_name] )
else:
service_config = default_config
self.dependencies = service_config.dependencies[:] self.dependencies = service_config.dependencies[:]
self.executables = service_config.executables[:] self.executables = service_config.executables[:]
self.metadata = service_config.meta self.metadata = service_config.meta
@ -115,12 +109,10 @@ class ServiceConfigDialog(Dialog):
for x in default_config.configs 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_config = self.file_configs.get(self.node_id, {}).get(
if ( self.service_name, {}
self.node_id in file_configs )
and self.service_name in file_configs[self.node_id] for file, data in file_config.items():
):
for file, data in file_configs[self.node_id][self.service_name].items():
self.temp_service_files[file] = data self.temp_service_files[file] = data
except grpc.RpcError as e: except grpc.RpcError as e:
self.has_error = True self.has_error = True
@ -451,23 +443,30 @@ class ServiceConfigDialog(Dialog):
def click_apply(self): def click_apply(self):
current_listbox = self.master.current.listbox current_listbox = self.master.current.listbox
all_current = current_listbox.get(0, tk.END)
if ( if (
not self.is_custom_command() 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()
and not self.is_custom_directory()
): ):
if self.node_id in self.service_configs: if self.node_id in self.service_configs:
self.service_configs[self.node_id].pop(self.service_name, None) self.service_configs[self.node_id].pop(self.service_name, None)
current_listbox.itemconfig(current_listbox.curselection()[0], bg="") current_listbox.itemconfig(all_current.index(self.service_name), bg="")
self.destroy() self.destroy()
return return
try: try:
if self.is_custom_command() or self.has_new_files(): if (
self.is_custom_command()
or self.has_new_files()
or self.is_custom_directory()
):
startup, validate, shutdown = self.get_commands() startup, validate, shutdown = self.get_commands()
config = self.core.set_node_service( config = self.core.set_node_service(
self.node_id, self.node_id,
self.service_name, self.service_name,
dirs=self.temp_directories,
files=list(self.filename_combobox["values"]), files=list(self.filename_combobox["values"]),
startups=startup, startups=startup,
validations=validate, validations=validate,
@ -487,22 +486,19 @@ class ServiceConfigDialog(Dialog):
self.app.core.set_node_service_file( self.app.core.set_node_service_file(
self.node_id, self.service_name, file, self.temp_service_files[file] self.node_id, self.service_name, file, self.temp_service_files[file]
) )
all_current = current_listbox.get(0, tk.END)
current_listbox.itemconfig(all_current.index(self.service_name), bg="green") current_listbox.itemconfig(all_current.index(self.service_name), bg="green")
except grpc.RpcError as e: except grpc.RpcError as e:
show_grpc_error(e, self.top, self.app) show_grpc_error(e, self.top, self.app)
self.destroy() self.destroy()
def display_service_file_data(self, event: tk.Event): def display_service_file_data(self, event: tk.Event):
combobox = event.widget filename = self.filename_combobox.get()
filename = combobox.get()
self.service_file_data.text.delete(1.0, "end") self.service_file_data.text.delete(1.0, "end")
self.service_file_data.text.insert("end", self.temp_service_files[filename]) self.service_file_data.text.insert("end", self.temp_service_files[filename])
def update_temp_service_file_data(self, event: tk.Event): def update_temp_service_file_data(self, event: tk.Event):
scrolledtext = event.widget
filename = self.filename_combobox.get() filename = self.filename_combobox.get()
self.temp_service_files[filename] = scrolledtext.get(1.0, "end") self.temp_service_files[filename] = self.service_file_data.text.get(1.0, "end")
if self.temp_service_files[filename] != self.original_service_files.get( if self.temp_service_files[filename] != self.original_service_files.get(
filename, "" filename, ""
): ):
@ -524,6 +520,9 @@ class ServiceConfigDialog(Dialog):
def is_custom_service_file(self): def is_custom_service_file(self):
return len(self.modified_files) > 0 return len(self.modified_files) > 0
def is_custom_directory(self):
return set(self.default_directories) != set(self.dir_list.listbox.get(0, "end"))
def click_defaults(self): def click_defaults(self):
if self.node_id in self.service_configs: if self.node_id in self.service_configs:
self.service_configs[self.node_id].pop(self.service_name, None) self.service_configs[self.node_id].pop(self.service_name, None)
@ -547,8 +546,9 @@ class ServiceConfigDialog(Dialog):
dialog = CopyServiceConfigDialog(self, self.app, self.node_id) dialog = CopyServiceConfigDialog(self, self.app, self.node_id)
dialog.show() dialog.show()
@classmethod
def append_commands( def append_commands(
self, commands: List[str], listbox: tk.Listbox, to_add: List[str] cls, commands: List[str], listbox: tk.Listbox, to_add: List[str]
): ):
for cmd in to_add: for cmd in to_add:
commands.append(cmd) commands.append(cmd)