From 8fa1f4100696f55c6a633ae4b5071b2bab86f1c5 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 29 Mar 2022 17:32:12 +0200 Subject: [PATCH] add requirements and drop dependencies --- ereuse_devicehub/parser/computer.py | 102 +--------------------------- requirements.txt | 1 + 2 files changed, 2 insertions(+), 101 deletions(-) diff --git a/ereuse_devicehub/parser/computer.py b/ereuse_devicehub/parser/computer.py index 3b6e8e78..75f0c74c 100644 --- a/ereuse_devicehub/parser/computer.py +++ b/ereuse_devicehub/parser/computer.py @@ -1,16 +1,11 @@ import json import re -import subprocess from contextlib import suppress from datetime import datetime -from enum import Enum, unique from fractions import Fraction -from subprocess import PIPE, run from typing import Iterator, List, Optional, Type, TypeVar -from warnings import catch_warnings, filterwarnings import dateutil.parser -import pySMART from ereuse_utils import getter as g from ereuse_utils import text from ereuse_utils.nested_lookup import ( @@ -184,87 +179,6 @@ class RamModule(Component): return '{} {} {}'.format(super().__str__(), self.format, self.size) -class DataStorage(Component): - @classmethod - def new(cls, lshw, hwinfo, **kwargs) -> Iterator[C]: - disks = get_nested_dicts_with_key_containing_value(lshw, 'id', 'disk') - - usb_disks = list() # List of disks that are plugged in an USB host - for usb in get_nested_dicts_with_key_containing_value(lshw, 'id', 'usbhost'): - usb_disks.extend( - get_nested_dicts_with_key_containing_value(usb, 'id', 'disk') - ) - - for disk in (n for n in disks if n not in usb_disks): - # We can get nodes that are not truly disks as they don't have size - if 'size' in disk: - interface = DataStorage.get_interface(disk) - removable = interface == 'usb' or disk.get('capabilities', {}).get( - 'removable', False - ) - if not removable: - yield cls(disk, interface) - - SSD = 'SolidStateDrive' - HDD = 'HardDrive' - - @unique - class DataStorageInterface(Enum): - ATA = 'ATA' - USB = 'USB' - PCI = 'PCI' - - def __str__(self): - return self.value - - def __init__(self, node: dict, interface: str) -> None: - super().__init__(node) - self.from_lshw(node) - self.size = unit.Quantity(node['size'], node.get('units', 'B')).to('MB').m - self.interface = ( - self.DataStorageInterface(interface.upper()) if interface else None - ) - self._logical_name = node['logicalname'] - self.variant = node['version'] - - with catch_warnings(): - filterwarnings('error') - try: - smart = pySMART.Device(self._logical_name) - except Warning: - self.type = self.HDD - else: - self.type = self.SSD if smart.is_ssd else self.HDD - self.serial_number = self.serial_number or smart.serial - self.model = self.model or smart.model - - assert 1.0 < self.size < 1000000000000000.0, 'Invalid HDD size {}'.format( - self.size - ) - - def __str__(self) -> str: - return '{} {} {} with {} MB'.format( - super().__str__(), self.interface, self.type, self.size - ) - - @staticmethod - def get_interface(node: dict): - interface = run( - 'udevadm info ' - '--query=all ' - '--name={} | ' - 'grep ' - 'ID_BUS | ' - 'cut -c 11-'.format(node['logicalname']), - check=True, - universal_newlines=True, - shell=True, - stdout=PIPE, - ).stdout - # todo not sure if ``interface != usb`` is needed - return interface.strip() - - class GraphicCard(Component): @classmethod def new(cls, lshw, hwinfo, **kwargs) -> Iterator[C]: @@ -279,21 +193,7 @@ class GraphicCard(Component): @staticmethod def _memory(bus_info): """The size of the memory of the gpu.""" - try: - # lines = cmd.run( - # 'lspci', - # '-v -s {bus} | ', - # 'grep \'prefetchable\' | ', - # 'grep -v \'non-prefetchable\' | ', - # 'egrep -o \'[0-9]{{1,3}}[KMGT]+\''.format(bus=bus_info), - # shell=True, - # ).stdout.splitlines() - # return max( - # (base2.Quantity(value).to('MiB') for value in lines), default=None - # ) - return None - except subprocess.CalledProcessError: - return None + return None def __str__(self) -> str: return '{} with {}'.format(super().__str__(), self.memory) diff --git a/requirements.txt b/requirements.txt index 59375c33..2f8a8ece 100644 --- a/requirements.txt +++ b/requirements.txt @@ -40,3 +40,4 @@ tqdm==4.32.2 python-decouple==3.3 python-dotenv==0.14.0 pyjwt==2.0.0a1 +numpy==1.16.3