=== modified file 'linaro_image_tools/tests/test_utils.py'
--- linaro_image_tools/tests/test_utils.py	2012-04-18 13:26:25 +0000
+++ linaro_image_tools/tests/test_utils.py	2012-05-31 04:30:32 +0000
@@ -33,19 +33,21 @@
     MockSomethingFixture,
     )
 from linaro_image_tools.utils import (
+    IncompatibleOptions,
+    InvalidHwpackFile,
+    UnableToFindPackageProvidingCommand,
+    additional_option_checks,
+    check_file_integrity_and_log_errors,
     ensure_command,
     find_command,
     install_package_providing,
+    path_in_tarfile_exists,
     preferred_tools_dir,
-    UnableToFindPackageProvidingCommand,
+    prep_media_path,
     verify_file_integrity,
-    check_file_integrity_and_log_errors,
-    path_in_tarfile_exists,
-    IncompatibleOptions,
-    prep_media_path,
-    additional_option_checks,
     )
 
+
 sudo_args = " ".join(cmd_runner.SUDO_ARGS)
 
 
@@ -77,7 +79,7 @@
             self.returncode = 0
             return self
 
-        def communicate(self, input=None):
+        def communicate(self, input = None):
             self.wait()
             return ': OK\n'.join(
                 TestVerifyFileIntegrity.filenames_in_shafile) + ': OK\n', ''
@@ -91,7 +93,7 @@
             self.returncode = 0
             return self
 
-        def communicate(self, input=None):
+        def communicate(self, input = None):
             self.wait()
             return ': ERROR\n'.join(
                 TestVerifyFileIntegrity.filenames_in_shafile) + ': ERROR\n', ''
@@ -105,7 +107,7 @@
             self.returncode = 0
             return self
 
-        def communicate(self, input=None):
+        def communicate(self, input = None):
             self.wait()
             return ': OK\n'.join(
                 TestVerifyFileIntegrity.filenames_in_shafile) + ': OK\n', ''
@@ -136,7 +138,7 @@
                                                    signature_filename),
              'sha1sum -c %s' % hash_filename],
             fixture.mock.commands_executed)
-        
+
     def test_verify_files_returns_files(self):
         self.useFixture(MockSomethingFixture(cmd_runner, 'Popen',
                                              self.MockCmdRunnerPopen()))
@@ -236,7 +238,7 @@
         if prefer_dir is None:
             expected, _ = cmd_runner.run(
                 ['which', lmc, ],
-                stdout=subprocess.PIPE).communicate()
+                stdout = subprocess.PIPE).communicate()
             expected = expected.strip()
         else:
             expected = os.path.join(prefer_dir, lmc)
@@ -277,14 +279,15 @@
         self.useFixture(MockSomethingFixture(os, "makedirs", lambda x: x))
 
         self.assertEqual("testdevice",
-                         prep_media_path(Args(directory=None,
-                                              device="testdevice",
-                                              board="testboard")))
+                         prep_media_path(Args(directory = None,
+                                              device = "testdevice",
+                                              board = "testboard")))
 
         self.assertEqual("/foo/bar/testdevice",
-                         prep_media_path(Args(directory="/foo/bar",
-                                              device="testdevice",
-                                              board="testboard")))
+                         prep_media_path(Args(directory = "/foo/bar",
+                                              device = "testdevice",
+                                              board = "testboard")))
+
 
 class TestPrepMediaPath(TestCaseWithFixtures):
 
@@ -293,13 +296,55 @@
         self.useFixture(MockSomethingFixture(os, "makedirs", lambda x: x))
 
         self.assertRaises(IncompatibleOptions, additional_option_checks,
-                          Args(directory="/foo/bar",
-                               device="/testdevice",
-                               board="testboard"))
+                          Args(directory = "/foo/bar",
+                               device = "/testdevice",
+                               board = "testboard"))
 
         sys.argv.append("--mmc")
         self.assertRaises(IncompatibleOptions, additional_option_checks,
-                          Args(directory="/foo/bar",
-                               device="testdevice",
-                               board="testboard"))
+                          Args(directory = "/foo/bar",
+                               device = "testdevice",
+                               board = "testboard"))
         sys.argv.remove("--mmc")
+
+
+class TestHwpackIsFile(TestCaseWithFixtures):
+
+    """Testing '--hwpack' option only allows regular files."""
+
+    def test_hwpack_is_file(self):
+        class HwPackArgs:
+            def __init__(self, hwpack):
+                self.hwpacks = [hwpack]
+                self.directory = None
+
+        try:
+            tmpdir = tempfile.mkdtemp()
+            self.assertRaises(InvalidHwpackFile, additional_option_checks,
+                              HwPackArgs(hwpack = tmpdir))
+        finally:
+            os.rmdir(tmpdir)
+
+
+    def test_hwpacks_are_files(self):
+
+        """
+        Tests that multiple hwpacks are regular files.
+
+        Tests against a file and a directory, to avoid circumstances in which
+        'additional_option_checks' is tweaked.
+        """
+
+        class HwPacksArgs:
+            def __init__(self, hwpacks):
+                self.hwpacks = hwpacks
+                self.directory = None
+
+        try:
+            tmpdir = tempfile.mkdtemp()
+            _, tmpfile = tempfile.mkstemp()
+            self.assertRaises(InvalidHwpackFile, additional_option_checks,
+                              HwPacksArgs([tmpfile, tmpdir]))
+        finally:
+            os.rmdir(tmpdir)
+            os.remove(tmpfile)

=== modified file 'linaro_image_tools/utils.py'
--- linaro_image_tools/utils.py	2012-04-18 13:26:25 +0000
+++ linaro_image_tools/utils.py	2012-05-31 04:30:32 +0000
@@ -3,7 +3,7 @@
 # Author: Guilherme Salgado <guilherme.salgado@linaro.org>
 #
 # This file is part of Linaro Image Tools.
-# 
+#
 # Linaro Image Tools is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation, either version 3 of the License, or
@@ -147,20 +147,20 @@
         if not gpg_sig_pass:
             logging.error("GPG signature verification failed.")
             return False, []
-    
+
         if not os.path.basename(binary) in verified_files:
             logging.error("OS Binary verification failed")
             return False, []
-        
+
         for hwpack in hwpacks:
             if not os.path.basename(hwpack) in verified_files:
                 logging.error("Hwpack {0} verification failed".format(hwpack))
                 return False, []
-    
+
         for verified_file in verified_files:
             logging.info('Hash verification of file {0} OK.'.format(
                                                                 verified_file))
-    
+
     return True, verified_files
 
 def install_package_providing(command):
@@ -266,6 +266,10 @@
     """We can't find a package which provides the given command."""
 
 
+class InvalidHwpackFile(Exception):
+    """The hwpack parameter is not a regular file."""
+
+
 class IncompatibleOptions(Exception):
     def __init__(self, value):
         self.value = value
@@ -277,11 +281,17 @@
     if args.directory is not None:
     # If args.device is a path to a device (/dev/) then this is an error
         if "--mmc" in sys.argv:
-            raise IncompatibleOptions("--directory option incompatable with "
+            raise IncompatibleOptions("--directory option incompatible with "
                                       "option --mmc")
 
         # If directory is used as well as having a full path (rather than just
         # a file name or relative path) in args.device, this is an error.
         if re.search(r"^/", args.device):
-            raise IncompatibleOptions("--directory option incompatable with "
+            raise IncompatibleOptions("--directory option incompatible with "
                                       "a full path in --image-file")
+
+    for hwpack in args.hwpacks:
+        if not os.path.isfile(hwpack):
+            raise InvalidHwpackFile(
+                "--hwpack argument (%s) is not a regular file" % hwpack)
+

