Optimization of config sending via network

This commit is contained in:
Artem30801
2020-01-24 15:46:48 +03:00
parent e38b396da5
commit 0134227742
4 changed files with 13 additions and 13 deletions

View File

@@ -170,7 +170,6 @@ class Client(object):
while True:
#self.server_connection.send_message("telemetry", kwargs={"value":{"time": time.time()}})
events = self.selector.select(timeout=1)
for key, mask in events:
connection = key.data
if connection is not None:
@@ -217,7 +216,7 @@ def _command_config_write(*args, **kwargs):
@messaging.request_callback("config")
def _response_config(*args, **kwargs):
response = {"config": active_client.config.full_dict,
response = {"config": active_client.config.full_dict(),
"configspec": dict(active_client.config.config.configspec)}
return response

View File

@@ -773,7 +773,7 @@ class ConfigDialog(QtWidgets.QDialog):
cfg = config.ConfigManager()
cfg.load_from_dict(config_dict, spec_dict)
self.setupModel(config_dict)
self.setupModel(cfg.full_dict(include_defaults=True))
if not self.validation_loop(cfg, spec_dict):
return False
@@ -799,7 +799,7 @@ class ConfigDialog(QtWidgets.QDialog):
"Config cannot be opened or validated: {}".format(error))
return False
self.setupModel(cfg.full_dict, convert_types=(not cfg.validated))
self.setupModel(cfg.full_dict(include_defaults=True), convert_types=(not cfg.validated))
self.ui.do_restart.setDisabled(True)
filename = cfg.config.filename

View File

@@ -462,7 +462,7 @@ class MainWindow(QtWidgets.QMainWindow):
config = cfg.ConfigManager()
config.load_only_config(path)
data = config.full_dict
data = config.full_dict()
logging.info(f"Loaded config from {path}")
copters = self.model.user_selected()

View File

@@ -92,7 +92,7 @@ class ConfigManager:
self.validated = True
@classmethod
def _full_dict(cls, item):
def _full_dict(cls, item, include_defaults=False):
if not isinstance(item, Section):
return item
@@ -103,15 +103,17 @@ class ConfigManager:
inline_comments = item.inline_comments
for key, value in item.items():
result = cls._full_dict(value)
result = cls._full_dict(value, include_defaults)
if not isinstance(result, dict):
item_d = {'__option__': True,
'value': value,
'default': default_values.get(key, None),
'unchanged': key in defaults,
'comments': comments.get(key, []),
'inline_comment': inline_comments.get(key, None),
}
if include_defaults:
item_d.update({'default': default_values.get(key, None),
'unchanged': key in defaults,
})
data[key] = item_d
else:
@@ -119,9 +121,8 @@ class ConfigManager:
return data
@property
def full_dict(self):
d = self._full_dict(self.config)
def full_dict(self, include_defaults=False):
d = self._full_dict(self.config, include_defaults=include_defaults)
d['initial_comment'] = self.config.initial_comment
d['final_comment'] = self.config.final_comment
return d
@@ -322,7 +323,7 @@ if __name__ == '__main__':
#pprint.pprint(cfg2.full_dict)
cfg.merge(cfg2)
#pprint.pprint(cfg.full_dict)
print(cfg.full_dict)
print(cfg.full_dict(include_defaults=True))
print(dict(cfg.config.configspec))
#print(dict(ConfigManager(cfg.config.configspec).config))