Merge lp:~zyga/checkbox/fix-1323236 into lp:checkbox

Proposed by Zygmunt Krynicki
Status: Merged
Approved by: Ara Pulido
Approved revision: 3035
Merged at revision: 3035
Proposed branch: lp:~zyga/checkbox/fix-1323236
Merge into: lp:checkbox
Diff against target: 67 lines (+48/-7)
1 file modified
plainbox/plainbox/impl/exporter/xlsx.py (+48/-7)
To merge this branch: bzr merge lp:~zyga/checkbox/fix-1323236
Reviewer Review Type Date Requested Status
Ara Pulido (community) Approve
Daniel Manrique (community) Approve
Review via email: mp+221245@code.launchpad.net

Description of the change

db8aad9 plainbox:exporter:xlsx: more resilient bluetooth report

This is an alternative version of https://code.launchpad.net/~sylvain-pineau/checkbox/fix-1323236/+merge/221207 that should be more readable and maintainable over time. I hope.

To post a comment you must log in.
Revision history for this message
Daniel Manrique (roadmr) wrote :

Looks OK, the code is a bit more complex than the original but it should solve the problem.

review: Approve
Revision history for this message
Ara Pulido (ara) wrote :

That fixes the error for me.

review: Approve
Revision history for this message
Ara Pulido (ara) wrote :

Only BT devices appear in the XLS report

review: Needs Fixing
Revision history for this message
Ara Pulido (ara) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plainbox/plainbox/impl/exporter/xlsx.py'
2--- plainbox/plainbox/impl/exporter/xlsx.py 2014-05-21 10:46:09 +0000
3+++ plainbox/plainbox/impl/exporter/xlsx.py 2014-05-28 14:42:47 +0000
4@@ -229,15 +229,56 @@
5 '.1f')) for i in data["resource_map"]['2013.com.canonical.certification::meminfo']]
6 if result:
7 hw_info['memory'] = result.pop()
8- if '2013.com.canonical.certification::device' in data['resource_map']:
9- result = ['{}'.format(i['product'])
10- for i in data["resource_map"]['2013.com.canonical.certification::device']
11- if ('category' in i and i['category'] == 'BLUETOOTH' and
12- 'driver' in i)]
13- if result:
14- hw_info['bluetooth'] = result.pop()
15+ bluetooth = self._get_bluetooth_product_or_path(data)
16+ if bluetooth:
17+ hw_info['bluetooth'] = bluetooth
18 return hw_info
19
20+ def _get_resource_list(self, data, resource_id):
21+ """
22+ Get a list of resource objects associated with the specified job
23+ (resource) identifier
24+
25+ :param data:
26+ Exporter data
27+ :param resource_id:
28+ Identifier of the job / resource
29+ :returns:
30+ A list of matching resource objects. If there are no resources of
31+ that kind then an empty list list returned.
32+ """
33+ resource_map = data.get('resource_map')
34+ if not resource_map:
35+ return []
36+ return resource_map.get(resource_id, [])
37+
38+ def _get_bluetooth_product_or_path(
39+ self, data,
40+ resource_id='2013.com.canonical.certification::device'):
41+ """
42+ Get the 'product' or 'path' of the first bluetooth device.
43+
44+ :param data:
45+ Exporter data
46+ :param resource_id:
47+ (optional) Identifier of the device resource.
48+ :returns:
49+ The 'product' attribute, or the 'path' attribute or None if no such
50+ device can be found.
51+
52+ This method finds the name of the 'product' or 'path' attributes (first
53+ available one wins) associated with a resource that has a 'category'
54+ attribute equal to BLUETOOTH. The resource is looked using the supplied
55+ (default) resource identifier.
56+ """
57+ for resource in self._get_resource_list(data, resource_id):
58+ if resource.get('category') != 'BLUETOOTH':
59+ continue
60+ if 'product' in resource:
61+ return resource['product']
62+ if 'path' in resource:
63+ return resource['path']
64+
65 def write_systeminfo(self, data):
66 self.worksheet1.set_column(0, 0, 4)
67 self.worksheet1.set_column(1, 1, 34)

Subscribers

People subscribed via source and target branches