Skip to content

Commit

Permalink
fix(devices): improves code quality
Browse files Browse the repository at this point in the history
  • Loading branch information
RomilShah committed Sep 3, 2023
1 parent d71c97d commit e18681f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
21 changes: 1 addition & 20 deletions riocli/device/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down
18 changes: 18 additions & 0 deletions riocli/device/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit e18681f

Please sign in to comment.