summaryrefslogtreecommitdiff
path: root/compose/cli/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'compose/cli/utils.py')
-rw-r--r--compose/cli/utils.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/compose/cli/utils.py b/compose/cli/utils.py
index f60f61cd..4d4fc4c1 100644
--- a/compose/cli/utils.py
+++ b/compose/cli/utils.py
@@ -2,6 +2,7 @@ from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
+import math
import os
import platform
import ssl
@@ -11,6 +12,7 @@ import sys
import docker
import compose
+from ..const import IS_WINDOWS_PLATFORM
# WindowsError is not defined on non-win32 platforms. Avoid runtime errors by
# defining it as OSError (its parent class) if missing.
@@ -73,6 +75,10 @@ def is_ubuntu():
return platform.system() == 'Linux' and platform.linux_distribution()[0] == 'Ubuntu'
+def is_windows():
+ return IS_WINDOWS_PLATFORM
+
+
def get_version_info(scope):
versioninfo = 'docker-compose version {}, build {}'.format(
compose.__version__,
@@ -122,3 +128,23 @@ def generate_user_agent():
else:
parts.append("{}/{}".format(p_system, p_release))
return " ".join(parts)
+
+
+def unquote_path(s):
+ if not s:
+ return s
+ if s[0] == '"' and s[-1] == '"':
+ return s[1:-1]
+ return s
+
+
+def human_readable_file_size(size):
+ suffixes = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', ]
+ order = int(math.log(size, 2) / 10) if size else 0
+ if order >= len(suffixes):
+ order = len(suffixes) - 1
+
+ return '{0:.3g} {1}'.format(
+ size / float(1 << (order * 10)),
+ suffixes[order]
+ )