Skip to content

Commit

Permalink
Fix black format
Browse files Browse the repository at this point in the history
  • Loading branch information
rickwu666666 committed Apr 15, 2024
1 parent 9a6dfa4 commit d55effe
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 131 deletions.
63 changes: 20 additions & 43 deletions contrib/checkbox-ce-oem/checkbox-provider-ce-oem/bin/check_gpio.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import argparse
import os
from contextlib import contextmanager

# from checkbox_support.snap_utils.snapd import Snapd
from checkbox_support.snap_utils.snapd import Snapd
from checkbox_support.snap_utils.system import get_gadget_snap
Expand Down Expand Up @@ -96,7 +97,9 @@ def check_gpio_list(gpio_list, config):
for gpio_slot in expect_port:
print(
"Error: Slot of GPIO {} is not defined in gadget snap".
format(gpio_slot)
format(
gpio_slot
)
)
raise SystemExit(1)
else:
Expand All @@ -107,25 +110,16 @@ def check_gpio_list(gpio_list, config):

@contextmanager
def interface_test(gpio_slot, gadget_name, timeout=60):
snap = os.environ['SNAP_NAME']
timeout = int(os.environ.get('SNAPD_TASK_TIMEOUT', timeout))
snap = os.environ["SNAP_NAME"]
timeout = int(os.environ.get("SNAPD_TASK_TIMEOUT", timeout))
try:
connect_interface(gadget_name,
gpio_slot,
snap,
timeout)
connect_interface(gadget_name, gpio_slot, snap, timeout)
yield
finally:
disconnect_interface(gadget_name,
gpio_slot,
snap,
timeout)
disconnect_interface(gadget_name, gpio_slot, snap, timeout)


def connect_interface(gadget_name,
gpio_slot,
snap,
timeout):
def connect_interface(gadget_name, gpio_slot, snap, timeout):
"""
Connect GPIO plugs of checkbox to GPIO slots of gadget snap.
Expand All @@ -141,21 +135,14 @@ def connect_interface(gadget_name,
print("Attempting connect GPIO to {}:{}".format(gadget_name, gpio_slot))
try:
Snapd(task_timeout=timeout).connect(
gadget_name,
gpio_slot,
snap,
"gpio"
)
gadget_name, gpio_slot, snap, "gpio")
print("Success")
except requests.HTTPError:
print("Failed to connect {}".format(gpio_slot))
raise SystemExit(1)


def disconnect_interface(gadget_name,
gpio_slot,
snap,
timeout):
def disconnect_interface(gadget_name, gpio_slot, snap, timeout):
"""
Connect GPIO plugs of checkbox to GPIO slots of gadget snap.
Expand All @@ -172,11 +159,7 @@ def disconnect_interface(gadget_name,
format(gadget_name, gpio_slot))
try:
Snapd(task_timeout=timeout).disconnect(
gadget_name,
gpio_slot,
snap,
"gpio"
)
gadget_name, gpio_slot, snap, "gpio")
print("Success")
except requests.HTTPError:
print("Failed to disconnect {}".format(gpio_slot))
Expand Down Expand Up @@ -204,36 +187,33 @@ def check_node(num):
def main():
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(
dest='action',
dest="action",
help="Action in check-gpio, check-node and dump",
)
)
check_gpio_subparser = subparsers.add_parser("check-gpio")
check_gpio_subparser.add_argument(
"-c",
"--config",
required=True,
help="Checkbox config include expected GPIO\
e.g. 499:500:501:502",
)
)
check_node_subparser = subparsers.add_parser("check-node")
check_node_subparser.add_argument(
"-n",
"--num",
type=int,
required=True,
help="GPIO number to check if node exported",
)
)
check_node_subparser.add_argument(
"-s",
"--slot",
type=str,
required=True,
help="GPIO slot to connect.",
)
subparsers.add_parser(
"dump",
help="Dump GPIO slots from gadget"
)
)
subparsers.add_parser("dump", help="Dump GPIO slots from gadget")
args = parser.parse_args()
snapd = Snapd()
gadget_name = get_gadget_snap()
Expand All @@ -242,11 +222,8 @@ def main():
check_gpio_list(gpio_slots, args.config)
if args.action == "dump":
for x in gpio_slots:
print(
"slot: {}\ngpio_number: {}\n".format(
x, gpio_slots[x]["number"]
)
)
print("slot: {}\ngpio_number: {}\n".
format(x, gpio_slots[x]["number"]))
if args.action == "check-node":
with interface_test(args.slot, gadget_name):
check_node(args.num)
Expand Down
Loading

0 comments on commit d55effe

Please sign in to comment.