Merge lp:~lool/linaro-image-tools/no-size-suffix into lp:linaro-image-tools/11.11

Proposed by Loïc Minier
Status: Merged
Approved by: Mattias Backman
Approved revision: 338
Merged at revision: 337
Proposed branch: lp:~lool/linaro-image-tools/no-size-suffix
Merge into: lp:linaro-image-tools/11.11
Diff against target: 26 lines (+6/-0)
2 files modified
linaro_image_tools/media_create/partitions.py (+3/-0)
linaro_image_tools/media_create/tests/test_media_create.py (+3/-0)
To merge this branch: bzr merge lp:~lool/linaro-image-tools/no-size-suffix
Reviewer Review Type Date Requested Status
Mattias Backman (community) Approve
Review via email: mp+60183@code.launchpad.net

Description of the change

Fixes support for --image_size without any unit specification

Suggestions on nicer constructs than ord() and int() welcome!

To post a comment you must log in.
Revision history for this message
Mattias Backman (mabac) wrote :

Can you do this for the same effect?

    if unit in '0123456789':

Revision history for this message
Loïc Minier (lool) wrote :

I tried avoiding the full list of digits, but it's much more readable your way; pushed a version to use this

338. By Loïc Minier

Use nicer construct to test if a char is a digit.

Revision history for this message
Mattias Backman (mabac) wrote :

Looks good to me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'linaro_image_tools/media_create/partitions.py'
2--- linaro_image_tools/media_create/partitions.py 2011-04-29 11:02:39 +0000
3+++ linaro_image_tools/media_create/partitions.py 2011-05-06 14:01:58 +0000
4@@ -330,6 +330,9 @@
5 def convert_size_to_bytes(size):
6 """Convert a size string in Kbytes, Mbytes or Gbytes to bytes."""
7 unit = size[-1].upper()
8+ # no unit? (ends with a digit)
9+ if unit in '0123456789':
10+ return int(size)
11 real_size = int(size[:-1])
12 if unit == 'K':
13 real_size = real_size * 1024
14
15=== modified file 'linaro_image_tools/media_create/tests/test_media_create.py'
16--- linaro_image_tools/media_create/tests/test_media_create.py 2011-05-02 07:59:07 +0000
17+++ linaro_image_tools/media_create/tests/test_media_create.py 2011-05-06 14:01:58 +0000
18@@ -846,6 +846,9 @@
19 return self._create_qemu_img_with_partitions(
20 '16384,15746,0x0C,*\n32768,,,-')
21
22+ def test_convert_size_no_suffix(self):
23+ self.assertEqual(524288, convert_size_to_bytes('524288'))
24+
25 def test_convert_size_in_kbytes_to_bytes(self):
26 self.assertEqual(512 * 1024, convert_size_to_bytes('512K'))
27

Subscribers

People subscribed via source and target branches