Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def get_last_revision(revs, sample_rev):
- '''Returns last revision in branch defined by sample_rev'''
- def revision_tail(rev):
- '''Revisions tails (everything without rev_branch_base of branch)'''
- return rev[len(rev_branch_base):]
- def is_rev_in_branch(rev):
- '''Check if revision is in the branch'''
- return rev.startswith(rev_branch_base) and revision_tail(rev).isdigit()
- rev_digit_array = sample_rev.split(".")
- rev_branch_base = ".".join(rev_digit_array[:-2] + [rev_digit_array[-1], ""])
- tails_in_branch = [int(revision_tail(rev)) for rev in revs if is_rev_in_branch(rev)]
- return "%s%d" % (rev_branch_base, max(tails_in_branch))
- if __name__ == "__main__":
- revs = ["1.18", "1.19","1.20","1.21","2.50",
- "1.18.2.1", "1.18.2.2","1.18.2.3","1.18.2.6", "1.19.2.6",
- "1.18.2.1.3.1", "1.18.2.1.3.2","1.18.2.1.3.3","1.18.2.1.3.6","1.18.3.1.3.6"]
- assert get_last_revision(revs, "1.18.0.2") == "1.18.2.6"
- assert get_last_revision(revs, "1.18.2.1.0.3") == "1.18.2.1.3.6"
- print "OK"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement