aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Tunnicliffe <james.tunnicliffe@linaro.org>2012-04-17 16:07:35 +0100
committerJames Tunnicliffe <james.tunnicliffe@linaro.org>2012-04-17 16:07:35 +0100
commit1a5f77d1cd16c200ec8758491e0003225e4e8788 (patch)
tree481ae57754163f5f6b16fe195c5c5f7a3adf943b
parentb38f878fb6dbe6656902196b6b62b46d0ce657be (diff)
--directory can now be specified at the same time as --image-file. If --directory and --image-file are combined, a file, whose name is specified by --image-file will be created in --directory. If --image-file is not specified, a sensible default file name will be used and printed for the user to see.
--directory and --mmc are incompatable. --directory and specifying a full path to a file with --image-file are incompatable.
-rwxr-xr-xlinaro-media-create59
-rw-r--r--linaro_image_tools/media_create/__init__.py6
-rw-r--r--linaro_image_tools/tests/test_utils.py27
-rw-r--r--linaro_image_tools/utils.py41
4 files changed, 84 insertions, 49 deletions
diff --git a/linaro-media-create b/linaro-media-create
index 9ea7f7a..9f2a342 100755
--- a/linaro-media-create
+++ b/linaro-media-create
@@ -48,7 +48,7 @@ from linaro_image_tools.utils import (
is_arm_host,
check_file_integrity_and_log_errors,
path_in_tarfile_exists,
- BoardAbilityNotMet,
+ IncompatableOptions,
prep_media_path,
)
@@ -99,6 +99,34 @@ if __name__ == '__main__':
parser = get_args_parser()
args = parser.parse_args()
+ board_config = board_configs[args.board]
+ board_config.set_metadata(args.hwpacks)
+ board_config.set_board(args.board)
+ board_config.add_boot_args(args.extra_boot_args)
+ board_config.add_boot_args_from_file(args.extra_boot_args_file)
+
+ try:
+ media = Media(prep_media_path(args, board_config))
+ except IncompatableOptions as e:
+ print >> sys.stderr, e.value
+ sys.exit(1)
+
+ if media.is_block_device:
+ if not board_config.supports_writing_to_mmc:
+ print "The board '%s' does not support the --mmc option. Please use "\
+ "--image_file to create an image file for this board." % args.board
+ sys.exit(1)
+ if not confirm_device_selection_and_ensure_it_is_ready(args.device,
+ args.nocheck_mmc):
+ sys.exit(1)
+ elif not args.should_format_rootfs or not args.should_format_bootfs:
+ print ("Do not use --no-boot or --no-part in conjunction with "
+ "--image_file.")
+ sys.exit(1)
+ else:
+ # All good, move on.
+ pass
+
ch = logging.StreamHandler()
ch.setLevel(logging.INFO)
formatter = logging.Formatter("%(message)s")
@@ -118,12 +146,6 @@ if __name__ == '__main__':
BOOT_DISK = os.path.join(TMP_DIR, 'boot-disc')
ROOT_DISK = os.path.join(TMP_DIR, 'root-disc')
- board_config = board_configs[args.board]
- board_config.set_metadata(args.hwpacks)
- board_config.set_board(args.board)
- board_config.add_boot_args(args.extra_boot_args)
- board_config.add_boot_args_from_file(args.extra_boot_args_file)
-
ensure_required_commands(args)
sig_file_list = args.hwpacksigs[:]
@@ -136,29 +158,8 @@ if __name__ == '__main__':
sig_file_list, args.binary, args.hwpacks)
if not files_ok:
sys.exit(1)
-
- atexit.register(cleanup_tempdir)
- try:
- media = Media(prep_media_path(args, board_config))
- except BoardAbilityNotMet as e:
- print e.value
- sys.exit(1)
- if media.is_block_device:
- if not board_config.supports_writing_to_mmc:
- print "The board '%s' does not support the --mmc option. Please use " \
- "--image_file to create an image file for this board." % args.board
- sys.exit(1)
- if not confirm_device_selection_and_ensure_it_is_ready(args.device,
- args.nocheck_mmc):
- sys.exit(1)
- elif not args.should_format_rootfs or not args.should_format_bootfs:
- print ("Do not use --no-boot or --no-part in conjunction with "
- "--image_file.")
- sys.exit(1)
- else:
- # All good, move on.
- pass
+ atexit.register(cleanup_tempdir)
unpack_binary_tarball(args.binary, TMP_DIR)
diff --git a/linaro_image_tools/media_create/__init__.py b/linaro_image_tools/media_create/__init__.py
index da63d9c..ec87578 100644
--- a/linaro_image_tools/media_create/__init__.py
+++ b/linaro_image_tools/media_create/__init__.py
@@ -77,14 +77,14 @@ def add_common_options(parser):
def get_args_parser():
"""Get the ArgumentParser for the arguments given on the command line."""
parser = argparse.ArgumentParser(version='%(prog)s ' + get_version())
- group = parser.add_mutually_exclusive_group(required=True)
+ group = parser.add_mutually_exclusive_group()
group.add_argument(
'--mmc', dest='device', help='The storage device to use.')
group.add_argument(
'--image-file', '--image_file', dest='device',
help='File where we should write an image file.')
- group.add_argument(
- '--directory', '--directory', dest='directory',
+ parser.add_argument(
+ '--directory', dest='directory',
help='Directory where image and accessories should be written to.')
parser.add_argument(
'--dev', required=True, dest='board', choices=KNOWN_BOARDS,
diff --git a/linaro_image_tools/tests/test_utils.py b/linaro_image_tools/tests/test_utils.py
index 8b907d7..643b720 100644
--- a/linaro_image_tools/tests/test_utils.py
+++ b/linaro_image_tools/tests/test_utils.py
@@ -41,7 +41,7 @@ from linaro_image_tools.utils import (
verify_file_integrity,
check_file_integrity_and_log_errors,
path_in_tarfile_exists,
- BoardAbilityNotMet,
+ IncompatableOptions,
prep_media_path,
)
@@ -277,9 +277,8 @@ class TestPrepMediaPath(TestCaseWithFixtures):
self.outputs_directory = outputs_directory
self.board = board
- self.useFixture(MockSomethingFixture(
- os.path, 'abspath', lambda x: x))
- self.useFixture(MockCmdRunnerPopenFixture())
+ self.useFixture(MockSomethingFixture(os.path, 'abspath', lambda x: x))
+ self.useFixture(MockSomethingFixture(os, "makedirs", lambda x: x))
self.assertEqual("testdevice",
prep_media_path(Args(directory=None,
@@ -290,14 +289,30 @@ class TestPrepMediaPath(TestCaseWithFixtures):
self.assertEqual("/foo/bar/testboard.img",
prep_media_path(Args(directory="/foo/bar",
+ device=None,
+ board="testboard"),
+ BoardConfig(outputs_directory=True,
+ board="testboard")))
+
+ self.assertEqual("/foo/bar/testdevice",
+ prep_media_path(Args(directory="/foo/bar",
device="testdevice",
board="testboard"),
BoardConfig(outputs_directory=True,
board="testboard")))
- self.assertRaises(BoardAbilityNotMet, prep_media_path,
+ self.assertRaises(IncompatableOptions, prep_media_path,
+ Args(directory="/foo/bar",
+ device="/testdevice",
+ board="testboard"),
+ BoardConfig(outputs_directory=True,
+ board="testboard"))
+
+ sys.argv.append("--mmc")
+ self.assertRaises(IncompatableOptions, prep_media_path,
Args(directory="/foo/bar",
device="testdevice",
board="testboard"),
- BoardConfig(outputs_directory=False,
+ BoardConfig(outputs_directory=True,
board="testboard"))
+ sys.argv.remove("--mmc")
diff --git a/linaro_image_tools/utils.py b/linaro_image_tools/utils.py
index 0b83731..0a24014 100644
--- a/linaro_image_tools/utils.py
+++ b/linaro_image_tools/utils.py
@@ -246,24 +246,43 @@ def preferred_tools_dir():
prefer_dir = os.getcwd()
return prefer_dir
-class BoardAbilityNotMet(Exception):
- """Tried to use a feature of a board that isn't supported."""
- pass
+
+class IncompatableOptions(Exception):
+ def __init__(self, value):
+ self.value = value
+
+ def __str__(self):
+ return repr(self.value)
+
def prep_media_path(args, board_config):
+
+ # If args.device isn't set, generate a sensible default file name and
+ # tell the user
+ if not args.device:
+ args.device = board_config.board + ".img"
+ print "Setting destination file name to", args.device
+
if args.directory is not None:
- if not board_config.outputs_directory:
- raise BoardAbilityNotMet("The board '%s' does not support the"
- "--directory option." % args.board)
- else:
- loc=os.path.abspath(args.directory)
- proc = cmd_runner.run(['mkdir','-p', '-v', loc])
- proc.wait()
- path = os.path.join(loc, board_config.board) + ".img"
+ # If args.device is a path to a device (/dev/) then this is an error
+ if "--mmc" in sys.argv:
+ raise IncompatableOptions("--directory option incompatable 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 IncompatableOptions("--directory option incompatable with "
+ "a full path in --image-file")
+
+ loc = os.path.abspath(args.directory)
+ os.makedirs(loc)
+ path = os.path.join(loc, args.device)
else:
path = args.device
return path
+
class UnableToFindPackageProvidingCommand(Exception):
"""We can't find a package which provides the given command."""