diff --git a/shell/src/interpreter.py b/shell/src/interpreter.py
index a10ca4a8..64641a02 100644
--- a/shell/src/interpreter.py
+++ b/shell/src/interpreter.py
@@ -13,6 +13,8 @@ import re
import time
import dateutil.parser
import pycurl
+import traceback
+
try:
from urllib.parse import unquote
except ImportError:
@@ -159,20 +161,7 @@ class DMLiteInterpreter(object):
return None
def prettySize(self, size):
- isize = int(size) # argument can be string
- if isize < 1024**1:
- prettySize = "%iB" % isize
- elif isize < 1024**2:
- prettySize = '%.2fkB' % (float(isize) / 1024**1)
- elif isize < 1024**3:
- prettySize = '%.2fMB' % (float(isize) / 1024**2)
- elif isize < 1024**4:
- prettySize = '%.2fGB' % (float(isize) / 1024**3)
- elif isize < 1024**5:
- prettySize = '%.2fTB' % (float(isize) / 1024**4)
- else:
- prettySize = '%.2fPB' % (float(isize) / 1024**5)
- return prettySize
+ return prettySize(size)
def prettyInputSize(self, prettysize):
if 'PB' in prettysize:
@@ -1715,31 +1704,52 @@ The latter is the default.
except Exception as e:
return self.error(e.__str__() + '\nParameter(s): ' + ', '.join(given))
+def prettySize(size):
+ isize = int(size) # argument can be string
+ if isize < 1024**1:
+ prettySize = "%iB" % isize
+ elif isize < 1024**2:
+ prettySize = '%.2fkB' % (float(isize) / 1024**1)
+ elif isize < 1024**3:
+ prettySize = '%.2fMB' % (float(isize) / 1024**2)
+ elif isize < 1024**4:
+ prettySize = '%.2fGB' % (float(isize) / 1024**3)
+ elif isize < 1024**5:
+ prettySize = '%.2fTB' % (float(isize) / 1024**4)
+ else:
+ prettySize = '%.2fPB' % (float(isize) / 1024**5)
+ return prettySize
+
def pprint_dictionary(dpool, indent=4):
- ret = StringIO.StringIO()
+ ret = ''
for key, value in dpool.items():
- ret.write(" " * indent)
- ret.write(key)
- ret.write(": ")
+ ret += (" " * indent)
+ ret += key
+ ret += ": "
if type(value) is dict:
- ret.write(pprint_dictionary(value, indent + 4))
+ ret += pprint_dictionary(value, indent + 4)
elif type(value) is list and len(value) > 0 and type(value[0]) is dict:
for item in value:
- ret.write("\n")
- ret.write(pprint_dictionary(item, indent + 4))
- ret.write("\n")
+ ret += "\n"
+ ret += pprint_dictionary(item, indent + 4)
+ ret += "\n"
#workaround to print the status and activitystatus as String
elif str(key) in ["status", "poolstatus"]:
- ret.write(fsstatusbycode[int(value)])
- ret.write("\n")
+ ret += fsstatusbycode[int(value)]
+ ret += "\n"
+ elif "space" in key or "size" in key:
+ ret += str(value)
+ ret += " ("
+ ret += prettySize(value)
+ ret += ")\n"
elif str(key) in ["activitystatus"]:
- ret.write(activitystatusbycode[int(value)])
- ret.write("\n")
+ ret += activitystatusbycode[int(value)]
+ ret += "\n"
else:
- ret.write(str(value))
- ret.write("\n")
- return ret.getvalue()
+ ret += str(value)
+ ret += "\n"
+ return ret
class PoolInfoCommand(ShellCommand):
@@ -1773,7 +1783,7 @@ class PoolInfoCommand(ShellCommand):
self.ok("%s (%s)\n%s" % (pool.name, pool.type, pprint_dictionary(dpool)))
return self.ok()
except Exception as e:
- return self.error(e.__str__() + '\nParameter(s): ' + ', '.join(given))
+ return self.error(e.__str__() + '\n' + traceback.format_exc() + '\nParameter(s): ' + ', '.join(given))
class PoolModifyCommand(ShellCommand):