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