Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. from sys import argv
  2. class Version:
  3. def __init__(self, ver_str):
  4. if type(ver_str) != 'string':
  5. ver_list = ver_str.split('.')
  6. self.Major = int(ver_list[0])
  7. self.Minor = int(ver_list[1])
  8. self.Patch = int(ver_list[2])
  9. self.Build = int(ver_list[3])
  10.  
  11. def __repr__(self):
  12. return "{}.{}.{}.{}".format(self.Major, self.Minor, self.Patch, self.Build)
  13. def __lt__(self, other):
  14. if other.Major != self.Major:
  15. return self.Major < other.Major
  16. elif other.Minor != self.Minor:
  17. return self.Minor < other.Minor
  18. elif other.Patch != self.Patch:
  19. return self.Patch < other.Patch
  20.  
  21. else:
  22. return self.Build < other.Build
  23.  
  24. def __gt__(self, other):
  25. if other.Major != self.Major:
  26. return self.Major > other.Major
  27. elif other.Minor != self.Minor:
  28. return self.Minor > other.Minor
  29. elif other.Patch != self.Patch:
  30. return self.Patch > other.Patch
  31.  
  32. else:
  33. return self.Build > other.Build
  34.  
  35. def printme(self):
  36. print("{}.{}.{}.{}".format(self.Major, self.Minor, self.Patch, self.Build))
  37.  
  38.  
  39. def main(argv):
  40. validate_args(argv)
  41.  
  42. ver_1 = Version(argv[1])
  43.  
  44. ver_2 = Version(argv[2])
  45. op = argv[3]
  46.  
  47. if op == '<':
  48. print("{} < {}: {}".format(ver_1, ver_2, ver_1 < ver_2))
  49. elif op == '>':
  50. print("{} > {}: {}".format(ver_1, ver_2, ver_1 > ver_2))
  51. else:
  52. print("Incorrect operator")
  53. exit(-1)
  54.  
  55. def validate_args(argv):
  56. no_of_args = len(argv)
  57. if no_of_args != 4:
  58. print("USAGE: {} 1.1.1.1 2.2.2.2 '<' or '>'".format(argv[0]))
  59. exit(-1)
  60. if (len(argv[1].split('.')) != 4) or (len(argv[2].split('.')) != 4):
  61. print("USAGE: {} 1.1.1.1 2.2.2.2. '<' or '>' IMPROPER VERSION FORMAT".format(argv[0]))
  62. exit(-1)
  63. if argv[3] != '>' and argv[3] != '<':
  64. print("USAGE: {} 1.1.1.1 2.2.2.2. '<' or '>' IMPROPER OPERATOR".format(argv[0]))
  65. exit(-1)
  66.  
  67. if __name__ == '__main__':
  68. main(argv)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement