brillo flash: progress bar when flashing to usb

Currently, when we flash an image to USB, a progress bar (pv) is
only shown if we are in the chroot or if pv is installed on the
host machine.

If brillo flash to usb is run outside the chroot, we enter the
chroot to ensure that a progress bar will be displayed.

BUG=brillo:1024
TEST=`cros flash usb:// peppy/latest --log-level notice`

Change-Id: If22b0b45fb8f361d57cb79393f85b743a94f5d3d
Reviewed-on: https://chromium-review.googlesource.com/270077
Reviewed-by: Bertrand Simonnet <bsimonnet@chromium.org>
Commit-Queue: Ralph Nathan <ralphnathan@chromium.org>
Trybot-Ready: Ralph Nathan <ralphnathan@chromium.org>
Tested-by: Ralph Nathan <ralphnathan@chromium.org>
diff --git a/cli/cros/cros_flash.py b/cli/cros/cros_flash.py
index 8624a89..0a7bf2d 100644
--- a/cli/cros/cros_flash.py
+++ b/cli/cros/cros_flash.py
@@ -142,6 +142,16 @@
 
   def Run(self):
     """Perfrom the cros flash command."""
+
+    # Enter the chroot to display the progress bar for flashing to usb if the
+    # following conditions are met:
+    # (1) Device is USB.
+    # (2) Logging level is less than equal to logging.NOTICE.
+    if self.options.device is not None and (
+        self.options.device.scheme == commandline.DEVICE_SCHEME_USB and
+        logging.getLogger().getEffectiveLevel() <= logging.NOTICE):
+      commandline.RunInsideChroot(self)
+
     self.options.Freeze()
     try:
       flash.Flash(