Python 3.7.0
from sys import argv
class Version:
def __init__(self, ver_str):
if type(ver_str) != 'string':
ver_list = ver_str.split('.')
self.Major = int(ver_list[0])
self.Minor = int(ver_list[1])
self.Patch = int(ver_list[2])
self.Build = int(ver_list[3])
def __repr__(self):
return "{}.{}.{}.{}".format(self.Major, self.Minor, self.Patch, self.Build)
def __lt__(self, other):
if other.Major != self.Major:
return self.Major < other.Major
elif other.Minor != self.Minor:
return self.Minor < other.Minor
elif other.Patch != self.Patch:
return self.Patch < other.Patch
else:
return self.Build < other.Build
def __gt__(self, other):
if other.Major != self.Major:
return self.Major > other.Major
elif other.Minor != self.Minor:
return self.Minor > other.Minor
elif other.Patch != self.Patch:
return self.Patch > other.Patch
else:
return self.Build > other.Build
def printme(self):
print("{}.{}.{}.{}".format(self.Major, self.Minor, self.Patch, self.Build))
def main(argv):
validate_args(argv)
ver_1 = Version(argv[1])
ver_2 = Version(argv[2])
op = argv[3]
if op == '<':
print("{} < {}: {}".format(ver_1, ver_2, ver_1 < ver_2))
elif op == '>':
print("{} > {}: {}".format(ver_1, ver_2, ver_1 > ver_2))
else:
print("Incorrect operator")
exit(-1)
def validate_args(argv):
no_of_args = len(argv)
if no_of_args != 4:
print("USAGE: {} 1.1.1.1 2.2.2.2 '<' or '>'".format(argv[0]))
exit(-1)
if (len(argv[1].split('.')) != 4) or (len(argv[2].split('.')) != 4):
print("USAGE: {} 1.1.1.1 2.2.2.2. '<' or '>' IMPROPER VERSION FORMAT".format(argv[0]))
exit(-1)
if argv[3] != '>' and argv[3] != '<':
print("USAGE: {} 1.1.1.1 2.2.2.2. '<' or '>' IMPROPER OPERATOR".format(argv[0]))
exit(-1)
if __name__ == '__main__':
main(argv)