From a5d6d2e610202e68704618d6cf96e97fe52c3948 Mon Sep 17 00:00:00 2001 From: Artem30801 Date: Wed, 20 Mar 2019 16:26:01 +0300 Subject: [PATCH] Closes #9 Added ability to send configuration files from server --- Drone/client.py | 6 +++++- Server/server_qt.py | 20 +++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/Drone/client.py b/Drone/client.py index b51cf36..a0e9d52 100644 --- a/Drone/client.py +++ b/Drone/client.py @@ -254,6 +254,10 @@ try: print("Command from server:", command, args) if command == "writefile": recive_file(list(args.values)[0]) + elif command == 'config_write': + write_to_config(args['section'], args['option'], args['value']) + elif command == 'config_reload': + load_config() elif command == "starttime": starttime = float(list(args.values)[0]) print("Starting on:", time.ctime(starttime)) @@ -279,7 +283,7 @@ try: print("Got request for:", request_target) response = "" if request_target == 'test': - response = "test_succsess" + response = "test_success" elif request_target == 'id': response = COPTER_ID elif request_target == 'selfcheck': diff --git a/Server/server_qt.py b/Server/server_qt.py index 46a520a..599e5bc 100644 --- a/Server/server_qt.py +++ b/Server/server_qt.py @@ -270,6 +270,7 @@ class MainWindow(QtWidgets.QMainWindow): self.ui.disarm_button.clicked.connect(self.disarm_all) self.ui.action_send_animations.triggered.connect(self.send_animations) + self.ui.action_send_configurations.triggered.connect(self.send_configurations) #Initing table and table model self.ui.tableView.setModel(model) @@ -330,9 +331,22 @@ class MainWindow(QtWidgets.QMainWindow): copter.send_file(file, "animation.csv") # TODO config else: print("Filename not matches with any drone connected") - # dr = next(iter(Client.clients.values())) # костыль для тестирования - # ANS = dr.get_response("someshit") - # print(ANS) + + @pyqtSlot() + def send_configurations(self): + path = QFileDialog.getOpenFileName(self, "Select configuration file", filter="Configs (*.ini *.txt .cfg)")[0] + if path: + print("Selected file:", path) + sendable_config = configparser.ConfigParser() + sendable_config.read(path) + for section in sendable_config.sections(): + for option in dict(sendable_config.items(section)): + value = sendable_config[section][option] + print("Got item from config:", section, option, value) + Client.send_to_selected( + Client.form_message('config_write', {'section': section, 'option': option, 'value': value}) + ) + Client.send_to_selected(Client.form_message("config_reload")) model = QStandardItemModel()