devices: add device path helper functions
Add new helper functions that can translate from a managed device to its path. One is relative and one is the absolute path on the host, i.e. to the device node on the host.
This commit is contained in:
parent
a5e07cf506
commit
2447172125
1 changed files with 14 additions and 5 deletions
|
|
@ -15,8 +15,9 @@ support in osbuild itself is abstract.
|
|||
import abc
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
|
||||
from typing import Dict
|
||||
from typing import Dict, Optional
|
||||
|
||||
from osbuild import host
|
||||
|
||||
|
|
@ -57,12 +58,20 @@ class DeviceManager:
|
|||
self.tree = tree
|
||||
self.devices = {}
|
||||
|
||||
def device_relpath(self, dev: Optional[Device]) -> Optional[str]:
|
||||
if dev is None:
|
||||
return None
|
||||
return self.devices[dev.name]["path"]
|
||||
|
||||
def device_abspath(self, dev: Optional[Device]) -> Optional[str]:
|
||||
relpath = self.device_relpath(dev)
|
||||
if relpath is None:
|
||||
return None
|
||||
return os.path.join(self.devpath, relpath)
|
||||
|
||||
def open(self, dev: Device) -> Dict:
|
||||
|
||||
if dev.parent:
|
||||
parent = self.devices[dev.parent.name]["path"]
|
||||
else:
|
||||
parent = None
|
||||
parent = self.device_relpath(dev.parent)
|
||||
|
||||
args = {
|
||||
# global options
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue