Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

examples: fixes, cleanup, use StepLogger instead of StepReporter #1449

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions examples/deditec-relais8/deditec.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
import sys
import labgrid
import logging
import time

from labgrid import Environment, StepReporter
from labgrid.strategy.bareboxstrategy import Status
from labgrid.driver.deditecrelaisdriver import DeditecRelaisDriver
from labgrid import Target
from labgrid.logging import basicConfig, StepLogger
from labgrid.resource.udev import DeditecRelais8
from labgrid.driver import DeditecRelaisDriver

# enable debug logging
logging.basicConfig(
level=logging.DEBUG,
format='%(levelname)7s: %(message)s',
stream=sys.stderr,
)
# enable info logging
basicConfig(level=logging.INFO)

# show labgrid steps on the console
StepReporter.start()
# log labgrid steps
StepLogger.start()

t = labgrid.Target('main')
r = labgrid.resource.udev.DeditecRelais8(t, name=None, index=1)
t = Target('main')
r = DeditecRelais8(t, name=None, index=1)
d = DeditecRelaisDriver(t, name=None)

p = t.get_driver("DigitalOutputProtocol")
Expand Down
19 changes: 6 additions & 13 deletions examples/deditec-relais8/deditec_remote.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
import sys
import labgrid
import logging
import time

from labgrid import Environment, StepReporter
from labgrid.strategy.bareboxstrategy import Status
from labgrid.driver.deditecrelaisdriver import DeditecRelaisDriver
from labgrid import Environment
from labgrid.logging import basicConfig, StepLogger

# enable debug logging
logging.basicConfig(
level=logging.DEBUG,
format='%(levelname)7s: %(message)s',
stream=sys.stderr,
)
# enable info logging
basicConfig(level=logging.INFO)

# show labgrid steps on the console
StepReporter.start()
StepLogger.start()

e = labgrid.Environment('import-dedicontrol.yaml')
e = Environment('import-dedicontrol.yaml')
t = e.get_target()

p = t.get_driver("DigitalOutputProtocol")
Expand Down
15 changes: 6 additions & 9 deletions examples/library/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,16 @@
import sys
import logging

from labgrid import Environment, StepReporter
from labgrid import Environment
from labgrid.logging import basicConfig, StepLogger
from labgrid.strategy.bareboxstrategy import Status


# enable debug logging
logging.basicConfig(
level=logging.DEBUG,
format='%(levelname)7s: %(message)s',
stream=sys.stderr,
)
# enable info logging
basicConfig(level=logging.INFO)

# show labgrid steps on the console
StepReporter.start()
# log labgrid steps
StepLogger.start()

def run_once(target):
s = target.get_driver('BareboxStrategy')
Expand Down
13 changes: 5 additions & 8 deletions examples/networkmanager/nm.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import logging, sys
import logging
from pprint import pprint

from labgrid import *
from labgrid import Environment
from labgrid.logging import basicConfig, StepLogger


# enable debug logging
logging.basicConfig(
level=logging.DEBUG,
format='%(levelname)7s: %(message)s',
stream=sys.stderr,
)
basicConfig(level=logging.DEBUG)

# show labgrid steps on the console
StepReporter.start()
StepLogger.start()


e = Environment('nm.env')
Expand Down
8 changes: 4 additions & 4 deletions examples/qemu-networking/qemunetworkstrategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import attr

from labgrid import target_factory, step
from labgrid.strategy import Strategy
from labgrid.strategy import Strategy, StrategyError
from labgrid.util import get_free_port


Expand Down Expand Up @@ -75,15 +75,15 @@ def update_network_service(self):
networkservice.port = local_port
else:
networkservice.address = new_address
networkserivce.port = self.__remote_port
networkservice.port = self.__remote_port

@step(args=["state"])
def transition(self, state, *, step):
if not isinstance(state, Status):
state = Status[state]

if state == Status.unknown:
raise StrategyError(f"can not transition to {new_status}")
raise StrategyError(f"can not transition to {state}")

elif self.status == state:
step.skip("nothing to do")
Expand All @@ -99,4 +99,4 @@ def transition(self, state, *, step):
self.target.activate(self.shell)
self.update_network_service()

self.status = status
self.status = state
9 changes: 3 additions & 6 deletions examples/sigrok/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@
import logging

from labgrid import Environment
from labgrid.logging import basicConfig

# enable debug logging
logging.basicConfig(
level=logging.DEBUG,
format='%(levelname)7s: %(message)s',
stream=sys.stderr,
)
# enable info logging
basicConfig(level=logging.INFO)

env = Environment(sys.argv[1])
target = env.get_target('main')
Expand Down
5 changes: 2 additions & 3 deletions examples/strategy/bareboxrebootstrategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

import attr

from labgrid import target_factory, step
from labgrid.driver import BareboxDriver, ShellDriver
from labgrid.protocol import PowerProtocol
from labgrid.factory import target_factory
from labgrid.step import step
from labgrid.strategy.common import Strategy
from labgrid.strategy import Strategy


@attr.s(eq=False)
Expand Down
5 changes: 2 additions & 3 deletions examples/strategy/quartusstrategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

import attr

from labgrid import target_factory, step
from labgrid.driver import QuartusHPSDriver, SerialDriver
from labgrid.factory import target_factory
from labgrid.protocol import PowerProtocol
from labgrid.step import step
from labgrid.strategy.common import Strategy
from labgrid.strategy import Strategy


@attr.s(eq=False)
Expand Down
2 changes: 0 additions & 2 deletions examples/strategy/test_barebox_strategy.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import pytest

from labgrid.exceptions import NoDriverFoundError


@pytest.fixture(scope="function")
def in_bootloader(strategy, capsys):
Expand Down
22 changes: 9 additions & 13 deletions examples/sysfsgpio/sysfsgpio.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
import sys
import labgrid
import logging
import time

from labgrid import Environment, StepReporter
from labgrid.driver.gpiodriver import GpioDigitalOutputDriver
from labgrid import Target
from labgrid.logging import basicConfig, StepLogger
from labgrid.driver import GpioDigitalOutputDriver
from labgrid.resource import SysfsGPIO

# enable debug logging
logging.basicConfig(
level=logging.DEBUG,
format='%(levelname)7s: %(message)s',
stream=sys.stderr,
)
# enable info logging
basicConfig(level=logging.INFO)

# show labgrid steps on the console
StepReporter.start()
StepLogger.start()

t = labgrid.Target('main')
r = labgrid.resource.base.SysfsGPIO(t, name=None, index=60)
t = Target('main')
r = SysfsGPIO(t, name=None, index=60)
d = GpioDigitalOutputDriver(t, name=None)

p = t.get_driver("DigitalOutputProtocol")
Expand Down
18 changes: 6 additions & 12 deletions examples/sysfsgpio/sysfsgpio_remote.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
import sys
import labgrid
import logging
import time

from labgrid import Environment, StepReporter
from labgrid.driver.gpiodriver import GpioDigitalOutputDriver
from labgrid import Environment
from labgrid.logging import basicConfig, StepLogger

# enable debug logging
logging.basicConfig(
level=logging.DEBUG,
format='%(levelname)7s: %(message)s',
stream=sys.stderr,
)
# enable info logging
basicConfig(level=logging.INFO)

# show labgrid steps on the console
StepReporter.start()
StepLogger.start()

e = labgrid.Environment('import-gpio.yaml')
e = Environment('import-gpio.yaml')
t = e.get_target()

p = t.get_driver("DigitalOutputProtocol")
Expand Down
3 changes: 1 addition & 2 deletions examples/usbpower/examplestrategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
import attr

from labgrid.driver import BareboxDriver, ShellDriver, USBSDMuxDriver
from labgrid.factory import target_factory
from labgrid import step, target_factory
from labgrid.protocol import PowerProtocol
from labgrid.step import step
from labgrid.strategy import Strategy


Expand Down
2 changes: 0 additions & 2 deletions examples/usbpower/test_example.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import pytest

from labgrid.exceptions import NoDriverFoundError


@pytest.fixture(scope="function")
def bootloader(target, strategy, capsys):
Expand Down
Loading