diff mbox

[Branch,~linaro-image-tools/linaro-image-tools/trunk] Rev 607: Fix for bug 1118544. Reviewed by milo.

Message ID 20130226160926.25663.55698.launchpad@ackee.canonical.com
State Accepted
Headers show

Commit Message

Stevan Radakovic Feb. 26, 2013, 4:09 p.m. UTC
Merge authors:
  Stevan Radaković (stevanr)
Related merge proposals:
  https://code.launchpad.net/~stevanr/linaro-image-tools/bug1118544/+merge/150516
  proposed by: Stevan Radaković (stevanr)
  review: Approve - Milo Casagrande (milo)
------------------------------------------------------------
revno: 607 [merge]
committer: Stevan Radakovic <stevan.radakovic@linaro.org>
branch nick: trunk
timestamp: Tue 2013-02-26 17:05:10 +0100
message:
  Fix for bug 1118544. Reviewed by milo.
modified:
  README
  linaro-media-create
  linaro_image_tools/tests/test_utils.py
  linaro_image_tools/utils.py


--
lp:linaro-image-tools
https://code.launchpad.net/~linaro-image-tools/linaro-image-tools/trunk

You are subscribed to branch lp:linaro-image-tools.
To unsubscribe from this branch go to https://code.launchpad.net/~linaro-image-tools/linaro-image-tools/trunk/+edit-subscription
diff mbox

Patch

=== modified file 'README'
--- README	2013-01-07 14:21:55 +0000
+++ README	2013-02-25 19:52:53 +0000
@@ -36,6 +36,7 @@ 
   - apt-utils
   - pep8
   - python-mock
+  - python-commandnotfound (as of Ubuntu 12.10)
 
 Also consider installing pyflakes, which is optional but will enable more
 tests.
@@ -50,7 +51,8 @@ 
 
   $ sudo apt-get install testrepository python-testtools python-debian \
         python-argparse dpkg-dev python-parted dbus udisks python-dbus \
-        python-apt qemu-kvm util-linux apt-utils pep8 pyflakes
+        python-apt qemu-kvm util-linux apt-utils pep8 pyflakes \
+        python-commandnotfound
 
 To initialized testsuite, run the following command:
 

=== modified file 'linaro-media-create'
--- linaro-media-create	2013-01-02 14:36:38 +0000
+++ linaro-media-create	2013-02-25 18:18:09 +0000
@@ -98,8 +98,13 @@ 
         required_commands.append('mkfs.%s' % args.rootfs)
     else:
         raise AssertionError('Unsupported rootfs type %s' % args.rootfs)
+
     for command in required_commands:
-        ensure_command(command)
+        try:
+            ensure_command(command)
+        except UnableToFindPackageProvidingCommand:
+            logger.error("Could not look up command %s. Please ensure that command %s is installed." % (command, command))
+            raise
 
 
 if __name__ == '__main__':
@@ -177,7 +182,10 @@ 
 
     ROOTFS_DIR = os.path.join(BIN_DIR, filesystem_dir)
 
-    ensure_required_commands(args)
+    try:
+        ensure_required_commands(args)
+    except UnableToFindPackageProvidingCommand:
+        sys.exit(1)
 
     sig_file_list = args.hwpacksigs[:]
     if args.binarysig is not None:

=== modified file 'linaro_image_tools/tests/test_utils.py'
--- linaro_image_tools/tests/test_utils.py	2013-02-18 09:40:15 +0000
+++ linaro_image_tools/tests/test_utils.py	2013-02-25 18:31:26 +0000
@@ -47,6 +47,7 @@ 
     path_in_tarfile_exists,
     preferred_tools_dir,
     prep_media_path,
+    try_import,
     verify_file_integrity,
 )
 
@@ -270,11 +271,17 @@ 
                                              StringIO('Y')))
         fixture = self.useFixture(
             MockCmdRunnerPopenFixture(self.output_string))
-        install_package_providing('mkfs.vfat')
-        self.assertEqual(
-            ['apt-get -s install dosfstools',
-             '%s apt-get --yes install dosfstools' % sudo_args],
-            fixture.mock.commands_executed)
+
+        try:
+            install_package_providing('mkfs.vfat')
+        except UnableToFindPackageProvidingCommand as inst:
+            self.assertEqual("CommandNotFound python module does not exist.",
+                             inst.args[0])
+        else:
+            self.assertEqual(
+                ['apt-get -s install dosfstools',
+                '%s apt-get --yes install dosfstools' % sudo_args],
+                fixture.mock.commands_executed)
 
     def test_package_installation_refused(self):
         self.useFixture(MockSomethingFixture(sys,
@@ -286,7 +293,15 @@ 
                                              'stdin',
                                              StringIO('n')))
         self.useFixture(MockCmdRunnerPopenFixture(self.output_string))
-        self.assertRaises(SystemExit, install_package_providing, 'mkfs.vfat')
+
+        CommandNotFound = try_import('CommandNotFound.CommandNotFound')
+
+        if CommandNotFound is None:
+            self.assertRaises(UnableToFindPackageProvidingCommand,
+                              install_package_providing, 'mkfs.vfat')
+        else:
+            self.assertRaises(SystemExit, install_package_providing,
+                              'mkfs.vfat')
 
     def test_not_found_package(self):
         self.assertRaises(UnableToFindPackageProvidingCommand,

=== modified file 'linaro_image_tools/utils.py'
--- linaro_image_tools/utils.py	2013-02-18 09:40:15 +0000
+++ linaro_image_tools/utils.py	2013-02-25 18:18:09 +0000
@@ -186,7 +186,7 @@ 
 
     if CommandNotFound is None:
         raise UnableToFindPackageProvidingCommand(
-            "Cannot lookup a package which provides %s" % command)
+            "CommandNotFound python module does not exist.")
 
     packages = CommandNotFound().getPackages(command)
     if len(packages) == 0: