[elbe-devel] [PATCH v2 5/8] size_to_int: move size_to_int() from hdimg.py to filesystem.py

Torben Hohn torben.hohn at linutronix.de
Tue May 8 17:10:43 CEST 2018


in order to access size_to_int from "elbe init" it needs to move
into python-elbe-common package.

move the function to filesystem.py and import it into hdimg.

Signed-off-by: Torben Hohn <torben.hohn at linutronix.de>
---
 elbepack/filesystem.py | 36 +++++++++++++++++++++++++++++++++++-
 elbepack/hdimg.py      | 37 +------------------------------------
 2 files changed, 36 insertions(+), 37 deletions(-)

diff --git a/elbepack/filesystem.py b/elbepack/filesystem.py
index f0a1a9ec..f8978438 100644
--- a/elbepack/filesystem.py
+++ b/elbepack/filesystem.py
@@ -9,7 +9,41 @@ import shutil
 
 from glob import glob
 from tempfile import mkdtemp
-
+from string import digits
+
+def size_to_int(size):
+    if size[-1] in digits:
+        return int(size)
+
+    if size.endswith("M"):
+        unit = 1000 * 1000
+        s = size[:-1]
+    elif size.endswith("MiB"):
+        unit = 1024 * 1024
+        s = size[:-3]
+    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
+        s = size[:-2]
+
+    return int(s) * unit
 
 class Filesystem(object):
     def __init__(self, path, clean=False):
diff --git a/elbepack/hdimg.py b/elbepack/hdimg.py
index 3f1dfd9a..5434734e 100644
--- a/elbepack/hdimg.py
+++ b/elbepack/hdimg.py
@@ -10,13 +10,13 @@
 from __future__ import print_function
 
 import os
-from string import digits
 
 import parted
 import _ped
 
 from elbepack.fstab import fstabentry, mountpoint_dict
 from elbepack.asciidoclog import CommandError
+from elbepack.filesystem import size_to_int
 
 
 def mkfs_mtd(outf, mtd, fslabel, rfs, target):
@@ -141,41 +141,6 @@ def build_image_mtd(outf, mtd, target):
     return img_files
 
 
-def size_to_int(size):
-    if size[-1] in digits:
-        return int(size)
-
-    if size.endswith("M"):
-        unit = 1000 * 1000
-        s = size[:-1]
-    elif size.endswith("MiB"):
-        unit = 1024 * 1024
-        s = size[:-3]
-    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
-        s = size[:-2]
-
-    return int(s) * unit
-
-
 class grubinstaller_base(object):
     def __init__(self, outf, fw_type=None):
         self.outf = outf
-- 
2.11.0




More information about the elbe-devel mailing list