From e18681f9bbe843791a50bc754a86a934c22cad15 Mon Sep 17 00:00:00 2001 From: RomilShah Date: Sun, 3 Sep 2023 17:51:26 +0530 Subject: [PATCH] fix(devices): improves code quality --- riocli/device/delete.py | 21 +-------------------- riocli/device/util.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/riocli/device/delete.py b/riocli/device/delete.py index a67314d0..11f39124 100644 --- a/riocli/device/delete.py +++ b/riocli/device/delete.py @@ -12,10 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. import functools -import re from concurrent.futures import ThreadPoolExecutor from queue import Queue -from typing import List import click import requests @@ -25,6 +23,7 @@ from yaspin.api import Yaspin from riocli.config import new_client +from riocli.device.util import fetch_devices from riocli.constants import Symbols, Colors from riocli.utils import tabulate_data from riocli.utils.spinner import with_spinner @@ -141,24 +140,6 @@ def delete_device( spinner.red.fail(Symbols.ERROR) raise SystemExit(1) from e - -def fetch_devices( - client: Client, - device_name_or_regex: str, - delete_all: bool, -) -> List[Device]: - devices = client.get_all_devices() - result = [] - for device in devices: - if (delete_all or device.name == device_name_or_regex or - (device_name_or_regex not in device.name and - re.search(device_name_or_regex, device.name)) or - device_name_or_regex == device.uuid): - result.append(device) - - return result - - def _delete_deivce( client: Client, result: Queue, diff --git a/riocli/device/util.py b/riocli/device/util.py index 13d9dec2..e52726b5 100644 --- a/riocli/device/util.py +++ b/riocli/device/util.py @@ -14,10 +14,12 @@ import functools import typing from pathlib import Path +import re import click from rapyuta_io import Client from rapyuta_io.clients import LogUploads +from rapyuta_io.clients.device import Device from riocli.config import new_client from riocli.utils import is_valid_uuid @@ -99,6 +101,22 @@ def decorated(**kwargs): return decorated +def fetch_devices( + client: Client, + device_name_or_regex: str, + delete_all: bool, +) -> typing.List[Device]: + devices = client.get_all_devices() + result = [] + for device in devices: + if (delete_all or device.name == device_name_or_regex or + (device_name_or_regex not in device.name and + re.search(device_name_or_regex, device.name)) or + device_name_or_regex == device.uuid): + result.append(device) + + return result + def find_request_id(requests: typing.List[LogUploads], file_name: str) -> (str, str): for request in requests: