Skip to content

Commit

Permalink
feat: Enable --power-cycle/--no-power-cyle
Browse files Browse the repository at this point in the history
The sleep time is now --power-cycle-sleep and can be put into the config
as well.
  • Loading branch information
rumpelsepp committed Oct 31, 2022
1 parent 33933db commit 6d07ed7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/gallia/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,8 @@ def cmd_template(args: argparse.Namespace) -> None:
# db = <string>
# target = <string>
# power_supply = <string>
# power_cycle = <float>
# power_cycle = <bool>
# power_cycle_sleep = <float>
# dumpcap = <bool>
# artifacts_dir = <string>
# artifacts_base = <string>
Expand Down
24 changes: 14 additions & 10 deletions src/gallia/command/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,9 +524,11 @@ async def setup(self, args: Namespace) -> None:

if args.power_supply is not None:
self.power_supply = await PowerSupply.connect(args.power_supply)
if (time_ := args.power_cycle) is not None:
await self.power_supply.power_cycle(time_, lambda: asyncio.sleep(2))
elif args.power_cycle is not None:
if args.power_cycle is True:
await self.power_supply.power_cycle(
args.power_cycle_sleep, lambda: asyncio.sleep(2)
)
elif args.power_cycle is True:
self.parser.error("--power-cycle needs --power-supply")

# Start dumpcap as the first subprocess; otherwise network
Expand Down Expand Up @@ -577,14 +579,16 @@ def configure_class_parser(self) -> None:
)
group.add_argument(
"--power-cycle",
default=self.config.get_value("gallia.scanner.power_cycle"),
const=5.0,
nargs="?",
action=argparse.BooleanOptionalAction,
default=self.config.get_value("gallia.scanner.power_cycle", False),
help="trigger a powercycle before starting the scan",
)
group.add_argument(
"--power-cycle-sleep",
metavar="SECs",
type=float,
help=(
"trigger a powercycle before starting the scan; "
"optional argument specifies the sleep time in secs"
),
default=self.config.get_value("gallia.scanner.power_cycle_sleep", 5.0),
help="time to sleep after the power-cycle",
)

def entry_point(self, args: Namespace) -> int:
Expand Down

0 comments on commit 6d07ed7

Please sign in to comment.