Skip to content

Instantly share code, notes, and snippets.

@dnorton
Last active December 15, 2015 10:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dnorton/5245428 to your computer and use it in GitHub Desktop.
Save dnorton/5245428 to your computer and use it in GitHub Desktop.
attempting to order versions that are "#.#.##.##"
def _determine_version(artifact):
def determine_version(artifact):
base_path, symlink_name = os.path.split(artifact)
base_name = symlink_name.split('-')[0]
version = None
version_map = {}
version_list = []
list = os.listdir(base_path)
#build a list of versions
for file in [x for x in list if x.find(base_name) >= 0]:
m = re.search(base_name + '-(\d+\.\d+\.\d+(\.\d+)*)', file)
if m is not None:
version_list.append( m.group(1))
#attempt to order
#TODO: work on this algorithm to get correctly ordered versions
for version in version_list:
c = version.split('.')
number = int(c[0]) * 1000 + int(c[1]) * 100 + int(c[2]) * 6
if len(c) > 3:
number += int(c[3])
version_map[number] = version
key_list = version_map.keys()
key_list.sort()
#test the order of tke keys
for key in key_list:
print version_map[key]
# return the next to last version (this was specific to my needs)
return version_map[key_list[len(key_list)-2]] if len(key_list) > 1 else None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment