Code Duplication    Length = 21-23 lines in 2 locations

glances/plugins/vms/__init__.py 1 location

@@ 153-173 (lines=21) @@
150
            return False
151
        return all_tag[0].lower() == 'true'
152
153
    @GlancesPluginModel._check_decorator
154
    @GlancesPluginModel._log_result_decorator
155
    def update(self) -> List[Dict]:
156
        """Update VMs stats using the input method."""
157
        # Connection should be ok
158
        if not self.watchers or self.input_method != 'local':
159
            return self.get_init_value()
160
161
        # Update stats
162
        stats = []
163
        for engine, watcher in iteritems(self.watchers):
164
            version, vms = watcher.update(all_tag=self._all_tag())
165
            for vm in vms:
166
                vm["engine"] = engine
167
                vm["engine_version"] = version
168
            stats.extend(vms)
169
170
        # Sort and update the stats
171
        # TODO: test
172
        self.sort_key, self.stats = sort_vm_stats(stats)
173
        return self.stats
174
175
    def update_views(self) -> bool:
176
        """Update stats views."""

glances/plugins/containers/__init__.py 1 location

@@ 215-237 (lines=23) @@
212
            return False
213
        return all_tag[0].lower() == 'true'
214
215
    @GlancesPluginModel._check_decorator
216
    @GlancesPluginModel._log_result_decorator
217
    def update(self) -> List[Dict]:
218
        """Update Docker and podman stats using the input method."""
219
        # Connection should be ok
220
        if not self.watchers:
221
            return self.get_init_value()
222
223
        if self.input_method != 'local':
224
            return self.get_init_value()
225
226
        # Update stats
227
        stats = []
228
        for engine, watcher in iteritems(self.watchers):
229
            version, containers = watcher.update(all_tag=self._all_tag())
230
            for container in containers:
231
                container["engine"] = engine
232
            stats.extend(containers)
233
234
        # Sort and update the stats
235
        # @TODO: Have a look because sort did not work for the moment (need memory stats ?)
236
        self.sort_key, self.stats = sort_docker_stats(stats)
237
        return self.stats
238
239
    @staticmethod
240
    def memory_usage_no_cache(mem: Dict[str, float]) -> float: