From patchwork Mon May 14 12:30:17 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?0JTQsNC90LjQu9C+INCo0LXQs9Cw0L0=?= X-Patchwork-Id: 8593 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 9644F23F00 for ; Mon, 14 May 2012 12:30:21 +0000 (UTC) Received: from mail-yw0-f52.google.com (mail-yw0-f52.google.com [209.85.213.52]) by fiordland.canonical.com (Postfix) with ESMTP id 2A949A18558 for ; Mon, 14 May 2012 12:30:21 +0000 (UTC) Received: by mail-yw0-f52.google.com with SMTP id p61so5244413yhp.11 for ; Mon, 14 May 2012 05:30:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf :content-type:mime-version:x-launchpad-project:x-launchpad-branch :x-launchpad-message-rationale:x-launchpad-branch-revision-number :x-launchpad-notification-type:to:from:subject:message-id:date :reply-to:sender:errors-to:precedence:x-generated-by :x-launchpad-hash:x-gm-message-state; bh=hTuZ7NBivZvWcf45iRNb1/GhSWXos3AR9MKBHlcMPL8=; b=LbleS863Uq5kDuxtFl+uC9bkkMcTkGMfze0OiGlMkCKbrHLfSEZ1GWiDTA8LBLWgYM d0q5HaqLBheDgO3O8v8oKxcltQEj0SzS7ZSK/xslof1XBxRPYGjThl7dHOk5goKkfeRj AiJqr0LtIxKTd/ULor0PQCCiMJofoMpp7y1JP96N5H7RPj5rGb+lp3jZdHSrfyRbd8zJ bPKV0xzsM2D7N2Yoxn/t5A7YXoCFKqD9zCnXa9XK+i+8xxtLQbnArLBwe2iAQfM3aDYK S9IWzxkWJNjNUIbiHh2n6PIfzoBA1ReCy6ch0q/X4wkZGDZmrwvLNVh/B1l39PgWyq5B fytA== Received: by 10.50.40.193 with SMTP id z1mr4159674igk.0.1336998620874; Mon, 14 May 2012 05:30:20 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.35.72 with SMTP id o8csp339202ibd; Mon, 14 May 2012 05:30:19 -0700 (PDT) Received: by 10.216.145.153 with SMTP id p25mr5072176wej.112.1336998618159; Mon, 14 May 2012 05:30:18 -0700 (PDT) Received: from indium.canonical.com (indium.canonical.com. [91.189.90.7]) by mx.google.com with ESMTPS id t18si15559427wiv.29.2012.05.14.05.30.17 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 14 May 2012 05:30:18 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) client-ip=91.189.90.7; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) smtp.mail=bounces@canonical.com Received: from ackee.canonical.com ([91.189.89.26]) by indium.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1STuPp-0000C4-Jk for ; Mon, 14 May 2012 12:30:17 +0000 Received: from ackee.canonical.com (localhost [127.0.0.1]) by ackee.canonical.com (Postfix) with ESMTP id 8FC94E091F for ; Mon, 14 May 2012 12:30:17 +0000 (UTC) MIME-Version: 1.0 X-Launchpad-Project: linaro-image-tools X-Launchpad-Branch: ~linaro-image-tools/linaro-image-tools/trunk X-Launchpad-Message-Rationale: Subscriber X-Launchpad-Branch-Revision-Number: 516 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~linaro-image-tools/linaro-image-tools/trunk] Rev 516: Allow image sizes to be specified as floating point values. Fixes #997344. Patch by Michael Hope. Message-Id: <20120514123017.18968.24416.launchpad@ackee.canonical.com> Date: Mon, 14 May 2012 12:30:17 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="15238"; Instance="launchpad-lazr.conf" X-Launchpad-Hash: bcea044290f404c55d339e077e07a9c38d051cd3 X-Gm-Message-State: ALoCoQlTfmP0kKibqfF0Mha0dHbvWyIy9hsU+7v3vHZfm7mRBubY7fYT52MWnxFN9N9JHbMAdbsu Merge authors: Michael Hope (michaelh1) Related merge proposals: https://code.launchpad.net/~michaelh1/linaro-image-tools/float-image-size/+merge/105270 proposed by: Michael Hope (michaelh1) review: Approve - Данило Шеган (danilo) ------------------------------------------------------------ revno: 516 [merge] committer: Danilo Šegan branch nick: trunk timestamp: Mon 2012-05-14 14:27:10 +0200 message: Allow image sizes to be specified as floating point values. Fixes #997344. Patch by Michael Hope. modified: linaro_image_tools/media_create/partitions.py linaro_image_tools/media_create/tests/test_media_create.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 === modified file 'linaro_image_tools/media_create/partitions.py' --- linaro_image_tools/media_create/partitions.py 2012-04-18 14:18:34 +0000 +++ linaro_image_tools/media_create/partitions.py 2012-05-09 21:25:20 +0000 @@ -483,8 +483,8 @@ unit = size[-1].upper() # no unit? (ends with a digit) if unit in '0123456789': - return int(size) - real_size = int(size[:-1]) + return int(round(float(size))) + real_size = float(size[:-1]) if unit == 'K': real_size = real_size * 1024 elif unit == 'M': @@ -495,7 +495,7 @@ raise ValueError("Unknown size format: %s. Use K[bytes], M[bytes] " "or G[bytes]" % size) - return real_size + return int(round(real_size)) def run_sfdisk_commands(commands, heads, sectors, cylinders, device, === modified file 'linaro_image_tools/media_create/tests/test_media_create.py' --- linaro_image_tools/media_create/tests/test_media_create.py 2012-04-20 13:09:03 +0000 +++ linaro_image_tools/media_create/tests/test_media_create.py 2012-05-09 21:25:20 +0000 @@ -2408,6 +2408,21 @@ def test_convert_size_in_gbytes_to_bytes(self): self.assertEqual(12 * 1024**3, convert_size_to_bytes('12G')) + def test_convert_size_float_no_suffix(self): + self.assertEqual(1539, convert_size_to_bytes('1539.49')) + + def test_convert_size_float_round_up(self): + self.assertEqual(1540, convert_size_to_bytes('1539.50')) + + def test_convert_size_float_in_kbytes_to_bytes(self): + self.assertEqual(int(round(234.8 * 1024)), convert_size_to_bytes('234.8K')) + + def test_convert_size_float_in_mbytes_to_bytes(self): + self.assertEqual(int(round(876.123 * 1024**2)), convert_size_to_bytes('876.123M')) + + def test_convert_size_float_in_gbytes_to_bytes(self): + self.assertEqual(int(round(1.9 * 1024**3)), convert_size_to_bytes('1.9G')) + def test_calculate_partition_size_and_offset(self): tmpfile = self._create_tmpfile() vfat_size, vfat_offset, linux_size, linux_offset = (