-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Unvendor pydantic_argparse and wire up uv correctly
- Loading branch information
1 parent
1c8ea4b
commit 4778027
Showing
44 changed files
with
182 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# SPDX-FileCopyrightText: AISEC Pentesting Team | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# SPDX-FileCopyrightText: AISEC Pentesting Team | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import asyncio | ||
from collections.abc import Awaitable, Callable | ||
from typing import Self | ||
|
||
from gallia.log import get_logger | ||
from gallia.power_supply.base import BasePowerSupplyDriver | ||
from gallia.power_supply.devices.rs.hmc804 import HMC804 | ||
from gallia.power_supply.uri import PowerSupplyURI | ||
|
||
power_supply_drivers: list[type[BasePowerSupplyDriver]] = [HMC804] | ||
|
||
logger = get_logger(__name__) | ||
|
||
|
||
class PowerSupply: | ||
def __init__(self, driver: BasePowerSupplyDriver, channel_id: int | list[int]) -> None: | ||
self.channel_id = channel_id | ||
self.driver = driver | ||
self.mutex = asyncio.Lock() | ||
|
||
@classmethod | ||
async def connect(cls, target: PowerSupplyURI) -> Self: | ||
if target.product_id == "": | ||
raise ValueError("no device_id specified") | ||
|
||
for driver in power_supply_drivers: | ||
if target.product_id == driver.PRODUCT_ID: | ||
client = await driver.connect(target, timeout=1.0) | ||
return cls(client, target.channel) | ||
raise ValueError(f"{target.product_id} is not supported") | ||
|
||
async def _power(self, op: bool) -> None: | ||
assert self.driver | ||
if isinstance(self.channel_id, list): | ||
for id_ in self.channel_id: | ||
if id_ == 0: | ||
await self.driver.set_master(op) | ||
else: | ||
await self.driver.set_output(id_, op) | ||
elif isinstance(self.channel_id, int): | ||
if self.channel_id == 0: | ||
await self.driver.set_master(op) | ||
else: | ||
await self.driver.set_output(self.channel_id, op) | ||
|
||
async def power_up(self) -> None: | ||
logger.info("power up") | ||
await self._power(True) | ||
|
||
async def power_down(self) -> None: | ||
logger.info("power down") | ||
await self._power(False) | ||
|
||
async def power_cycle( | ||
self, | ||
sleep: float = 2.0, | ||
callback: Callable[[], Awaitable[None]] | None = None, | ||
) -> None: | ||
async with self.mutex: | ||
await self.power_down() | ||
await asyncio.sleep(sleep) | ||
await self.power_up() | ||
if callback is not None: | ||
await callback() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# SPDX-FileCopyrightText: AISEC Pentesting Team | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
from functools import partial | ||
|
||
from gallia.log import get_logger | ||
from gallia.transports import TargetURI | ||
|
||
logger = get_logger(__name__) | ||
|
||
|
||
class PowerSupplyURI(TargetURI): | ||
@property | ||
def id(self) -> int: | ||
if "id" in self.qs: | ||
return int(self.qs["id"][0], 0) | ||
return 0 | ||
|
||
@property | ||
def channel(self) -> int | list[int]: | ||
if "channel" in self.qs: | ||
if len(ch := self.qs["channel"]) == 1: | ||
return int(ch[0], 0) | ||
return list(map(partial(int, base=0), ch)) | ||
return 0 | ||
|
||
@property | ||
def product_id(self) -> str: | ||
if "product_id" in self.qs: | ||
return self.qs["product_id"][0] | ||
return "" |
Oops, something went wrong.