cros flash: create the target file if necessary

Previously, if target points to a directory, cros flash works fine. But
if target path does not exists, cros flash gives error.

The expected behavior should be:
  - If target path does not exist, copy source to target.
  - If target path exists and is not a directory, copy source to target,
    overwrite it.
  - If target path exists and is a directory, copy source to
    target/basename(source).

BUG=None
TEST=Unit tests
TEST=manually tested:
  - cros flash file://PATH_NOT_EXISTS xbuddy://remote/BOARD/VERSION
  - cros flash file://PATH_TO_DIR xbuffy://remote/BOARD/VERSION
  both work and got the same md5sum

Change-Id: I038d59319dddbd7fbff1712dbf4a9d8e5937af0e
Reviewed-on: https://chromium-review.googlesource.com/332565
Commit-Ready: Mao Huang <littlecvr@chromium.org>
Tested-by: Mao Huang <littlecvr@chromium.org>
Reviewed-by: Don Garrett <dgarrett@chromium.org>
diff --git a/cli/flash.py b/cli/flash.py
index 4863e40..e44508b 100644
--- a/cli/flash.py
+++ b/cli/flash.py
@@ -288,8 +288,8 @@
 
   def Run(self):
     """Copy the image to the path specified by self.device."""
-    if not os.path.exists(self.device):
-      raise FlashError('Path %s does not exist.' % self.device)
+    if not os.path.isdir(os.path.dirname(self.device)):
+      raise FlashError('Parent of path %s is not a directory.' % self.device)
 
     image_path = self._GetImagePath()
     if os.path.isdir(self.device):