Synced repos to: 60588
diff --git a/utils/misc.py b/utils/misc.py
index 9111c6b..43ef09d 100644
--- a/utils/misc.py
+++ b/utils/misc.py
@@ -22,6 +22,22 @@
   return string
 
 
+def UnitToNumber(string, base=1000):
+  unit_dict = {"kilo": base,
+               "mega": base**2,
+               "giga": base**3}
+  string = string.lower()
+  mo = re.search("(\d*)(.+)", string)
+  number = mo.group(1)
+  unit = mo.group(2)
+  for k, v in unit_dict.items():
+    if k.startswith(unit):
+      return float(number) * v
+  raise Exception("Unit: %s not found in byte: %s!" %
+                  (unit,
+                   string))
+
+
 def GetFilenameFromString(string):
   return ApplySubs(string,
                    ("/", "__"),
@@ -36,6 +52,24 @@
   return (os.path.dirname(abs_path), os.path.basename(abs_path))
 
 
+def GetChrootPath(chromeos_root):
+  return os.path.join(chromeos_root,
+                      "chroot")
+
+
+def GetInsideChrootPath(chromeos_root, file_path):
+  if not file_path.startswith(GetChrootPath(chromeos_root)):
+    raise Exception("File: %s doesn't seem to be in the chroot: %s" %
+                    (file_path,
+                     chromeos_root))
+  return file_path[len(GetChrootPath(chromeos_root)):]
+
+
+def GetOutsideChrootPath(chromeos_root, file_path):
+  return os.path.join(GetChrootPath(chromeos_root),
+                      file_path.lstrip("/"))
+
+
 def FormatQuotedCommand(command):
   return ApplySubs(command,
                    ("\"", "\\\""))