Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
def cmpver(vA, vB):
def matchesCas(version):
return re.match("^.*\d+\.(\d{4})\.(\d+)\-(\d+)-[a-z0-9]+$", version)
if vA == vB: return 0
vA = vA.replace('-jetty-console', '')
vB = vB.replace('-jetty-console', '')
vA_Array = vA.split('-')
vB_Array = vB.split('-')
if not matchesCas(vA) and len(vA_Array) > 2 and len(vB_Array) > 2:
vA = vA_Array [len(vA_Array) - 1]
vB = vB_Array [len(vB_Array) - 1]
return cmp(long(vA), long(vB))
elif matchesCas(vA) or (len(vA_Array) <= 2 and len(vB_Array) <= 2):
def num(s):
if s.isdigit(): return int(s)
return s
seqA = map(num, re.findall('\d+|\w+', vA.replace('-SNAPSHOT', '')))
seqB = map(num, re.findall('\d+|\w+', vB.replace('-SNAPSHOT', '')))
# this is to ensure that 1.0 == 1.0.0 in cmp(..)
lenA, lenB = len(seqA), len(seqB)
for i in range(lenA, lenB): seqA += (0,)
for i in range(lenB, lenA): seqB += (0,)
rc = cmp(seqA, seqB)
if rc == 0:
if vA.endswith('-SNAPSHOT'): return -1
if vB.endswith('-SNAPSHOT'): return 1
return rc
else:
if len(vA_Array) > 2: return 1
return -1
=========
WARNING: Govnokod.
=========
#
# Don't need to change this, "defines" for code readability, numbers here don't matter as long as they differ
#
TARBALL = 1
WAR = 2
PROPERTIES = 3
UNKNOWN = 99
def getBaseNameFromFile(file):
if "/" in file:
file = file.rsplit('/', 1)[1]
baseName = file.rsplit('_', 1)[0]
return baseName
def getVersionFromFile(file):
version = "0.0"
versionExt = file.rsplit('_', 1)[1]
version = versionExt
if versionExt.endswith('.tar.gz'):
version = versionExt.replace('.tar.gz', '')
if versionExt.endswith('.war'):
version = versionExt.replace('.war', '')
return version
def getExtFromFile(file):
ext = "none"
if file.endswith('.tar.gz'):
ext = 'tar.gz'
if file.endswith('.war'):
ext = 'war'
return ext
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.