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
=== modified file 'linaro-hwpack-install'
--- linaro-hwpack-install 2010-12-16 02:19:53 +0000
+++ linaro-hwpack-install 2011-01-06 13:02:59 +0000
@@ -137,7 +137,8 @@
137echo "deb file:${HWPACK_DIR}/pkgs ./" > "$SOURCES_LIST_FILE"137echo "deb file:${HWPACK_DIR}/pkgs ./" > "$SOURCES_LIST_FILE"
138cat /etc/apt/sources.list >> "$SOURCES_LIST_FILE"138cat /etc/apt/sources.list >> "$SOURCES_LIST_FILE"
139139
140sudo apt-get -o "$APT_GET_OPTIONS" update -qq140echo "Updating apt package lists ..."
141sudo apt-get -o "$APT_GET_OPTIONS" update -q
141142
142echo -n "Installing packages ..."143echo -n "Installing packages ..."
143144
144145
=== modified file 'media_create/check_device.py'
--- media_create/check_device.py 2011-01-03 11:51:36 +0000
+++ media_create/check_device.py 2011-01-06 13:02:59 +0000
@@ -1,13 +1,15 @@
1import glob
1import sys2import sys
23
3import dbus4import dbus
45
6from media_create import partitions
7
58
6def _get_system_bus_and_udisks_iface():9def _get_system_bus_and_udisks_iface():
7 """Return the system bus and the UDisks interface.10 """Return the system bus and the UDisks interface.
8 11
9 :return: System bus and UDisks inteface tuple.12 :return: System bus and UDisks inteface tuple.
10
11 """13 """
12 bus = dbus.SystemBus()14 bus = dbus.SystemBus()
13 udisks = dbus.Interface(15 udisks = dbus.Interface(
@@ -24,7 +26,6 @@
24 :param device: Device object.26 :param device: Device object.
25 :param path: Device path.27 :param path: Device path.
26 :return: Device property.28 :return: Device property.
27
28 """29 """
29 return device.Get(30 return device.Get(
30 path, prop, dbus_interface='org.freedesktop.DBus.Properties')31 path, prop, dbus_interface='org.freedesktop.DBus.Properties')
@@ -35,7 +36,6 @@
3536
36 :param path: Disk device path.37 :param path: Disk device path.
37 :return: True if the device exist, else False.38 :return: True if the device exist, else False.
38
39 """39 """
40 bus, udisks = _get_system_bus_and_udisks_iface()40 bus, udisks = _get_system_bus_and_udisks_iface()
41 try:41 try:
@@ -49,7 +49,6 @@
4949
50def _print_devices():50def _print_devices():
51 """Print disk devices found on the system."""51 """Print disk devices found on the system."""
52
53 bus, udisks = _get_system_bus_and_udisks_iface()52 bus, udisks = _get_system_bus_and_udisks_iface()
54 print '%-16s %-16s %s' % ('Device', 'Mount point', 'Size')53 print '%-16s %-16s %s' % ('Device', 'Mount point', 'Size')
55 devices = udisks.get_dbus_method('EnumerateDevices')()54 devices = udisks.get_dbus_method('EnumerateDevices')()
@@ -77,35 +76,42 @@
7776
78 :param device: Device path.77 :param device: Device path.
79 :return: True if the user confirms the selection, else False.78 :return: True if the user confirms the selection, else False.
80
81 """79 """
82
83 resp = raw_input('Are you 100%% sure, on selecting [%s] (y/n)? ' % device)80 resp = raw_input('Are you 100%% sure, on selecting [%s] (y/n)? ' % device)
84 if resp.lower() != 'y':81 if resp.lower() != 'y':
85 return False82 return False
86 return True83 return True
8784
8885
89def check_device(path):86def _ensure_device_partitions_not_mounted(device):
90 """Checks that a selected device exists.87 """Ensure all partitions of the given device are not mounted."""
9188 # Use '%s?*' as we only want the device files representing
92 If the device exist, the user is asked to confirm that this is the89 # partitions and not the one representing the device itself.
93 device to use.90 for part in glob.glob('%s?*' % device):
9491 partitions.ensure_partition_is_not_mounted(part)
95 :param path: Device path.92
93
94def confirm_device_selection_and_ensure_it_is_ready(device):
95 """Confirm this is the device to use and ensure it's ready.
96
97 If the device exists, the user is asked to confirm that this is the
98 device to use. Upon confirmation we ensure all partitions of the device
99 are umounted.
100
101 :param device: The path to the device.
96 :return: True if the device exist and is selected, else False.102 :return: True if the device exist and is selected, else False.
97
98 """103 """
99104 if _does_device_exist(device):
100 if _does_device_exist(path):
101 print '\nI see...'105 print '\nI see...'
102 _print_devices()106 _print_devices()
103 return _select_device(path)107 if _select_device(device):
108 _ensure_device_partitions_not_mounted(device)
109 return True
104 else:110 else:
105 print '\nAre you sure? I do not see [%s].' % path111 print '\nAre you sure? I do not see [%s].' % device
106 print 'Here is what I see...'112 print 'Here is what I see...'
107 _print_devices()113 _print_devices()
108 return False114 return False
109115
110116
111if __name__ == '__main__':117if __name__ == '__main__':
@@ -113,7 +119,8 @@
113 print 'usage: ' + sys.argv[0] + ' <DEVICE>'119 print 'usage: ' + sys.argv[0] + ' <DEVICE>'
114 sys.exit(2)120 sys.exit(2)
115121
116 device_selected = check_device(sys.argv[1])122 device_selected = confirm_device_selection_and_ensure_it_is_ready(
123 sys.argv[1])
117 if device_selected:124 if device_selected:
118 sys.exit(0)125 sys.exit(0)
119 else:126 else:
120127
=== modified file 'media_create/tests/test_media_create.py'
--- media_create/tests/test_media_create.py 2011-01-05 19:32:02 +0000
+++ media_create/tests/test_media_create.py 2011-01-06 13:02:59 +0000
@@ -1,5 +1,6 @@
1from contextlib import contextmanager1from contextlib import contextmanager
2import atexit2import atexit
3import glob
3import os4import os
4import random5import random
5import string6import string
@@ -656,19 +657,37 @@
656 self._mock_sys_stdout()657 self._mock_sys_stdout()
657 self._mock_print_devices()658 self._mock_print_devices()
658659
660 def test_ensure_device_partitions_not_mounted(self):
661 partitions_umounted = []
662 def ensure_partition_is_not_mounted_mock(part):
663 partitions_umounted.append(part)
664 self.useFixture(MockSomethingFixture(
665 partitions, 'ensure_partition_is_not_mounted',
666 ensure_partition_is_not_mounted_mock))
667 self.useFixture(MockSomethingFixture(
668 glob, 'glob', lambda pattern: ['/dev/sdz1', '/dev/sdz2']))
669 check_device._ensure_device_partitions_not_mounted('/dev/sdz')
670 self.assertEquals(['/dev/sdz1', '/dev/sdz2'], partitions_umounted)
671
659 def test_check_device_and_select(self):672 def test_check_device_and_select(self):
660 self._mock_does_device_exist_true()673 self._mock_does_device_exist_true()
661 self._mock_select_device()674 self._mock_select_device()
662 self.assertTrue(check_device.check_device(None))675 self.assertTrue(
676 check_device.confirm_device_selection_and_ensure_it_is_ready(
677 None))
663678
664 def test_check_device_and_deselect(self):679 def test_check_device_and_deselect(self):
665 self._mock_does_device_exist_true()680 self._mock_does_device_exist_true()
666 self._mock_deselect_device()681 self._mock_deselect_device()
667 self.assertFalse(check_device.check_device(None))682 self.assertFalse(
683 check_device.confirm_device_selection_and_ensure_it_is_ready(
684 None))
668685
669 def test_check_device_not_found(self):686 def test_check_device_not_found(self):
670 self._mock_does_device_exist_false()687 self._mock_does_device_exist_false()
671 self.assertFalse(check_device.check_device(None))688 self.assertFalse(
689 check_device.confirm_device_selection_and_ensure_it_is_ready(
690 None))
672691
673692
674class AtExitRegister(object):693class AtExitRegister(object):

Subscribers

People subscribed via source and target branches