Skip to content

Commit

Permalink
q-dev: backend_name
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrbartman committed Oct 14, 2024
1 parent 405e91a commit ac42e08
Showing 1 changed file with 29 additions and 12 deletions.
41 changes: 29 additions & 12 deletions qubesadmin/device_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,29 +258,35 @@ def __init__(self, backend_domain, port_id, devclass):
self.__devclass = devclass

def __hash__(self):
return hash((self.backend_domain.name, self.port_id, self.devclass))
return hash((self.backend_name, self.port_id, self.devclass))

def __eq__(self, other):
if isinstance(other, Port):
return (
self.backend_domain == other.backend_domain and
self.port_id == other.port_id and
self.devclass == other.devclass
self.backend_name == other.backend_name and
self.port_id == other.port_id and
self.devclass == other.devclass
)
return False

def __lt__(self, other):
if isinstance(other, Port):
return (self.backend_domain.name, self.devclass, self.port_id) < \
(other.backend_domain.name, other.devclass, other.port_id)
return (self.backend_name, self.devclass, self.port_id) < \
(self.backend_name, other.devclass, other.port_id)
raise TypeError(f"Comparing instances of 'Port' and '{type(other)}' "
"is not supported")

def __repr__(self):
return f"{self.backend_domain.name}+{self.port_id}"
return f"{self.backend_name}+{self.port_id}"

def __str__(self):
return f"{self.backend_domain.name}:{self.port_id}"
return f"{self.backend_name}:{self.port_id}"

@property
def backend_name(self) -> str:
if self.backend_domain is not None:
return self.backend_domain.name
return "*"

@classmethod
def from_qarg(
Expand Down Expand Up @@ -324,7 +330,7 @@ def port_id(self) -> str:
return self.__port_id

@property
def backend_domain(self) -> QubesVM:
def backend_domain(self) -> Optional[QubesVM]:
""" Which domain exposed this port. (immutable)"""
return self.__backend_domain

Expand Down Expand Up @@ -387,6 +393,13 @@ def backend_domain(self):
return self.port.backend_domain
return '*'

@property
def backend_name(self):
if self.port != '*':
return self.port.backend_name
return '*'


@property
def port_id(self):
if self.port != '*' and self.port.port_id is not None:
Expand Down Expand Up @@ -1090,15 +1103,19 @@ def __lt__(self, other):

@property
def backend_domain(self):
return self.virtual_device.port.backend_domain
return self.virtual_device.backend_domain

@property
def backend_name(self) -> str:
return self.virtual_device.backend_name

@property
def port_id(self):
return self.virtual_device.port.port_id
return self.virtual_device.port_id

@property
def devclass(self):
return self.virtual_device.port.devclass
return self.virtual_device.devclass

@property
def device_id(self):
Expand Down

0 comments on commit ac42e08

Please sign in to comment.