[elbe-devel] [PATCH] fix unit symbol for kibibyte

Benedikt Spranger b.spranger at linutronix.de
Thu Jan 14 11:07:12 CET 2016


On Wed, 13 Jan 2016 10:40:15 +0100
John Ogness <john.ogness at linutronix.de> wrote:

> IEC 80000-13 defines the unit symbol for the kibibyte as KiB.
It also negates the use of SI-Prefixes like k, M or G as binary
prefix.

Changing the XML schema has a greater impact on E.L.B.E. I suggest a
more comprehensive change and drop all legacy units. While at it add
the missing prefixes.

Regards
    Bene

From f0e948e70cafce970a291db7981013c8fcf4c744 Mon Sep 17 00:00:00 2001
From: Benedikt Spranger <bene at mitra>
Date: Thu, 14 Jan 2016 10:38:20 +0100
Subject: [PATCH] change units according to IEC 80000-13:2009.

IEC 80000-13:2009 defines binary prefixes for units. A use of SI prefixes
as binary prefix is strongly discouraged.

ATTENTION: This patch modifies the XML Schema Reference!

Signed-off-by: Benedikt Spranger <bene at mitra>
---
 elbepack/dbsfed.xsd |  2 +-
 elbepack/hdimg.py   | 55 ++++++++++++++++++++++++++++++++++++-----------------
 2 files changed, 39 insertions(+), 18 deletions(-)

diff --git a/elbepack/dbsfed.xsd b/elbepack/dbsfed.xsd
index 2160197..2b18a91 100644
--- a/elbepack/dbsfed.xsd
+++ b/elbepack/dbsfed.xsd
@@ -1341,7 +1341,7 @@
       </documentation>
     </annotation>
     <restriction base="string">
-      <pattern value="(\d+(k|M|G|kB|MB|GB|KiB|MiB|GiB)?|remain)" />
+      <pattern value="(\d+(KiB|MiB|GiB|TiB|PiB|EiB|ZiB|YiB|kB|MB|GB|TB|PB|EB|ZB|YB)?|remain)" />
     </restriction>
   </simpleType>
 
diff --git a/elbepack/hdimg.py b/elbepack/hdimg.py
index 3c93138..133b24a 100644
--- a/elbepack/hdimg.py
+++ b/elbepack/hdimg.py
@@ -145,32 +145,53 @@ def size_to_int( size ):
     if size[-1] in digits:
         return int(size)
 
-    if size.endswith( "M" ):
-        unit = 1000*1000
-        s = size[:-1]
+    if size.endswith( "KiB" ):
+        unit = 1024
+        s = size[:-3]
     elif size.endswith( "MiB" ):
         unit = 1024*1024
         s = size[:-3]
+    elif size.endswith( "GiB" ):
+        unit = 1024*1024*1024*1024
+        s = size[:-3]
+    elif size.endswith( "TiB" ):
+        unit = 1024*1024*1024*1024*1024
+        s = size[:-3]
+    elif size.endswith( "PiB" ):
+        unit = 1024*1024*1024*1024*1024*1024
+        s = size[:-3]
+    elif size.endswith( "EiB" ):
+        unit = 1024*1024*1024*1024*1024*1024*1024
+        s = size[:-3]
+    elif size.endswith( "ZiB" ):
+        unit = 1024*1024*1024*1024*1024*1024*1024*1024
+        s = size[:-3]
+    elif size.endswith( "YiB" ):
+        unit = 1024*1024*1024*1024*1024*1024*1024*1024*1024
+        s = size[:-3]
+    elif size.endswith( "kB" ):
+        unit = 1000
+        s = size[:-2]
     elif size.endswith( "MB" ):
         unit = 1000*1000
         s = size[:-2]
-    if size.endswith( "G" ):
-        unit = 1000*1000*1000
-        s = size[:-1]
-    elif size.endswith( "GiB" ):
-        unit = 1024*1024*1024
-        s = size[:-3]
     elif size.endswith( "GB" ):
         unit = 1000*1000*1000
         s = size[:-2]
-    if size.endswith( "k" ):
-        unit = 1000
-        s = size[:-1]
-    elif size.endswith( "KiB" ):
-        unit = 1024
-        s = size[:-3]
-    elif size.endswith( "kB" ):
-        unit = 1000
+    elif size.endswith( "TB" ):
+        unit = 1000*1000*1000*1000
+        s = size[:-2]
+    elif size.endswith( "PB" ):
+        unit = 1000*1000*1000*1000*1000
+        s = size[:-2]
+    elif size.endswith( "EB" ):
+        unit = 1000*1000*1000*1000*1000*1000
+        s = size[:-2]
+    elif size.endswith( "ZB" ):
+        unit = 1000*1000*1000*1000*1000*1000*1000
+        s = size[:-2]
+    elif size.endswith( "YB" ):
+        unit = 1000*1000*1000*1000*1000*1000*1000*1000
         s = size[:-2]
 
     return int(s) * unit
-- 
2.7.0.rc3





More information about the elbe-devel mailing list