Add resolve_uri_to_tree to mozautomation
authorGregory Szorc <gps@mozilla.com>
Sun, 21 Jul 2013 23:02:19 -0700
changeset 9 916cf879e9a7cb3af1a7f167c4195288fc8bfa2d
parent 8 c390365395d92e97911567f7691ecb3267405f17
child 10 72299b499208efe068499f72f7d8eacb300b178f
push id2
push usergszorc@mozilla.com
push dateMon, 22 Jul 2013 06:02:53 +0000
Add resolve_uri_to_tree to mozautomation
mozautomation/repository.py
--- a/mozautomation/repository.py
+++ b/mozautomation/repository.py
@@ -114,16 +114,29 @@ def resolve_trees_to_uris(trees, write_a
         if tree is None:
             uris.append((trees[i], None))
         else:
             uris.append((mapped[i], '%s%s' % (base, tree)))
 
     return uris
 
 
+def resolve_uri_to_tree(uri):
+    """Try to resolve a URI back to a known tree."""
+
+    for tree, path in REPOS.items():
+        if uri.startswith('%s%s' % (BASE_READ_URI, path)):
+            return tree
+
+        if uri.startswith('%s%s' % (BASE_WRITE_URI, path)):
+            return tree
+
+    return None
+
+
 class PushInfo(object):
     """Represents an entry from the repository pushlog."""
 
     def __init__(self, push_id, d):
         self.push_id = push_id
         self.date = d['date']
         self.changesets = []