Skip to content

Commit 28b859b

Browse files
doc: use REPL syntax where appropriate
Most examples are meant to demonstrate some aspect on how to use labgrid. These are best displayed as if typed into a REPL shell. This will also ease automated testing of examples in a future commit. Signed-off-by: Bastian Krause <bst@pengutronix.de>
1 parent 4944abc commit 28b859b

2 files changed

Lines changed: 40 additions & 53 deletions

File tree

doc/configuration.rst

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2628,12 +2628,11 @@ to transition to the shell state:
26282628

26292629
::
26302630

2631-
from labgrid import Environment
2632-
2633-
e = Environment("local.yaml")
2634-
t = e.get_target("main")
2635-
s = t.get_driver("BareboxStrategy")
2636-
s.transition("shell")
2631+
>>> from labgrid import Environment
2632+
>>> e = Environment("local.yaml")
2633+
>>> t = e.get_target("main")
2634+
>>> s = t.get_driver("BareboxStrategy")
2635+
>>> s.transition("shell")
26372636

26382637

26392638
this command would transition from the bootloader into a Linux shell and
@@ -2652,12 +2651,11 @@ to transition to the shell state:
26522651

26532652
::
26542653

2655-
from labgrid import Environment
2656-
2657-
e = Environment("local.yaml")
2658-
t = e.get_target("main")
2659-
s = t.get_driver("ShellStrategy")
2660-
s.transition("shell")
2654+
>>> from labgrid import Environment
2655+
>>> e = Environment("local.yaml")
2656+
>>> t = e.get_target("main")
2657+
>>> s = t.get_driver("ShellStrategy")
2658+
>>> s.transition("shell")
26612659

26622660

26632661
this command would transition directly into a Linux shell and
@@ -2677,12 +2675,11 @@ to transition to the shell state:
26772675

26782676
::
26792677

2680-
from labgrid import Environment
2681-
2682-
e = Environment("local.yaml")
2683-
t = e.get_target("main")
2684-
s = t.get_driver("UBootStrategy")
2685-
s.transition("shell")
2678+
>>> from labgrid import Environment
2679+
>>> e = Environment("local.yaml")
2680+
>>> t = e.get_target("main")
2681+
>>> s = t.get_driver("UBootStrategy")
2682+
>>> s.transition("shell")
26862683

26872684

26882685
this command would transition from the bootloader into a Linux shell and
@@ -2701,12 +2698,11 @@ To transition to the shell state:
27012698

27022699
::
27032700

2704-
from labgrid import Environment
2705-
2706-
e = Environment("local.yaml")
2707-
t = e.get_target("main")
2708-
s = t.get_driver("DockerShellStrategy")
2709-
s.transition("shell")
2701+
>>> from labgrid import Environment
2702+
>>> e = Environment("local.yaml")
2703+
>>> t = e.get_target("main")
2704+
>>> s = t.get_driver("DockerShellStrategy")
2705+
>>> s.transition("shell")
27102706

27112707

27122708
These commands would activate the docker driver which creates and starts
@@ -2727,17 +2723,15 @@ The StepReporter outputs individual labgrid steps to `STDOUT`.
27272723

27282724
::
27292725

2730-
from labgrid import StepReporter
2731-
2732-
StepReporter.start()
2726+
>>> from labgrid import StepReporter
2727+
>>> StepReporter.start()
27332728

27342729
The Reporter can be stopped with a call to the stop function:
27352730

27362731
::
27372732

2738-
from labgrid import StepReporter
2739-
2740-
StepReporter.stop()
2733+
>>> from labgrid import StepReporter
2734+
>>> StepReporter.stop()
27412735

27422736
Stopping the StepReporter if it has not been started will raise an
27432737
AssertionError, as will starting an already started StepReporter.
@@ -2754,17 +2748,15 @@ files. It takes the path as a parameter.
27542748

27552749
::
27562750

2757-
from labgrid import ConsoleLoggingReporter
2758-
2759-
ConsoleLoggingReporter.start(".")
2751+
>>> from labgrid import ConsoleLoggingReporter
2752+
>>> ConsoleLoggingReporter.start(".")
27602753

27612754
The Reporter can be stopped with a call to the stop function:
27622755

27632756
::
27642757

2765-
from labgrid import ConsoleLoggingReporter
2766-
2767-
ConsoleLoggingReporter.stop()
2758+
>>> from labgrid import ConsoleLoggingReporter
2759+
>>> ConsoleLoggingReporter.stop()
27682760

27692761

27702762
Stopping the ConsoleLoggingReporter if it has not been started will raise an

doc/development.rst

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -515,25 +515,22 @@ To use the SSHManager in your code, import it from :any:`labgrid.util.ssh`:
515515

516516
.. code-block:: python
517517
518-
from labgrid.util import sshmanager
518+
>>> from labgrid.util import sshmanager
519519
520520
you can now request or remove port forwardings:
521521

522522
.. code-block:: python
523523
524-
from labgrid.util import sshmanager
525-
526-
localport = sshmanager.request_forward('localhost', 'somehost', 3000)
527-
528-
sshmanager.remove_forward('localhost', 'somehost', 3000)
524+
>>> from labgrid.util import sshmanager
525+
>>> localport = sshmanager.request_forward('localhost', 'somehost', 3000)
526+
>>> sshmanager.remove_forward('localhost', 'somehost', 3000)
529527
530528
or get and put files:
531529

532530
.. code-block:: python
533531
534-
from labgrid.util import sshmanager
535-
536-
sshmanager.put_file('somehost', '/path/to/local/file', '/path/to/remote/file')
532+
>>> from labgrid.util import sshmanager
533+
>>> sshmanager.put_file('somehost', '/path/to/local/file', '/path/to/remote/file')
537534
538535
.. note::
539536
The SSHManager will reuse existing Control Sockets and set up a keepalive loop
@@ -556,11 +553,10 @@ To use it in conjunction with a `Resource` and a file:
556553

557554
.. code-block:: python
558555
559-
from labgrid.util.managedfile import ManagedFile
560-
561-
mf = ManagedFile(<your-file>, <your-resource>)
562-
mf.sync_to_resource()
563-
path = mf.get_remote_path()
556+
>>> from labgrid.util.managedfile import ManagedFile
557+
>>> mf = ManagedFile(<your-file>, <your-resource>)
558+
>>> mf.sync_to_resource()
559+
>>> path = mf.get_remote_path()
564560
565561
Unless constructed with `ManagedFile(..., detect_nfs=False)`, ManagedFile
566562
employs the following heuristic to check if a file is stored on a NFS share
@@ -585,9 +581,8 @@ Usage:
585581

586582
.. code-block:: python
587583
588-
from labgrid.util.proxy import proxymanager
589-
590-
proxymanager.get_host_and_port(<resource>)
584+
>>> from labgrid.util.proxy import proxymanager
585+
>>> proxymanager.get_host_and_port(<resource>)
591586
592587
593588
.. _contributing:

0 commit comments

Comments
 (0)