Merge lp:~salgado/linaro-image-tools/bug-687636 into lp:linaro-image-tools/11.11

Proposed by Guilherme Salgado
Status: Merged
Merged at revision: 232
Proposed branch: lp:~salgado/linaro-image-tools/bug-687636
Merge into: lp:linaro-image-tools/11.11
Diff against target: 178 lines (+51/-24)
3 files modified
linaro-hwpack-install (+2/-1)
media_create/check_device.py (+27/-20)
media_create/tests/test_media_create.py (+22/-3)
To merge this branch: bzr merge lp:~salgado/linaro-image-tools/bug-687636
Reviewer Review Type Date Requested Status
James Westby (community) Approve
Review via email: mp+45363@code.launchpad.net

Description of the change

To post a comment you must log in.
Revision history for this message
James Westby (james-w) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'linaro-hwpack-install'
2--- linaro-hwpack-install 2010-12-16 02:19:53 +0000
3+++ linaro-hwpack-install 2011-01-06 13:02:59 +0000
4@@ -137,7 +137,8 @@
5 echo "deb file:${HWPACK_DIR}/pkgs ./" > "$SOURCES_LIST_FILE"
6 cat /etc/apt/sources.list >> "$SOURCES_LIST_FILE"
7
8-sudo apt-get -o "$APT_GET_OPTIONS" update -qq
9+echo "Updating apt package lists ..."
10+sudo apt-get -o "$APT_GET_OPTIONS" update -q
11
12 echo -n "Installing packages ..."
13
14
15=== modified file 'media_create/check_device.py'
16--- media_create/check_device.py 2011-01-03 11:51:36 +0000
17+++ media_create/check_device.py 2011-01-06 13:02:59 +0000
18@@ -1,13 +1,15 @@
19+import glob
20 import sys
21
22 import dbus
23
24+from media_create import partitions
25+
26
27 def _get_system_bus_and_udisks_iface():
28 """Return the system bus and the UDisks interface.
29
30 :return: System bus and UDisks inteface tuple.
31-
32 """
33 bus = dbus.SystemBus()
34 udisks = dbus.Interface(
35@@ -24,7 +26,6 @@
36 :param device: Device object.
37 :param path: Device path.
38 :return: Device property.
39-
40 """
41 return device.Get(
42 path, prop, dbus_interface='org.freedesktop.DBus.Properties')
43@@ -35,7 +36,6 @@
44
45 :param path: Disk device path.
46 :return: True if the device exist, else False.
47-
48 """
49 bus, udisks = _get_system_bus_and_udisks_iface()
50 try:
51@@ -49,7 +49,6 @@
52
53 def _print_devices():
54 """Print disk devices found on the system."""
55-
56 bus, udisks = _get_system_bus_and_udisks_iface()
57 print '%-16s %-16s %s' % ('Device', 'Mount point', 'Size')
58 devices = udisks.get_dbus_method('EnumerateDevices')()
59@@ -77,35 +76,42 @@
60
61 :param device: Device path.
62 :return: True if the user confirms the selection, else False.
63-
64 """
65-
66 resp = raw_input('Are you 100%% sure, on selecting [%s] (y/n)? ' % device)
67 if resp.lower() != 'y':
68 return False
69 return True
70
71
72-def check_device(path):
73- """Checks that a selected device exists.
74-
75- If the device exist, the user is asked to confirm that this is the
76- device to use.
77-
78- :param path: Device path.
79+def _ensure_device_partitions_not_mounted(device):
80+ """Ensure all partitions of the given device are not mounted."""
81+ # Use '%s?*' as we only want the device files representing
82+ # partitions and not the one representing the device itself.
83+ for part in glob.glob('%s?*' % device):
84+ partitions.ensure_partition_is_not_mounted(part)
85+
86+
87+def confirm_device_selection_and_ensure_it_is_ready(device):
88+ """Confirm this is the device to use and ensure it's ready.
89+
90+ If the device exists, the user is asked to confirm that this is the
91+ device to use. Upon confirmation we ensure all partitions of the device
92+ are umounted.
93+
94+ :param device: The path to the device.
95 :return: True if the device exist and is selected, else False.
96-
97 """
98-
99- if _does_device_exist(path):
100+ if _does_device_exist(device):
101 print '\nI see...'
102 _print_devices()
103- return _select_device(path)
104+ if _select_device(device):
105+ _ensure_device_partitions_not_mounted(device)
106+ return True
107 else:
108- print '\nAre you sure? I do not see [%s].' % path
109+ print '\nAre you sure? I do not see [%s].' % device
110 print 'Here is what I see...'
111 _print_devices()
112- return False
113+ return False
114
115
116 if __name__ == '__main__':
117@@ -113,7 +119,8 @@
118 print 'usage: ' + sys.argv[0] + ' <DEVICE>'
119 sys.exit(2)
120
121- device_selected = check_device(sys.argv[1])
122+ device_selected = confirm_device_selection_and_ensure_it_is_ready(
123+ sys.argv[1])
124 if device_selected:
125 sys.exit(0)
126 else:
127
128=== modified file 'media_create/tests/test_media_create.py'
129--- media_create/tests/test_media_create.py 2011-01-05 19:32:02 +0000
130+++ media_create/tests/test_media_create.py 2011-01-06 13:02:59 +0000
131@@ -1,5 +1,6 @@
132 from contextlib import contextmanager
133 import atexit
134+import glob
135 import os
136 import random
137 import string
138@@ -656,19 +657,37 @@
139 self._mock_sys_stdout()
140 self._mock_print_devices()
141
142+ def test_ensure_device_partitions_not_mounted(self):
143+ partitions_umounted = []
144+ def ensure_partition_is_not_mounted_mock(part):
145+ partitions_umounted.append(part)
146+ self.useFixture(MockSomethingFixture(
147+ partitions, 'ensure_partition_is_not_mounted',
148+ ensure_partition_is_not_mounted_mock))
149+ self.useFixture(MockSomethingFixture(
150+ glob, 'glob', lambda pattern: ['/dev/sdz1', '/dev/sdz2']))
151+ check_device._ensure_device_partitions_not_mounted('/dev/sdz')
152+ self.assertEquals(['/dev/sdz1', '/dev/sdz2'], partitions_umounted)
153+
154 def test_check_device_and_select(self):
155 self._mock_does_device_exist_true()
156 self._mock_select_device()
157- self.assertTrue(check_device.check_device(None))
158+ self.assertTrue(
159+ check_device.confirm_device_selection_and_ensure_it_is_ready(
160+ None))
161
162 def test_check_device_and_deselect(self):
163 self._mock_does_device_exist_true()
164 self._mock_deselect_device()
165- self.assertFalse(check_device.check_device(None))
166+ self.assertFalse(
167+ check_device.confirm_device_selection_and_ensure_it_is_ready(
168+ None))
169
170 def test_check_device_not_found(self):
171 self._mock_does_device_exist_false()
172- self.assertFalse(check_device.check_device(None))
173+ self.assertFalse(
174+ check_device.confirm_device_selection_and_ensure_it_is_ready(
175+ None))
176
177
178 class AtExitRegister(object):

Subscribers

People subscribed via source and target branches