utils.py 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # -*- coding: utf-8 -*-
  2. import datetime
  3. DEFAULT_WEBDAV_CONFIG_FILE = "wsgidav.conf"
  4. DEFAULT_TRACIM_CONFIG_FILE = "development.ini"
  5. def cmp_to_key(mycmp):
  6. """
  7. List sort related function
  8. Convert a cmp= function into a key= function
  9. """
  10. class K(object):
  11. def __init__(self, obj, *args):
  12. self.obj = obj
  13. def __lt__(self, other):
  14. return mycmp(self.obj, other.obj) < 0
  15. def __gt__(self, other):
  16. return mycmp(self.obj, other.obj) > 0
  17. def __eq__(self, other):
  18. return mycmp(self.obj, other.obj) == 0
  19. def __le__(self, other):
  20. return mycmp(self.obj, other.obj) <= 0
  21. def __ge__(self, other):
  22. return mycmp(self.obj, other.obj) >= 0
  23. def __ne__(self, other):
  24. return mycmp(self.obj, other.obj) != 0
  25. return K
  26. def current_date_for_filename() -> str:
  27. """
  28. ISO8601 current date, adapted to be used in filename (for
  29. webdav feature for example), with trouble-free characters.
  30. :return: current date as string like "2018-03-19T15.49.27.246592"
  31. """
  32. # INFO - G.M - 19-03-2018 - As ':' is in transform_to_bdd method in
  33. # webdav utils, it may cause trouble. So, it should be replaced to
  34. # a character which will not change in bdd.
  35. return datetime.datetime.now().isoformat().replace(':', '.')