[anaconda 2/2] Be more liberal in what is accepted as a size unit.

David Shea dshea at redhat.com
Tue Jan 21 14:33:02 UTC 2014


On 01/21/2014 02:36 AM, Vratislav Podzimek wrote:
> On Mon, 2014-01-20 at 17:26 -0500, David Shea wrote:
>> Not all size specifications will end with a letter. For example: the
>> translation of "B" for byte in Telugu ends with a vowel sign,
>> categorized in Unicode as a non-spacing mark. Instead check whether the
>> size string ends with a [0-9]: if so, the unit is missing.
>> ---
>>   pyanaconda/ui/gui/spokes/custom.py | 8 +++++---
>>   1 file changed, 5 insertions(+), 3 deletions(-)
>>
>> diff --git a/pyanaconda/ui/gui/spokes/custom.py b/pyanaconda/ui/gui/spokes/custom.py
>> index 4b94628..dd3afdc 100644
>> --- a/pyanaconda/ui/gui/spokes/custom.py
>> +++ b/pyanaconda/ui/gui/spokes/custom.py
>> @@ -31,6 +31,7 @@
>>   
>>   from contextlib import contextmanager
>>   import re
>> +import locale
>>   
>>   from pykickstart.constants import CLEARPART_TYPE_NONE, AUTOPART_TYPE_PLAIN, AUTOPART_TYPE_BTRFS, AUTOPART_TYPE_LVM, AUTOPART_TYPE_LVM_THINP
>>   
>> @@ -162,10 +163,11 @@ partition_only_format_types = ["efi", "macefi", "prepboot", "biosboot",
>>                                  "appleboot"]
>>   
>>   def size_from_entry(entry):
>> -    size_text = entry.get_text().strip()
>> +    size_text = entry.get_text().decode("utf-8").strip()
>>   
>> -    # if no unit was specified, default to MiB
>> -    if not re.search(r'[A-Za-z]+$', size_text):
>> +    # if no unit was specified, default to MiB. Assume that a string
>> +    # ending with anything other than a digit has a unit suffix
>> +    if not size_text or re.search(r'[\d.%s]$' % locale.nl_langinfo(locale.RADIXCHAR), size_text):
> Empty size_text means "grow as much as possible". I don't think it will
> work the same if there is the "MiB" string instead of the "" string.

It does work the same, since that's the same thing we did before I 
started on all of this, but it's not exactly the cleanest. It works 
because "MiB" gets rejected with a ValueError by blivet.size.Size (as 
does the empty string) so size_from_entry returns None. The better way 
would be something like:

     if not size_text:
         return None
     if re.search ...

>
> Also, looking at the regexp -- do we want to support size specs looking
> like "20." or "20,"?
>

Yes. We certainly did before, and based on dlehman's comment on the last 
patch it's my understanding that we want to continue to do so


More information about the anaconda-patches mailing list