Merge ~kissiel/pigbox:dev into pigbox:master

Proposed by Maciej Kisielewski
Status: Approved
Approved by: Maciej Kisielewski
Approved revision: f58f5b4b6ff3cdc5d0fcc3b1a5f9dd31f6f0700c
Proposed branch: ~kissiel/pigbox:dev
Merge into: pigbox:master
Diff against target: 127 lines (+114/-1)
2 files modified
pigbox/__init__.py (+65/-1)
pigbox/capabilities.py (+49/-0)
Reviewer Review Type Date Requested Status
Sylvain Pineau (community) Approve
Maciej Kisielewski Pending
Review via email: mp+372991@code.launchpad.net

Description of the change

Basic functionality implementation.

Prepare doesn't do anything yet as I need to work out where to store stateful info.

To post a comment you must log in.
Revision history for this message
Sylvain Pineau (sylvain-pineau) wrote :

LGTM

review: Approve

Unmerged commits

f58f5b4... by Maciej Kisielewski

implement basic functionality

207d8e9... by Maciej Kisielewski

add basic subcmd skeleton

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/pigbox/__init__.py b/pigbox/__init__.py
2index 559fbb7..d622e65 100644
3--- a/pigbox/__init__.py
4+++ b/pigbox/__init__.py
5@@ -1,2 +1,66 @@
6+# Copyright 2019 Canonical Ltd.
7+# Written by:
8+# Maciej Kisielewski <maciej.kisielewski@canonical.com>
9+#
10+# Checkbox is free software: you can redistribute it and/or modify
11+# it under the terms of the GNU General Public License version 3,
12+# as published by the Free Software Foundation.
13+#
14+# Checkbox is distributed in the hope that it will be useful,
15+# but WITHOUT ANY WARRANTY; without even the implied warranty of
16+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+# GNU General Public License for more details.
18+#
19+# You should have received a copy of the GNU General Public License
20+# along with Checkbox. If not, see <http://www.gnu.org/licenses/>.
21+import argparse
22+import subprocess
23+import sys
24+
25+from pigbox.capabilities import has_hdmi_bridge
26+
27+class Pigbox:
28+ def prepare(self):
29+ parser = argparse.ArgumentParser(
30+ description="Prepare PIG for running tests"
31+ )
32+ parser.add_argument(
33+ 'teardown_command', help="Command to run after testing"
34+ )
35+ parser.add_argument(
36+ 'prepare_command', help="Command that prepares the PIG environment"
37+ )
38+ args = parser.parse_args(sys.argv[2:])
39+ def run(self):
40+ parser = argparse.ArgumentParser(
41+ description="Run command in the PIG environment"
42+ )
43+ parser.add_argument('command', help="Command to run")
44+ args = parser.parse_args(sys.argv[2:])
45+ subprocess.run(args.command, shell=True)
46+ def teardown(self):
47+ parser = argparse.ArgumentParser(
48+ description="Clear the PIG environment"
49+ )
50+ args = parser.parse_args(sys.argv[2:])
51+ def capabilities(self):
52+ parser = argparse.ArgumentParser(
53+ description="List capabilities currently available"
54+ )
55+ args = parser.parse_args(sys.argv[2:])
56+ if has_hdmi_bridge():
57+ print("hdmi_bridge: installed")
58+ print()
59+
60+
61 def main():
62- return
63+ parser = argparse.ArgumentParser(
64+ description="Control PI testing riG",
65+ usage="{} <ACTION> [COMMAND] ...".format(sys.argv[0]),
66+ )
67+ parser.add_argument('action', help="Action to run")
68+ args = parser.parse_args(sys.argv[1:2])
69+ app = Pigbox()
70+ if not hasattr(app, args.action):
71+ raise SystemExit("Unknown action '{}'".format(args.action))
72+ return getattr(app, args.action)()
73diff --git a/pigbox/capabilities.py b/pigbox/capabilities.py
74new file mode 100644
75index 0000000..5701eb4
76--- /dev/null
77+++ b/pigbox/capabilities.py
78@@ -0,0 +1,49 @@
79+# Copyright 2019 Canonical Ltd.
80+# Written by:
81+# Maciej Kisielewski <maciej.kisielewski@canonical.com>
82+#
83+# Checkbox is free software: you can redistribute it and/or modify
84+# it under the terms of the GNU General Public License version 3,
85+# as published by the Free Software Foundation.
86+#
87+# Checkbox is distributed in the hope that it will be useful,
88+# but WITHOUT ANY WARRANTY; without even the implied warranty of
89+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
90+# GNU General Public License for more details.
91+#
92+# You should have received a copy of the GNU General Public License
93+# along with Checkbox. If not, see <http://www.gnu.org/licenses/>.
94+import subprocess
95+import sys
96+
97+def has_hdmi_bridge():
98+ # the heuristic here is based on `v4l2-ctl --info-edid` output
99+ # I found three known responses, depending on the state:
100+ # 1. command returns nothing and the error code is 0 when there is no hdmi
101+ # bridge connected
102+ # 2. command returns an error (error code 255) and some message(s) if
103+ # the bridge is connected, but it hasn't been programmed with any EDID
104+ # info yet (for instance after a reboot)
105+ # 3. command returns no error and prints out edid info when the bridge
106+ # is connected and operational
107+ try:
108+ output = subprocess.check_output(
109+ ['v4l2-ctl', '--info-edid'], stderr=subprocess.PIPE
110+ ).decode(sys.stdout.encoding)
111+ except subprocess.CalledProcessError as exc:
112+ if exc.returncode == 255:
113+ # case 2. EDID not programmed, but the bridge's there
114+ return True
115+ elif exc.returncode == 1:
116+ print("There was a problem with v4l2-ctl invocation",
117+ file=sys.stderr)
118+ print(exc.stderr.decode(sys.stderr.encoding), file=sys.stderr)
119+ return False
120+ except FileNotFoundError:
121+ print("v4l2-ctl not found", file=sys.stderr)
122+ return False
123+ if not output:
124+ # case 1.
125+ return False
126+ # case 3.
127+ return True

Subscribers

People subscribed via source and target branches

to all changes: