Merge lp:~cypressyew/checkbox/fix-missing-optical-resource into lp:checkbox

Proposed by Po-Hsu Lin
Status: Merged
Approved by: Sylvain Pineau
Approved revision: 3104
Merged at revision: 3106
Proposed branch: lp:~cypressyew/checkbox/fix-missing-optical-resource
Merge into: lp:checkbox
Diff against target: 84 lines (+80/-0)
1 file modified
providers/plainbox-provider-resource-generic/bin/optical_resource (+80/-0)
To merge this branch: bzr merge lp:~cypressyew/checkbox/fix-missing-optical-resource
Reviewer Review Type Date Requested Status
Sylvain Pineau (community) Approve
Zygmunt Krynicki (community) Needs Information
Review via email: mp+225607@code.launchpad.net

Description of the change

I am not sure if I did this right :P
But it works with this file in plainbox-resources/bin

To post a comment you must log in.
Revision history for this message
Zygmunt Krynicki (zyga) wrote :

This is probably okay but IIRC we have a number of optical-resource-like scripts now and before we merge this one in I'd like to ensure that we don't have responsibility duplicates (separate tools that effectively try to do the same thing).

Thanks

review: Needs Information
Revision history for this message
Sylvain Pineau (sylvain-pineau) wrote :

We removed the previous resource job/scripts that used wodim to guess the capabilities of a drive. The only script that we need is the one that was left in checkbox-legacy.

So +1 sor resurecting the missing one.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'providers/plainbox-provider-resource-generic/bin/optical_resource'
2--- providers/plainbox-provider-resource-generic/bin/optical_resource 1970-01-01 00:00:00 +0000
3+++ providers/plainbox-provider-resource-generic/bin/optical_resource 2014-07-04 07:23:58 +0000
4@@ -0,0 +1,80 @@
5+#!/usr/bin/python3
6+# -*- coding: utf-8 -*-
7+#
8+# color_depth_info
9+#
10+# This file is part of Checkbox.
11+#
12+# Copyright 2014 Canonical Ltd.
13+#
14+# Authors: Brendan Donegan <brendan.donegan@canonical.com>
15+#
16+# Checkbox is free software: you can redistribute it and/or modify
17+# it under the terms of the GNU General Public License version 3,
18+# as published by the Free Software Foundation.
19+
20+#
21+# Checkbox is distributed in the hope that it will be useful,
22+# but WITHOUT ANY WARRANTY; without even the implied warranty of
23+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24+# GNU General Public License for more details.
25+#
26+# You should have received a copy of the GNU General Public License
27+# along with Checkbox. If not, see <http://www.gnu.org/licenses/>.
28+
29+"""
30+This script discovers the types of media supported by a named optical drive
31+and the capabilities available for that media. It uses the information
32+provided by udev for this purpose. Currently supported media types and
33+capabilities are:
34+
35+* CD
36+ * Read
37+ * Write
38+ * Rewrite
39+* DVD
40+ * Read
41+ * Write
42+ * Rewrite
43+* Blu-Ray (BD)
44+ * Read
45+ * Write
46+ * Rewrite
47+"""
48+
49+import sys
50+
51+from argparse import ArgumentParser
52+from collections import OrderedDict
53+from subprocess import check_output, CalledProcessError
54+
55+CAP_MAP = OrderedDict([('ID_CDROM_CD=1', 'cd_read'),
56+ ('ID_CDROM_CD_R=1', 'cd_write'),
57+ ('ID_CDROM_CD_RW=1', 'cd_rewrite'),
58+ ('ID_CDROM_DVD=1', 'dvd_read'),
59+ ('ID_CDROM_DVD_R=1', 'dvd_write'),
60+ ('ID_CDROM_DVD_RW=1', 'dvd_rewrite'),
61+ ('ID_CDROM_BD=1', 'bd_read'),
62+ ('ID_CDROM_BD_R=1', 'bd_write'),
63+ ('ID_CDROM_BD_RE=1', 'bd_rewrite')])
64+
65+
66+def main():
67+ parser = ArgumentParser("Shows which capabilities are supported "
68+ "by the specified optical device.")
69+ parser.add_argument("device",
70+ help="The optical device to get capabilities for")
71+ args = parser.parse_args()
72+
73+ try:
74+ cdrom_id = check_output(['/lib/udev/cdrom_id', args.device],
75+ universal_newlines=True).split('\n')
76+ except CalledProcessError:
77+ return 1
78+ if cdrom_id:
79+ for cap in CAP_MAP:
80+ if cap in cdrom_id:
81+ print(CAP_MAP[cap] + ": supported")
82+
83+if __name__ == "__main__":
84+ sys.exit(main())

Subscribers

People subscribed via source and target branches