utils.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import base64
  2. import time
  3. from configs.logging import logger
  4. def decode_user(username, password):
  5. if not username or not password:
  6. return '' , ''
  7. try:
  8. u = base64.b64decode(username).decode('utf-8')
  9. p = base64.b64decode(password).decode('utf-8')
  10. return u, p
  11. except Exception as e:
  12. logger.error(e)
  13. return username, password
  14. def encode_base64(str):
  15. return base64.encodebytes(str.encode('utf-8')).decode('utf-8')
  16. def decode_base64(str):
  17. return base64.decodebytes(str.encode('utf-8')).decode('utf-8')
  18. def byte_conversion(size):
  19. if size < 1024:
  20. return str("%.1f"%size) + 'B'
  21. elif size < 1024 * 1024:
  22. return str("%.1f"%(size/1024)) + 'KB'
  23. elif size < 1024 * 1024 * 1024:
  24. return str("%.1f"%(size/1024/1024)) + 'MB'
  25. else:
  26. return str("%.1f"%(size/1024/1024/1024)) + 'GB'
  27. def get_cmd_parameter(jvm_param):
  28. cmd_parameter = ''
  29. if jvm_param is not None and jvm_param != '':
  30. cmd_parameter += '-j "' + jvm_param + '" '
  31. return cmd_parameter