xbuddy: Expose alias lookup method.

This is needed for applications (e.g. cros flash) to be able to properly
map image aliases (e.g. 'project_sdk') into the correct XBuddy path.
The signature is slightly changed by making the board and version
arguments optional, deferring to pre-initialized board/version.

BUG=brillo:608
TEST=Unit test

Change-Id: I5fa5ad77eff7768e078f842f8c9a14c369535fca
Reviewed-on: https://chromium-review.googlesource.com/267125
Trybot-Ready: Gilad Arnold <garnold@chromium.org>
Tested-by: Gilad Arnold <garnold@chromium.org>
Reviewed-by: Chris Sosa <sosa@chromium.org>
Commit-Queue: Gilad Arnold <garnold@chromium.org>
diff --git a/xbuddy.py b/xbuddy.py
index 36cc8b2..384de49 100644
--- a/xbuddy.py
+++ b/xbuddy.py
@@ -267,16 +267,18 @@
     except ConfigParser.Error:
       return 5
 
-  def _LookupAlias(self, alias, board, version):
+  def LookupAlias(self, alias, board=None, version=None):
     """Given the full xbuddy config, look up an alias for path rewrite.
 
     Args:
       alias: The xbuddy path that could be one of the aliases in the
         rewrite table.
       board: The board to fill in with when paths are rewritten. Can be from
-        the update request xml or the default board from devserver.
+        the update request xml or the default board from devserver. If None,
+        defers to the value given during XBuddy initialization.
       version: The version to fill in when rewriting paths. Could be a specific
-        version number or a version alias like LATEST.
+        version number or a version alias like LATEST. If None, defers to the
+        value given during XBuddy initialization, or LATEST.
 
     Returns:
       A pair (val, suffix) where val is the rewritten path, or the original
@@ -301,7 +303,8 @@
       # Fill in the board and version.
       val = val.replace("BOARD", "%(board)s")
       val = val.replace("VERSION", "%(version)s")
-      val = val % {'board': board, 'version': version}
+      val = val % {'board': board or self._board,
+                   'version': version or self._version or LATEST}
 
     _Log("Path is %s, location suffix is %s", val, suffix)
     return val, suffix
@@ -737,7 +740,8 @@
     default_board = self._board if self._board else board
     default_version = self._version or version or LATEST
     # Rewrite the path if there is an appropriate default.
-    path, suffix = self._LookupAlias(path, default_board, default_version)
+    path, suffix = self.LookupAlias(path, board=default_board,
+                                    version=default_version)
     # Parse the path.
     image_type, board, version, is_local = self._InterpretPath(
         path, default_board, default_version)