Advertisement
Guest User

Untitled

a guest
Jan 15th, 2010
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.07 KB | None | 0 0
  1. def get_last_revision(revs, sample_rev):
  2.     '''Returns last revision in branch defined by sample_rev'''
  3.    
  4.     def revision_tail(rev):
  5.         '''Revisions tails (everything without rev_branch_base of branch)'''
  6.         return rev[len(rev_branch_base):]
  7.    
  8.     def is_rev_in_branch(rev):
  9.         '''Check if revision is in the branch'''
  10.         return rev.startswith(rev_branch_base) and revision_tail(rev).isdigit()
  11.    
  12.     rev_digit_array = sample_rev.split(".")
  13.     rev_branch_base = ".".join(rev_digit_array[:-2] + [rev_digit_array[-1], ""])
  14.     tails_in_branch = [int(revision_tail(rev)) for rev in revs if is_rev_in_branch(rev)]  
  15.     return "%s%d" % (rev_branch_base, max(tails_in_branch))
  16.    
  17.  
  18. if __name__ == "__main__":
  19.     revs = ["1.18", "1.19","1.20","1.21","2.50",
  20.      "1.18.2.1", "1.18.2.2","1.18.2.3","1.18.2.6", "1.19.2.6",
  21.      "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"]
  22.     assert get_last_revision(revs, "1.18.0.2") == "1.18.2.6"
  23.     assert get_last_revision(revs, "1.18.2.1.0.3") == "1.18.2.1.3.6"
  24.     print "OK"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement