pyversion.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/usr/bin/env python3
  2. #
  3. # mmgen = Multi-Mode GENerator, a command-line cryptocurrency wallet
  4. # Copyright (C)2013-2024 The MMGen Project <mmgen@tuta.io>
  5. # Licensed under the GNU General Public License, Version 3:
  6. # https://www.gnu.org/licenses
  7. # Public project repositories:
  8. # https://github.com/mmgen/mmgen-wallet
  9. # https://gitlab.com/mmgen/mmgen-wallet
  10. """
  11. pyversion: Python version string operations
  12. """
  13. class PythonVersion(str):
  14. major = 0
  15. minor = 0
  16. def __new__(cls,arg=None):
  17. if isinstance(arg,PythonVersion):
  18. return arg
  19. if arg:
  20. major,minor = arg.split('.')
  21. else:
  22. import platform
  23. major,minor = platform.python_version_tuple()[:2]
  24. me = str.__new__( cls, f'{major}.{minor}' )
  25. me.major = int(major)
  26. me.minor = int(minor)
  27. return me
  28. def __lt__(self,other):
  29. other = type(self)(other)
  30. return self.major < other.major or (self.major == other.major and self.minor < other.minor)
  31. def __le__(self,other):
  32. other = type(self)(other)
  33. return self.major < other.major or (self.major == other.major and self.minor <= other.minor)
  34. def __eq__(self,other):
  35. other = type(self)(other)
  36. return self.major == other.major and self.minor == other.minor
  37. def __ne__(self,other):
  38. other = type(self)(other)
  39. return not (self.major == other.major and self.minor == other.minor)
  40. def __gt__(self,other):
  41. other = type(self)(other)
  42. return self.major > other.major or (self.major == other.major and self.minor > other.minor)
  43. def __ge__(self,other):
  44. other = type(self)(other)
  45. return self.major > other.major or (self.major == other.major and self.minor >= other.minor)
  46. python_version = PythonVersion()