Skip to content

opensampl.vendors.constants

Defines constants for use in probe functions

ProbeKey

Bases: BaseModel

Model for Probe identity, which is both probe_id and ip_address

Source code in opensampl/vendors/constants.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
class ProbeKey(BaseModel):
    """Model for Probe identity, which is both probe_id and ip_address"""

    probe_id: str
    ip_address: str

    def __repr__(self):
        """Represent Probe key as [ip_address]_[probe_id]"""
        return f"{self.ip_address}_{self.probe_id}"

    def __str__(self):
        """Get Probe key string as [ip_address]_[probe_id]"""
        return self.__repr__()

__repr__()

Represent Probe key as [ip_address]_[probe_id]

Source code in opensampl/vendors/constants.py
12
13
14
def __repr__(self):
    """Represent Probe key as [ip_address]_[probe_id]"""
    return f"{self.ip_address}_{self.probe_id}"

__str__()

Get Probe key string as [ip_address]_[probe_id]

Source code in opensampl/vendors/constants.py
16
17
18
def __str__(self):
    """Get Probe key string as [ip_address]_[probe_id]"""
    return self.__repr__()

VENDORS

Vendors available for use

Source code in opensampl/vendors/constants.py
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
class VENDORS:
    """Vendors available for use"""

    # --- SUPPORTED VENDORS ----
    ADVA = VendorType(
        name="ADVA",
        parser_class="AdvaProbe",
        parser_module="adva",
        metadata_table="adva_metadata",
        metadata_orm="AdvaMetadata",
    )

    MICROCHIP_TWST = VendorType(
        name="MicrochipTWST",
        parser_class="MicrochipTWSTProbe",
        parser_module="microchip.twst",
        metadata_table="microchip_twst_metadata",
        metadata_orm="MicrochipTWSTMetadata",
    )

    MICROCHIP_TP4100 = VendorType(
        name="MicrochipTP4100",
        parser_class="MicrochipTP4100Probe",
        parser_module="microchip.tp4100",
        metadata_table="microchip_tp4100_metadata",
        metadata_orm="MicrochipTP4100Metadata",
    )

    # --- CUSTOM VENDORS ---      !! Do not remove line, used as reference when inserting vendor

    # --- VENDOR FUNCTIONS ---

    @classmethod
    def all(cls) -> list[VendorType]:
        """Get all vendors"""
        return [attr for attr in cls.__dict__.values() if isinstance(attr, VendorType)]

    @classmethod
    def get_by_name(cls, name: str, case_sensitive: bool = False) -> VendorType:
        """
        Get a vendor type by name

        Args:
            name: The name of the vendor to get
            case_sensitive: Whether to match the name case-sensitively (default: False)

        Returns:
            VendorType: The vendor type definition

        """
        for attr_name in dir(cls):
            if attr_name.startswith("_"):
                continue

            attr = getattr(cls, attr_name)
            if isinstance(attr, VendorType):
                vendor_name = attr.name
                if vendor_name == name or (not case_sensitive and vendor_name.lower() == name.lower()):
                    return attr

        raise ValueError(f"Vendor '{name}' not found")

all() classmethod

Get all vendors

Source code in opensampl/vendors/constants.py
77
78
79
80
@classmethod
def all(cls) -> list[VendorType]:
    """Get all vendors"""
    return [attr for attr in cls.__dict__.values() if isinstance(attr, VendorType)]

get_by_name(name, case_sensitive=False) classmethod

Get a vendor type by name

Parameters:

Name Type Description Default
name str

The name of the vendor to get

required
case_sensitive bool

Whether to match the name case-sensitively (default: False)

False

Returns:

Name Type Description
VendorType VendorType

The vendor type definition

Source code in opensampl/vendors/constants.py
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
@classmethod
def get_by_name(cls, name: str, case_sensitive: bool = False) -> VendorType:
    """
    Get a vendor type by name

    Args:
        name: The name of the vendor to get
        case_sensitive: Whether to match the name case-sensitively (default: False)

    Returns:
        VendorType: The vendor type definition

    """
    for attr_name in dir(cls):
        if attr_name.startswith("_"):
            continue

        attr = getattr(cls, attr_name)
        if isinstance(attr, VendorType):
            vendor_name = attr.name
            if vendor_name == name or (not case_sensitive and vendor_name.lower() == name.lower()):
                return attr

    raise ValueError(f"Vendor '{name}' not found")

VendorType

Bases: BaseModel

Model for Vendor Type Definition

Source code in opensampl/vendors/constants.py
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
class VendorType(BaseModel):
    """Model for Vendor Type Definition"""

    name: str
    parser_class: str
    parser_module: str
    metadata_table: str
    metadata_orm: str

    def get_parser(self):
        """Get the Python Class object associated with the vendor type"""
        module = __import__(
            f"opensampl.vendors.{self.parser_module}",
            fromlist=[self.parser_class],
            globals=globals(),
        )
        return getattr(module, self.parser_class)

    def get_orm(self):
        """Get the Sqlalchemy ORM object associated with the vendor type"""
        module = __import__("opensampl.db.orm", fromlist=[self.metadata_orm], globals=globals())
        return getattr(module, self.metadata_orm)

get_orm()

Get the Sqlalchemy ORM object associated with the vendor type

Source code in opensampl/vendors/constants.py
39
40
41
42
def get_orm(self):
    """Get the Sqlalchemy ORM object associated with the vendor type"""
    module = __import__("opensampl.db.orm", fromlist=[self.metadata_orm], globals=globals())
    return getattr(module, self.metadata_orm)

get_parser()

Get the Python Class object associated with the vendor type

Source code in opensampl/vendors/constants.py
30
31
32
33
34
35
36
37
def get_parser(self):
    """Get the Python Class object associated with the vendor type"""
    module = __import__(
        f"opensampl.vendors.{self.parser_module}",
        fromlist=[self.parser_class],
        globals=globals(),
    )
    return getattr(module, self.parser_class)